<?php declare(strict_types=1);
namespace Weedesign\Images2WebP;
use Composer\Autoload\ClassLoader;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Plugin;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Weedesign\Images2WebP\Controller\Media\DeleteController;
use Weedesign\Images2WebP\Service\GenerateMediaFiles;
use Doctrine\DBAL\Connection;
class WeedesignImages2WebP extends Plugin
{
public const PLUGIN_NAME = 'WeedesignImages2WebP';
public function build(ContainerBuilder $container): void
{
parent::build($container);
$file = __DIR__.'/../vendor/autoload.php';
if (!is_file($file)) {
return;
}
$classLoader = require_once $file;
if ($classLoader instanceof ClassLoader) {
$classLoader->unregister();
$classLoader->register(false);
}
}
public function uninstall(UninstallContext $context): void
{
parent::uninstall($context);
if ($context->keepUserData()) {
return;
}
$deleteController = new DeleteController();
$deleteMedia = $deleteController->check();
$connection = $this->container->get(Connection::class);
$sql = "DELETE FROM `system_config` WHERE `configuration_key` LIKE '%WeedesignImages2WebP.config%'";
$results = $connection->prepare($sql)->executeStatement();
}
public function update(UpdateContext $context): void
{
$systemConfigService = $this->container->get(SystemConfigService::class);
$connection = $this->container->get(Connection::class);
$sql = "DELETE FROM `system_config` WHERE `configuration_key` LIKE '%WeedesignImages2WebP.config.get%'";
$results = $connection->prepare($sql)->executeStatement();
$sql = "DELETE FROM `system_config` WHERE `configuration_key` = 'WeedesignImages2WebP.config.mediaFiles'";
$results = $connection->prepare($sql)->executeStatement();
$sql = "DELETE FROM `system_config` WHERE `configuration_key` = 'WeedesignImages2WebP.config.thumbnailSizes'";
$results = $connection->prepare($sql)->executeStatement();
$systemConfigService->set('WeedesignImages2WebP.config.absolute',1);
$systemConfigService->set('WeedesignImages2WebP.config.webp',1);
if(empty($systemConfigService->get('WeedesignImages2WebP.config.email'))) {
$systemConfigService->set('WeedesignImages2WebP.config.email','support@weedesign.de');
}
}
}