custom/static-plugins/BaumarktTheme/src/BaumarktTheme.php line 17

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace BaumarktTheme;
  3. use Shopware\Core\Framework\Plugin;
  4. use Shopware\Storefront\Framework\ThemeInterface;
  5. use BaumarktTheme\Service\CategoryCustomFieldsetService;
  6. use BaumarktTheme\Service\ProductCustomFieldsetService;;
  7. use Shopware\Core\Framework\Context;
  8. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  9. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  10. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  11. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  12. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  13. class BaumarktTheme extends Plugin implements ThemeInterface
  14. {
  15.     public function install(InstallContext $installContext): void
  16.     {
  17.         parent::install($installContext);
  18.         $this->applyUpdates(
  19.             $installContext->getContext(),
  20.             null,
  21.             $installContext->getCurrentPluginVersion()
  22.         );
  23.     }
  24.     public function update(UpdateContext $updateContext): void
  25.     {
  26.         parent::update($updateContext);
  27.         $this->applyUpdates(
  28.             $updateContext->getContext(),
  29.             $updateContext->getCurrentPluginVersion(),
  30.             $updateContext->getUpdatePluginVersion()
  31.         );
  32.     }
  33.     public function uninstall(UninstallContext $uninstallContext): void
  34.     {
  35.         parent::uninstall($uninstallContext);
  36.         $customFieldSetService = new CategoryCustomFieldsetService(
  37.             $this->container->get('custom_field_set.repository'),
  38.             $uninstallContext->getContext()
  39.         );
  40.         $customFieldSetService->remove();
  41.     }
  42.     public function activate(ActivateContext $context): void
  43.     {
  44.     }
  45.     public function deactivate(DeactivateContext $context): void
  46.     {
  47.     }
  48.     public function getThemeConfigPath(): string
  49.     {
  50.         return 'theme.json';
  51.     }
  52.     private function applyUpdates(Context $context$oldVersion null$newVersion null)
  53.     {
  54.         $versionClosures = [
  55.             '0.1.1' => function () use ($context) {
  56.                 $customFieldSetService = new CategoryCustomFieldsetService(
  57.                     $this->container->get('custom_field_set.repository'),
  58.                     $context
  59.                 );
  60.                 $customFieldSetService->remove();
  61.                 $customFieldSetService->create();
  62.                 return true;
  63.             },
  64.             '0.1.2' => function () use ($context) {
  65.                 $productFieldSetService = new ProductCustomFieldsetService(
  66.                     $this->container->get('custom_field_set.repository'),
  67.                     $context
  68.                 );
  69.                 $productFieldSetService->remove();
  70.                 $productFieldSetService->create();
  71.                 return true;
  72.             },
  73.             '0.1.3' => function () use ($context) {
  74.                 $customFieldSetService = new CategoryCustomFieldsetService(
  75.                     $this->container->get('custom_field_set.repository'),
  76.                     $context
  77.                 );
  78.                 $customFieldSetService->remove();
  79.                 $customFieldSetService->create();
  80.                 return true;
  81.             },
  82.             '0.1.5' => function () use ($context) {
  83.                 $productFieldSetService = new ProductCustomFieldsetService(
  84.                     $this->container->get('custom_field_set.repository'),
  85.                     $context
  86.                 );
  87.                 $productFieldSetService->remove();
  88.                 $productFieldSetService->create();
  89.                 return true;
  90.             },
  91.             '0.1.6' => function () use ($context) {
  92.                 $productFieldSetService = new ProductCustomFieldsetService(
  93.                     $this->container->get('custom_field_set.repository'),
  94.                     $context
  95.                 );
  96.                 $productFieldSetService->remove();
  97.                 $productFieldSetService->create();
  98.                 return true;
  99.             },
  100.             '0.1.7' => function () use ($context) {
  101.                 $productFieldSetService = new ProductCustomFieldsetService(
  102.                     $this->container->get('custom_field_set.repository'),
  103.                     $context
  104.                 );
  105.                 $productFieldSetService->remove();
  106.                 $productFieldSetService->create();
  107.                 return true;
  108.             },
  109.             '0.1.8' => function () use ($context) {
  110.                 $customFieldSetService = new CategoryCustomFieldsetService(
  111.                     $this->container->get('custom_field_set.repository'),
  112.                     $context
  113.                 );
  114.                 $customFieldSetService->remove();
  115.                 $customFieldSetService->create();
  116.                 return true;
  117.             },
  118.             '0.1.9' => function () use ($context) {
  119.                 $customFieldSetService = new ProductCustomFieldsetService(
  120.                     $this->container->get('custom_field_set.repository'),
  121.                     $context
  122.                 );
  123.                 $customFieldSetService->remove();
  124.                 $customFieldSetService->create();
  125.                 return true;
  126.             },
  127.         ];
  128.         foreach ($versionClosures as $version => $versionClosure) {
  129.             if ($oldVersion === null ||
  130.                 (version_compare($oldVersion$version'<')
  131.                     && version_compare($version$newVersion'<='))
  132.             ) {
  133.                 if (!$versionClosure($this)) {
  134.                     return false;
  135.                 }
  136.             }
  137.         }
  138.         return true;
  139.     }
  140. }