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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Ngs\ShopRestrict;
  3. use Doctrine\DBAL\Connection;
  4. use Ngs\ShopRestrict\Service\RestrictedPageService;
  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 NgsShopRestrict extends Plugin
  12. {
  13.     public function install(InstallContext $installContext): void
  14.     {
  15.         // Do stuff such as creating a new payment method
  16.     }
  17.     public function uninstall(UninstallContext $uninstallContext): void
  18.     {
  19.         parent::uninstall($uninstallContext);
  20.         if ($uninstallContext->keepUserData()) {
  21.             return;
  22.         }
  23.         $connection $this->container->get(Connection::class);
  24.         $connection->executeUpdate('DROP TABLE IF EXISTS `restricted_page`');
  25.         // Remove or deactivate the data created by the plugin
  26.     }
  27.     public function activate(ActivateContext $activateContext): void
  28.     {
  29.         parent::activate($activateContext);
  30.         //get the config service
  31.         $this->container->get(RestrictedPageService::class)->create($activateContext->getContext());
  32.         //set the specified values as defaults
  33.     }
  34.     public function deactivate(DeactivateContext $deactivateContext): void
  35.     {
  36.         // Deactivate entities, such as a new payment method
  37.         // Or remove previously created entities
  38.         $this->container->get(RestrictedPageService::class)->delete($deactivateContext->getContext());
  39.     }
  40.     public function update(UpdateContext $updateContext): void
  41.     {
  42.         // Update necessary stuff, mostly non-database related
  43.     }
  44.     public function postInstall(InstallContext $installContext): void
  45.     {
  46.     }
  47.     public function postUpdate(UpdateContext $updateContext): void
  48.     {
  49.     }
  50. }