<?php declare(strict_types=1);
namespace Cbax\ModulAdcell;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
class CbaxModulAdcell extends Plugin
{
public function install(InstallContext $context): void
{
parent::install($context);
}
public function update(UpdateContext $context): void
{
parent::update($context);
}
public function uninstall(UninstallContext $context): void
{
if ($context->keepUserData()) {
parent::uninstall($context);
return;
}
$services = $this->getServices();
$this->removePluginConfig($services, $context->getContext());
parent::uninstall($context);
}
public function activate(ActivateContext $context): void
{
parent::activate($context);
}
public function deactivate(DeactivateContext $context): void
{
parent::deactivate($context);
}
private function removePluginConfig($services, $context)
{
$systemConfigRepository = $services['systemConfigRepository'];
$criteria = new Criteria();
$criteria->addFilter(new ContainsFilter('configurationKey', $this->getName() . '.config.'));
$idSearchResult = $systemConfigRepository->searchIds($criteria, $context);
$ids = array_map(static function ($id) {
return ['id' => $id];
}, $idSearchResult->getIds());
if ($ids === []) {
return;
}
$systemConfigRepository->delete($ids, $context);
}
private function getServices() {
$services = array();
/* Standard Services */
$services['systemConfigService'] = $this->container->get('Shopware\Core\System\SystemConfig\SystemConfigService');
$services['systemConfigRepository'] = $this->container->get('system_config.repository');
/* spezifische Services */
return $services;
}
}