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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace zenit\PlatformSalesCountdownBar;
  3. use Shopware\Core\Framework\Plugin;
  4. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  5. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  6. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  7. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  8. use Shopware\Core\System\SystemConfig\SystemConfigService;
  9. use Doctrine\DBAL\Connection;
  10. use zenit\PlatformSalesCountdownBar\Util\Lifecycle\Installer;
  11. use zenit\PlatformSalesCountdownBar\Util\Lifecycle\Uninstaller;
  12. class zenitPlatformSalesCountdownBar extends Plugin
  13. {
  14.     public function install(InstallContext $installContext): void
  15.     {
  16.         $this->addDefaultConfiguration();
  17.         $this->addInstallDefaultConfiguration();
  18.         /** @var EntityRepository $mediaDefaultFolderRepository */
  19.         $mediaDefaultFolderRepository $this->container->get('media_default_folder.repository');
  20.         /** @var Connection $connection */
  21.         $connection $this->container->get(Connection::class);
  22.         $installer = new Installer(
  23.             $mediaDefaultFolderRepository,
  24.             $connection
  25.         );
  26.         $installer->install($installContext->getContext());
  27.         parent::install($installContext);
  28.     }
  29.     public function update(UpdateContext $updateContext): void
  30.     {
  31.         $this->addDefaultConfiguration();
  32.         $this->addUpdateDefaultConfiguration();
  33.         if (version_compare($updateContext->getCurrentPluginVersion(), '2.5.0''<')) {
  34.             /** @var EntityRepository $mediaDefaultFolderRepository */
  35.             $mediaDefaultFolderRepository $this->container->get('media_default_folder.repository');
  36.             /** @var Connection $connection */
  37.             $connection $this->container->get(Connection::class);
  38.             $installer = new Installer(
  39.                 $mediaDefaultFolderRepository,
  40.                 $connection
  41.             );
  42.             $installer->install($updateContext->getContext());
  43.         }
  44.         parent::update($updateContext);
  45.     }
  46.     public function uninstall(UninstallContext $uninstallContext): void
  47.     {
  48.         if ($uninstallContext->keepUserData()) {
  49.             return;
  50.         }
  51.         /** @var EntityRepository $mediaFolderRepository */
  52.         $mediaFolderRepository $this->container->get('media_folder.repository');
  53.         /** @var EntityRepository $mediaRepository */
  54.         $mediaRepository $this->container->get('media.repository');
  55.         /** @var EntityRepository $mediaDefaultFolderRepository */
  56.         $mediaDefaultFolderRepository $this->container->get('media_default_folder.repository');
  57.         /** @var EntityRepository $mediaFolderConfigRepository */
  58.         $mediaFolderConfigRepository $this->container->get('media_folder_configuration.repository');
  59.         $uninstaller = new Uninstaller(
  60.             $mediaFolderRepository,
  61.             $mediaRepository,
  62.             $mediaDefaultFolderRepository,
  63.             $mediaFolderConfigRepository
  64.         );
  65.         $uninstaller->uninstall($uninstallContext->getContext());
  66.     }
  67.     private function addInstallDefaultConfiguration(): void
  68.     {
  69.         $this->setValue('font''base');
  70.     }
  71.     private function addUpdateDefaultConfiguration(): void
  72.     {
  73.         $this->setValue('font''custom');
  74.     }
  75.     private function addDefaultConfiguration(): void
  76.     {
  77.         $this->setValue('statemanager', ['d-block d-sm-none''d-sm-block d-md-none''d-md-block d-lg-none''d-lg-block d-xl-none''d-xl-block']);
  78.         $this->setValue('text'"Lorem ipsum dolor sit amet\r\nconsetetur sadipscing elitr");
  79.         $this->setValue('backgroundImageOpacity''.40');
  80.         $this->setValue('fontWeight''600');
  81.         $this->setValue('expiration''365');
  82.     }
  83.     /**
  84.      * @param string $configName
  85.      * @param null $default
  86.      */
  87.     public function setValue(string $configName$default null) : void
  88.     {
  89.         $systemConfigService $this->container->get(SystemConfigService::class);
  90.         $domain $this->getName() . '.config.';
  91.         if( $systemConfigService->get($domain $configName) === null )
  92.         {
  93.             $systemConfigService->set($domain $configName$default);
  94.         }
  95.     }
  96. }