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

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