custom/plugins/SwpaBackup/src/SwpaBackup.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Swpa\SwpaBackup;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Plugin;
  5. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  6. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  7. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  9. use Shopware\Core\System\SystemConfig\SystemConfigService;
  10. use Swpa\SwpaBackup\Setup;
  11. use Symfony\Component\Config\FileLocator;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. require_once __DIR__ '/../vendor/autoload.php';
  16. /**
  17.  * Main class of the plugin SwpaBackup:
  18.  *
  19.  * @package Swpa\SwpaBackup
  20.  * @license See COPYING.txt for license details
  21.  * @author  swpa <info@swpa.dev>
  22.  */
  23. class SwpaBackup extends Plugin
  24. {
  25.     /**
  26.      * @param ContainerBuilder $container
  27.      *
  28.      * @throws \Exception
  29.      */
  30.     public function build(ContainerBuilder $container): void
  31.     {
  32.         $yamlLoader = new YamlFileLoader($container, new FileLocator(__DIR__ '/DI/config'));
  33.         $yamlLoader->load('commands.yml');
  34.         $yamlLoader->load('logger.yml');
  35.         $yamlLoader->load('services.yml');
  36.         $yamlLoader->load('tasks.yml');
  37.         $yamlLoader->load('subscribers.yml');
  38.         $yamlLoader->load('entities.yml');
  39.         $yamlLoader->load('storage.yml');
  40.         $yamlLoader->load('databases.yml');
  41.         $this->initFilesystems($container);
  42.         $this->initDatabases($container);
  43.         parent::build($container);
  44.     }
  45.     /**
  46.      * @param ContainerBuilder $container
  47.      */
  48.     private function initFilesystems(ContainerBuilder $container)
  49.     {
  50.         $filesystems $container->findTaggedServiceIds('swpa.backup.filesystems');
  51.         $provider $container->getDefinition('swpa.backup.filesystems');
  52.         foreach ($filesystems as $id => $attributes) {
  53.             $provider->addMethodCall('add', [new Reference($id)]);
  54.         }
  55.     }
  56.     /**
  57.      * @param ContainerBuilder $container
  58.      */
  59.     private function initDatabases(ContainerBuilder $container)
  60.     {
  61.         $databases $container->findTaggedServiceIds('swpa.backup.databases');
  62.         $provider $container->getDefinition('swpa.backup.databases');
  63.         foreach ($databases as $id => $attributes) {
  64.             $provider->addMethodCall('add', [new Reference($id)]);
  65.         }
  66.     }
  67.     /**
  68.      * @return string
  69.      */
  70.     public function getStorefrontScriptPath(): string
  71.     {
  72.         return 'Resources/dist/storefront/js';
  73.     }
  74.     public function getViewPaths(): array
  75.     {
  76.         $viewPaths parent::getViewPaths();
  77.         $viewPaths[] = 'Resources/views/storefront';
  78.         return $viewPaths;
  79.     }
  80.     /**
  81.      * @param InstallContext $context
  82.      */
  83.     public function install(InstallContext $context): void
  84.     {
  85.         $install = new Setup\Install(
  86.             $this->container->get(Connection::class),
  87.             $this->container->get(SystemConfigService::class),
  88.             $this->container->get('kernel')->getProjectDir()
  89.         );
  90.         $install->install($context);
  91.         parent::install($context);
  92.     }
  93.     /**
  94.      * @param UninstallContext $context
  95.      */
  96.     public function uninstall(UninstallContext $context): void
  97.     {
  98.         /** @var Setup\Uninstall $install */
  99.         $install = new Setup\Uninstall($this->container->get(Connection::class));
  100.         $install->uninstall($context);
  101.         parent::uninstall($context);
  102.     }
  103.     /**
  104.      * @param ActivateContext $context
  105.      */
  106.     public function activate(ActivateContext $context): void
  107.     {
  108.         /** @var Setup\Activate $install */
  109.         $install = new Setup\Activate$this->container->get(Connection::class) );
  110.         $install->activate($context);
  111.         parent::activate($context);
  112.     }
  113.     /**
  114.      * @param DeactivateContext $context
  115.      */
  116.     public function deactivate(DeactivateContext $context): void
  117.     {
  118.         /** @var Setup\Deactivate $install */
  119.         $install = new Setup\Deactivate($this->container->get(Connection::class));
  120.         $install->deactivate($context);
  121.         parent::deactivate($context);
  122.     }
  123. }