vendor/store.shopware.com/dreisccmspro/src/DreiscCmsPro.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace DreiscCmsPro;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\Plugin;
  6. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9. use Symfony\Component\DependencyInjection\ContainerBuilder;
  10. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  11. use Symfony\Component\Config\FileLocator;
  12. class DreiscCmsPro extends Plugin
  13. {
  14.     /**
  15.     * @param ContainerBuilder $container
  16.     * @throws \Exception TEST
  17.     */
  18.     public function build(ContainerBuilder $container): void
  19.     {
  20.         parent::build($container);
  21.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/Resources/config/'));
  22.         $loader->load('dependency.injection.xml');
  23.     }
  24.     public function activate(ActivateContext $activateContext): void
  25.     {
  26.         $this->prepareCmsBlocks();
  27.     }
  28.     public function postUpdate(UpdateContext $updateContext): void
  29.     {
  30.         $this->prepareCmsBlocks();
  31.     }
  32.     private function prepareCmsBlocks()
  33.     {
  34.         $connection $this->container->get(Connection::class);
  35.         $connection->executeStatement('
  36.             UPDATE `cms_block` SET custom_fields = JSON_SET(IFNULL(custom_fields, "{}"), "$.dreisc_cms_block_id", LOWER(HEX(id)))
  37.         ');
  38.     }
  39. }