custom/plugins/LoyxxSW6SeoFaqManager/src/LoyxxSW6SeoFaqManager.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace LoyxxSW6SeoFaqManager;
  3. use Doctrine\DBAL\Connection;
  4. use LoyxxSW6SeoFaqManager\Installer\LoyPluginInstaller;
  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\InstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  11. class LoyxxSW6SeoFaqManager extends Plugin
  12. {
  13.     const PRIVILEGES = [
  14.         'category' => [
  15.             'viewer' => ['faq_category:read''category:read'],
  16.             'creator' => ['faq_category:write''category:read'],
  17.             'editor' => ['faq_category:update''category:read'],
  18.             'deleter' => ['faq_category:delete''category:read']
  19.         ],
  20.         'product' => [
  21.             'viewer' => ['faq_product:read''product:read'],
  22.             'creator' => ['faq_product:write''product:read'],
  23.             'editor' => ['faq_product:update''product:read'],
  24.             'deleter' => ['faq_product:delete''product:read']
  25.         ],
  26.         'set' => [
  27.             'viewer' => ['faq_set:read'],
  28.             'creator' => ['faq_set:write'],
  29.             'editor' => ['faq_set:update'],
  30.             'deleter' => ['faq_set:delete']
  31.         ]
  32.     ];
  33.     const ENABLE_SEO_PRIVILEGE_TO_ROLES false;
  34.     public function uninstall(UninstallContext $uninstallContext): void
  35.     {
  36.         parent::uninstall($uninstallContext);
  37.         if($uninstallContext->keepUserData()){
  38.             return;
  39.         }
  40.         (new LoyPluginInstaller($this->container))->uninstall($uninstallContext);
  41.         $this->removeMigrations();
  42.     }
  43.     public function activate(ActivateContext $activateContext): void
  44.     {
  45.         if (method_exists($this'addPrivileges') && static::ENABLE_SEO_PRIVILEGE_TO_ROLES) {
  46.             foreach (['viewer''creator''editor''deleter'] as $role) {
  47.                 $this->addPrivileges("seoFaq.editor", static::PRIVILEGES['category'][$role]);
  48.                 $this->addPrivileges("seoFaq.editor", static::PRIVILEGES['product'][$role]);
  49.             }
  50.         }
  51.         (new LoyPluginInstaller($this->container))->activate($activateContext);
  52.         parent::activate($activateContext);
  53.     }
  54.     public function deactivate(DeactivateContext $deactivateContext): void
  55.     {
  56.         if (method_exists($this'removePrivileges') && static::ENABLE_SEO_PRIVILEGE_TO_ROLES) {
  57.             $this->removePrivileges([
  58.                 'faq_category:read',
  59.                 'faq_category:write',
  60.                 'faq_category:update',
  61.                 'faq_category:delete',
  62.                 'faq_product:read',
  63.                 'faq_product:write',
  64.                 'faq_product:update',
  65.                 'faq_product:delete'
  66.             ]);
  67.         }
  68.         (new LoyPluginInstaller($this->container))->deactivate($deactivateContext);
  69.         parent::deactivate($deactivateContext);
  70.     }
  71.     public function update(UpdateContext $updateContext): void
  72.     {
  73.         parent::update($updateContext);
  74.         (new LoyPluginInstaller($this->container))->update($updateContext);
  75.     }
  76.     public function install(InstallContext $installContext): void
  77.     {
  78.         parent::install($installContext);
  79.         (new LoyPluginInstaller($this->container))->install($installContext);
  80.     }
  81.     public function postUpdate(UpdateContext $updateContext): void
  82.     {
  83.         parent::postUpdate($updateContext);
  84.         (new LoyPluginInstaller($this->container))->postUpdate($updateContext);
  85.     }
  86. }