<?php declare(strict_types=1);
namespace Laenen\Grid;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Plugin;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
class LaenenGrid extends Plugin
{
public function uninstall(UninstallContext $uninstallContext): void
{
if ($uninstallContext->keepUserData()) {
return;
}
/** @var EntityRepositoryInterface $sectionRepository */
$sectionRepository = $this->container->get('cms_section.repository');
// Remove all grid sections and their data
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('type', 'lae-grid'));
$ids = $sectionRepository->searchIds($criteria, $uninstallContext->getContext());
$sectionRepository->delete(
array_map(function ($id) {
return ['id' => $id];
}, $ids->getIds()),
$uninstallContext->getContext()
);
}
}