<?php declare(strict_types=1);
namespace Swpa\SwpaBackup;
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Swpa\SwpaBackup\Setup;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
require_once __DIR__ . '/../vendor/autoload.php';
/**
* Main class of the plugin SwpaBackup:
*
* @package Swpa\SwpaBackup
* @license See COPYING.txt for license details
* @author swpa <info@swpa.dev>
*/
class SwpaBackup extends Plugin
{
/**
* @param ContainerBuilder $container
*
* @throws \Exception
*/
public function build(ContainerBuilder $container): void
{
$yamlLoader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/DI/config'));
$yamlLoader->load('commands.yml');
$yamlLoader->load('logger.yml');
$yamlLoader->load('services.yml');
$yamlLoader->load('tasks.yml');
$yamlLoader->load('subscribers.yml');
$yamlLoader->load('entities.yml');
$yamlLoader->load('storage.yml');
$yamlLoader->load('databases.yml');
$this->initFilesystems($container);
$this->initDatabases($container);
parent::build($container);
}
/**
* @param ContainerBuilder $container
*/
private function initFilesystems(ContainerBuilder $container)
{
$filesystems = $container->findTaggedServiceIds('swpa.backup.filesystems');
$provider = $container->getDefinition('swpa.backup.filesystems');
foreach ($filesystems as $id => $attributes) {
$provider->addMethodCall('add', [new Reference($id)]);
}
}
/**
* @param ContainerBuilder $container
*/
private function initDatabases(ContainerBuilder $container)
{
$databases = $container->findTaggedServiceIds('swpa.backup.databases');
$provider = $container->getDefinition('swpa.backup.databases');
foreach ($databases as $id => $attributes) {
$provider->addMethodCall('add', [new Reference($id)]);
}
}
/**
* @return string
*/
public function getStorefrontScriptPath(): string
{
return 'Resources/dist/storefront/js';
}
public function getViewPaths(): array
{
$viewPaths = parent::getViewPaths();
$viewPaths[] = 'Resources/views/storefront';
return $viewPaths;
}
/**
* @param InstallContext $context
*/
public function install(InstallContext $context): void
{
$install = new Setup\Install(
$this->container->get(Connection::class),
$this->container->get(SystemConfigService::class),
$this->container->get('kernel')->getProjectDir()
);
$install->install($context);
parent::install($context);
}
/**
* @param UninstallContext $context
*/
public function uninstall(UninstallContext $context): void
{
/** @var Setup\Uninstall $install */
$install = new Setup\Uninstall($this->container->get(Connection::class));
$install->uninstall($context);
parent::uninstall($context);
}
/**
* @param ActivateContext $context
*/
public function activate(ActivateContext $context): void
{
/** @var Setup\Activate $install */
$install = new Setup\Activate( $this->container->get(Connection::class) );
$install->activate($context);
parent::activate($context);
}
/**
* @param DeactivateContext $context
*/
public function deactivate(DeactivateContext $context): void
{
/** @var Setup\Deactivate $install */
$install = new Setup\Deactivate($this->container->get(Connection::class));
$install->deactivate($context);
parent::deactivate($context);
}
}