<?php declare(strict_types=1);
namespace EmcgnGewerbeschein;
use Doctrine\DBAL\Connection;
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\InstallContext;
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
use Shopware\Core\Framework\Uuid\Uuid;
class EmcgnGewerbeschein extends Plugin
{
public function install(InstallContext $installContext): void
{
/* Medienordner für Gewerbescheine erstellen */
$mediaFolderRepository = $this->container->get('media_folder.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', 'Emcgn_Trade_Licenses'));
$criteria->setLimit(1);
$folderId = $mediaFolderRepository->searchIds($criteria, $installContext->getContext())->getIds();
if(empty($folderId)){
$mediaFolderRepository->create([
[
'name' => 'Emcgn_Trade_Licenses',
'configuration' => [
'id' => Uuid::randomHex()
]
]
], $installContext->getContext());
}
}
public function uninstall(UninstallContext $uninstallContext): void
{
if($uninstallContext->keepUserData()){
parent::uninstall($uninstallContext);
return;
}
$db = $this->container->get(Connection::class);
$db->executeUpdate('
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `emcgn_gewerbeschein`;
SET FOREIGN_KEY_CHECKS=1;
');
/* Medienordner für Gewerbescheine löschen */
/** @var EntityRepositoryInterface $mediaFolderRepository */
$mediaFolderRepository = $this->container->get('media_folder.repository');
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('name', 'Emcgn_Trade_Licenses'));
$criteria->setLimit(1);
$folderId = $mediaFolderRepository->searchIds($criteria, $uninstallContext->getContext())->getIds();
$folderId = $folderId[0];
if(!empty($folderId)) {
$mediaFolderRepository->delete(
[
[ 'id' => $folderId ]
],$uninstallContext->getContext()
);
}
}
public function getParent()
{
// TODO: Implement getParent() method.
}
}