custom/plugins/MagmodulesShopreview/src/MagmodulesShopreview.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Magmodules\Shopreview;
  3. use Doctrine\DBAL\Connection;
  4. use Magmodules\Shopreview\Util\ShopReviewProfile;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use Shopware\Core\Framework\Plugin;
  7. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  8. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  9. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  10. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  11. use Magmodules\Shopreview\Setup\ActivateDeactivate;
  12. class MagmodulesShopreview extends Plugin
  13. {
  14.     /**
  15.      * @var InstallContext
  16.      */
  17.     private $installContext;
  18.     /**
  19.      * @param InstallContext $installContext
  20.      */
  21.     public function install(InstallContext $installContext): void
  22.     {
  23.         parent::install($installContext);
  24.         $this->getProfile()->addShopReview($installContext->getContext());
  25.     }
  26.     /**
  27.      * @var ActivateDeactivate
  28.      */
  29.     private $activateDeactivate;
  30.     /**
  31.      * @Required
  32.      *
  33.      * @param ActivateDeactivate $activateDeactivate
  34.      */
  35.     public function setActivateDeactivate(ActivateDeactivate $activateDeactivate): void
  36.     {
  37.         $this->activateDeactivate $activateDeactivate;
  38.     }
  39.     /**
  40.      * @param ActivateContext $activateContext
  41.      */
  42.     public function activate(ActivateContext $activateContext): void
  43.     {
  44.         $this->activateDeactivate->activate($activateContext);
  45.         parent::activate($activateContext);
  46.     }
  47.     /**
  48.      * @param UninstallContext $context
  49.      */
  50.     public function uninstall(UninstallContext $context): void
  51.     {
  52.         parent::uninstall($context);
  53.         if ($context->keepUserData()) {
  54.             return;
  55.         }
  56.         /** @var Connection $connection */
  57.         $connection $this->container->get(Connection::class);
  58.         try {
  59.             $connection->delete('import_export_profile', [
  60.                 'name' => 'Shop Review',
  61.             ]);
  62.             if (method_exists($connection'executeStatement')) {
  63.                 $connection->executeStatement('DROP TABLE IF EXISTS `magmodules_shopreview_review`');
  64.             } else {
  65.                 $connection->exec('DROP TABLE IF EXISTS `magmodules_shopreview_review`');
  66.             }
  67.         } catch (\Exception $exception) {
  68.         }
  69.     }
  70.     /**
  71.      * @param EntityRepositoryInterface $shopReview
  72.      */
  73.     private function getProfile() : ShopReviewProfile
  74.     {
  75.         /* @var EntityRepositoryInterface $shopReview */
  76.         $shopReviewRepository $this->container->get('import_export_profile.repository');
  77.         return new ShopReviewProfile(
  78.             $shopReviewRepository
  79.         );
  80.     }
  81. }