custom/plugins/IwvDatevV6/src/IwvDatevV6.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Iwv\IwvDatevV6;
  4. if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
  5.     $loader = require_once dirname(__DIR__) . '/vendor/autoload.php';
  6.     if ($loader !== true) {
  7.         spl_autoload_unregister([$loader'loadClass']);
  8.         $loader->register(false);
  9.     }
  10. }
  11. use Doctrine\DBAL\Connection;
  12. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  13. use Shopware\Core\Framework\Plugin;
  14. use League\Flysystem\Filesystem;
  15. use Iwv\IwvDatevV6\Core\Content\IwvDatev\ScheduledExportDefinition;
  16. use Iwv\IwvDatevV6\Core\Content\IwvExtendedDocument\IwvExtDocDocumentPosition\IwvExtDocDocumentPositionDefinition;
  17. use Iwv\IwvDatevV6\Core\Content\IwvExtendedDocument\IwvExtDocDocumentData\IwvExtDocDocumentDataDefinition;
  18. use Iwv\IwvDatevV6\Core\Content\IwvExtendedDocument\IwvExtDocAddressBilling\IwvExtDocAddressBillingDefinition;
  19. use Iwv\IwvDatevV6\Core\Content\IwvExtendedDocument\IwvExtDocAddressShipping\IwvExtDocAddressShippingDefinition;
  20. use Shopware\Core\Framework\Api\Acl\Role\AclRoleDefinition;
  21. class IwvDatevV6 extends Plugin
  22. {
  23.     public function enrichPrivileges(): array
  24.     {
  25.         $iwvExtDocPrivileges = [
  26.             'iwv_datev_v6_ext_doc_document_data:create',
  27.             'iwv_datev_v6_ext_doc_address_billing:create',
  28.             'iwv_datev_v6_ext_doc_address_shipping:create',
  29.             'iwv_datev_v6_ext_doc_document_position:create',
  30.             'iwv_datev_v6_ext_doc_document_data:read',
  31.             'iwv_datev_v6_ext_doc_address_billing:read',
  32.             'iwv_datev_v6_ext_doc_address_shipping:read',
  33.             'iwv_datev_v6_ext_doc_document_position:read',
  34.             'iwv_datev_v6_ext_doc_document_data:update',
  35.             'iwv_datev_v6_ext_doc_address_billing:update',
  36.             'iwv_datev_v6_ext_doc_address_shipping:update',
  37.             'iwv_datev_v6_ext_doc_document_position:update',
  38.             'iwv_datev_v6_ext_doc_document_data:delete',
  39.             'iwv_datev_v6_ext_doc_address_billing:delete',
  40.             'iwv_datev_v6_ext_doc_address_shipping:delete',
  41.             'iwv_datev_v6_ext_doc_document_position:delete',
  42.         ];
  43.         return [
  44.             'additional_permissions' => [
  45.                 'iwv_export_datev:export',
  46.             ],
  47.             'document.viewer' => $iwvExtDocPrivileges,
  48.             'document.editor' => $iwvExtDocPrivileges,
  49.             'document.creator' => $iwvExtDocPrivileges,
  50.             'document.deleter' => $iwvExtDocPrivileges,
  51.             AclRoleDefinition::ALL_ROLE_KEY => $iwvExtDocPrivileges
  52.         ];
  53.     }
  54.     public function uninstall(UninstallContext $context): void
  55.     {
  56.         if ($context->keepUserData()) {
  57.             return;
  58.         }
  59.         $connection $this->container->get(Connection::class);
  60.         $connection->executeUpdate('DELETE FROM system_config WHERE `configuration_key` LIKE "IwvDatevV6.config.%"');
  61.         $connection->exec('
  62.             SET FOREIGN_KEY_CHECKS = 0;
  63.             -- Migration1645612676CreateTableIwvDatevScheduledExport.php
  64.             DROP TABLE IF EXISTS `' ScheduledExportDefinition::ENTITY_NAME '`;
  65.             -- Migration1652863370IwvExtDocAddressBilling.php
  66.             DROP TABLE IF EXISTS `' IwvExtDocAddressBillingDefinition::ENTITY_NAME '`;
  67.             -- Migration1652863390IwvExtDocAddressShipping.php
  68.             DROP TABLE IF EXISTS `' IwvExtDocAddressShippingDefinition::ENTITY_NAME '`;
  69.             -- Migration1652863365IwvExtDocDocumentPosition.php
  70.             DROP TABLE IF EXISTS `' IwvExtDocDocumentPositionDefinition::ENTITY_NAME '`;
  71.             -- Migration1652863360IwvExtDocDocumentData.php
  72.             DROP TABLE IF EXISTS `' IwvExtDocDocumentDataDefinition::ENTITY_NAME '`;
  73.             SET FOREIGN_KEY_CHECKS = 1;
  74.         ');
  75.         /** @var Filesystem $fs */
  76.         try {
  77.             $fs $this->container->get('shopware.filesystem.private');
  78.             $pluginPath '/plugins/iwv_datev_v6';
  79.             if ($fs->has($pluginPath)) {
  80.                 $fs->deleteDir($pluginPath);
  81.             }
  82.         } catch (\Throwable $ex) {
  83.             
  84.         }
  85.         parent::uninstall($context);
  86.     }
  87. }