custom/plugins/WeedesignImages2WebP/src/WeedesignImages2WebP.php line 17

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Weedesign\Images2WebP;
  3. use Composer\Autoload\ClassLoader;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Plugin;
  6. use Symfony\Component\DependencyInjection\ContainerBuilder;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  9. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  10. use Shopware\Core\System\SystemConfig\SystemConfigService;
  11. use Weedesign\Images2WebP\Controller\Media\DeleteController;
  12. use Weedesign\Images2WebP\Service\GenerateMediaFiles;
  13. use Doctrine\DBAL\Connection;
  14. class WeedesignImages2WebP extends Plugin
  15. {
  16.     public const PLUGIN_NAME 'WeedesignImages2WebP';
  17.     public function build(ContainerBuilder $container): void
  18.     {
  19.         parent::build($container);
  20.         $file __DIR__.'/../vendor/autoload.php';
  21.         if (!is_file($file)) {
  22.             return;
  23.         }
  24.         $classLoader = require_once $file;
  25.         if ($classLoader instanceof ClassLoader) {
  26.             $classLoader->unregister();
  27.             $classLoader->register(false);
  28.         }
  29.     }
  30.     public function uninstall(UninstallContext $context): void
  31.     {
  32.         parent::uninstall($context);
  33.         if ($context->keepUserData()) {
  34.             return;
  35.         }
  36.         $deleteController = new DeleteController();
  37.         $deleteMedia $deleteController->check();
  38.         $connection $this->container->get(Connection::class);
  39.         $sql "DELETE FROM `system_config` WHERE `configuration_key` LIKE '%WeedesignImages2WebP.config%'";
  40.         $results $connection->prepare($sql)->executeStatement();
  41.         
  42.     }
  43.     public function update(UpdateContext $context): void
  44.     {
  45.         $systemConfigService $this->container->get(SystemConfigService::class);
  46.         $connection $this->container->get(Connection::class);
  47.         $sql "DELETE FROM `system_config` WHERE `configuration_key` LIKE '%WeedesignImages2WebP.config.get%'";
  48.         $results $connection->prepare($sql)->executeStatement();
  49.         $sql "DELETE FROM `system_config` WHERE `configuration_key` = 'WeedesignImages2WebP.config.mediaFiles'";
  50.         $results $connection->prepare($sql)->executeStatement();
  51.         $sql "DELETE FROM `system_config` WHERE `configuration_key` = 'WeedesignImages2WebP.config.thumbnailSizes'";
  52.         $results $connection->prepare($sql)->executeStatement();
  53.         $systemConfigService->set('WeedesignImages2WebP.config.absolute',1);
  54.         $systemConfigService->set('WeedesignImages2WebP.config.webp',1);
  55.         if(empty($systemConfigService->get('WeedesignImages2WebP.config.email'))) {
  56.             $systemConfigService->set('WeedesignImages2WebP.config.email','support@weedesign.de');
  57.         }
  58.     }
  59. }