<?php declare(strict_types=1);
namespace DreiscCmsPro;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
class DreiscCmsPro extends Plugin
{
/**
* @param ContainerBuilder $container
* @throws \Exception TEST
*/
public function build(ContainerBuilder $container): void
{
parent::build($container);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/Resources/config/'));
$loader->load('dependency.injection.xml');
}
public function activate(ActivateContext $activateContext): void
{
$this->prepareCmsBlocks();
}
public function postUpdate(UpdateContext $updateContext): void
{
$this->prepareCmsBlocks();
}
private function prepareCmsBlocks()
{
$connection = $this->container->get(Connection::class);
$connection->executeStatement('
UPDATE `cms_block` SET custom_fields = JSON_SET(IFNULL(custom_fields, "{}"), "$.dreisc_cms_block_id", LOWER(HEX(id)))
');
}
}