vendor/store.shopware.com/jlauloginascustomer/src/JlauLoginAsCustomer.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Jlau\LoginAsCustomer;
  3. use Jlau\LoginAsCustomer\Controller\LoginAsCustomer;
  4. use Doctrine\DBAL\Connection;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Shopware\Core\Framework\Util\Random;
  10. use Shopware\Core\System\SystemConfig\SystemConfigService;
  11. class JlauLoginAsCustomer extends Plugin
  12. {
  13.     public function uninstall(UninstallContext $context): void
  14.     {
  15.         if ($context->keepUserData()) {
  16.             return;
  17.         }
  18.         $connection $this->container->get(Connection::class);
  19.         if (!$connection) {
  20.             return;
  21.         }
  22.         $connection->executeStatement('DROP TABLE IF EXISTS `jlau_login_as_customer`');
  23.     }
  24.     public function activate(ActivateContext $activateContext): void
  25.     {
  26.         $configService $this->container->get(SystemConfigService::class);
  27.         $random Random::getAlphanumericString(32);
  28.         $configService->set('JlauLoginAsCustomer.config.secret'$random);
  29.         $ivlen openssl_cipher_iv_length(LoginAsCustomer::CIPHER);
  30.         $iv Random::getAlphanumericString($ivlen);
  31.         $configService->set('JlauLoginAsCustomer.config.iv'$iv);
  32.     }
  33.     public function deactivate(DeactivateContext $deactivateContext): void
  34.     {
  35.         $configService $this->container->get(SystemConfigService::class);
  36.         $configService->delete('JlauLoginAsCustomer.config.secret');
  37.         $configService->delete('JlauLoginAsCustomer.config.iv');
  38.     }
  39.     public function enrichPrivileges(): array
  40.     {
  41.         return [
  42.             'login_as_customer' => [
  43.                 'jlau.customer.login-as-customer'
  44.             ]
  45.         ];
  46.     }
  47. }