custom/plugins/EmcgnGewerbeschein/src/EmcgnGewerbeschein.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace EmcgnGewerbeschein;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\Plugin;
  8. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  9. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  10. use Shopware\Core\Framework\Uuid\Uuid;
  11. class EmcgnGewerbeschein extends Plugin
  12. {
  13.     public function install(InstallContext $installContext): void
  14.     {
  15.         /* Medienordner für Gewerbescheine erstellen */
  16.         $mediaFolderRepository $this->container->get('media_folder.repository');
  17.         $criteria = new Criteria();
  18.         $criteria->addFilter(new EqualsFilter('name''Emcgn_Trade_Licenses'));
  19.         $criteria->setLimit(1);
  20.         $folderId $mediaFolderRepository->searchIds($criteria$installContext->getContext())->getIds();
  21.         if(empty($folderId)){
  22.             $mediaFolderRepository->create([
  23.                 [
  24.                     'name' => 'Emcgn_Trade_Licenses',
  25.                     'configuration' => [
  26.                         'id' => Uuid::randomHex()
  27.                     ]
  28.                 ]
  29.             ], $installContext->getContext());
  30.         }
  31.     }
  32.     public function uninstall(UninstallContext $uninstallContext): void
  33.     {
  34.         if($uninstallContext->keepUserData()){
  35.             parent::uninstall($uninstallContext);
  36.             return;
  37.         }
  38.         $db $this->container->get(Connection::class);
  39.         $db->executeUpdate('
  40.             SET FOREIGN_KEY_CHECKS=0;
  41.             DROP TABLE IF EXISTS `emcgn_gewerbeschein`;
  42.             SET FOREIGN_KEY_CHECKS=1;
  43.         ');
  44.         /* Medienordner für Gewerbescheine löschen */
  45.         /** @var EntityRepositoryInterface $mediaFolderRepository */
  46.         $mediaFolderRepository $this->container->get('media_folder.repository');
  47.         $criteria = new Criteria();
  48.         $criteria->addFilter(new EqualsFilter('name''Emcgn_Trade_Licenses'));
  49.         $criteria->setLimit(1);
  50.         $folderId $mediaFolderRepository->searchIds($criteria$uninstallContext->getContext())->getIds();
  51.         $folderId $folderId[0];
  52.         if(!empty($folderId)) {
  53.             $mediaFolderRepository->delete(
  54.                 [
  55.                     [ 'id' => $folderId ]
  56.                 ],$uninstallContext->getContext()
  57.             );
  58.         }
  59.     }
  60.     public function getParent()
  61.     {
  62.         // TODO: Implement getParent() method.
  63.     }
  64. }