custom/plugins/AcrisProductDownloadsCS/src/AcrisProductDownloadsCS.php line 26

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\ProductDownloads;
  3. use Acris\ImportExport\AcrisImportExport;
  4. use Acris\ImportExport\AcrisImportExportCS;
  5. use Doctrine\DBAL\Connection;
  6. use Shopware\Core\Content\ImportExport\Aggregate\ImportExportLog\ImportExportLogEntity;
  7. use Shopware\Core\Content\ImportExport\ImportExportProfileEntity;
  8. use Shopware\Core\Content\Media\Aggregate\MediaDefaultFolder\MediaDefaultFolderEntity;
  9. use Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderEntity;
  10. use Shopware\Core\Defaults;
  11. use Shopware\Core\Framework\Context;
  12. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
  15. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  16. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  17. use Shopware\Core\Framework\DataAbstractionLayer\Search\IdSearchResult;
  18. use Shopware\Core\Framework\Plugin;
  19. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  20. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  21. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  22. use Shopware\Core\System\SystemConfig\SystemConfigEntity;
  23. class AcrisProductDownloadsCS extends Plugin
  24. {
  25.     const DEFAULT_PRODUCT_DOWNLOADS_IMPORT_EXPORT_PROFILE_NAME 'ACRIS Product Downloads';
  26.     const DEFAULT_PRODUCT_DOWNLOADS_IMPORT_EXPORT_NO_IMPORT_PLUGIN_PROFILE_NAME 'ACRIS Product Downloads ( nur für export )';
  27.     const DEFAULT_PRODUCT_DOWNLOADS_PROCESS_NAME 'Product downloads import';
  28.     const DEFAULT_PRODUCT_DOWNLOADS_FILE_NAME 'Product_downloads';
  29.     const DEFAULT_MEDIA_FOLDER_NAME "Produkt Downloads";
  30.     const DEFAULT_MEDIA_FOLDER_CUSTOM_FIELD 'acrisProductDownloadsFolder';
  31.     public function uninstall(UninstallContext $context): void
  32.     {
  33.         if ($context->keepUserData()) {
  34.             return;
  35.         }
  36.         $this->cleanupDatabase();
  37.         $this->removeMediaUploadFolder($context->getContext());
  38.         $this->removeImportExportProfiles($context->getContext(), $this->getCriteriaForRemovingImportExportProfiles());
  39.         $this->removeDefaultValuesForImportExportPlugin($context->getContext());
  40.     }
  41.     public function postUpdate(UpdateContext $context): void
  42.     {
  43.         if(version_compare($context->getCurrentPluginVersion(), '1.1.1''<')) {
  44.             if($context->getPlugin()->isActive() === true) {
  45.                 $this->insertDefaultImportExportProfile($context->getContext());
  46.                 $this->insertDefaultValuesForImportExportPlugin($context->getContext());
  47.             }
  48.         }
  49.         if(version_compare($context->getCurrentPluginVersion(), '2.1.0''<')
  50.             && version_compare($context->getUpdatePluginVersion(), '2.1.0''>=')) {
  51.             if($context->getPlugin()->isActive() === true) {
  52.                 $this->insertUpdateConfigValues($context->getContext());
  53.             }
  54.         }
  55.         if(version_compare($context->getCurrentPluginVersion(), '2.1.3''<')) {
  56.             if($context->getPlugin()->isActive() === true) {
  57.                 $this->insertDefaultImportExportProfile($context->getContext());
  58.                 $this->removeOldImportExportProfile($context->getContext());
  59.             }
  60.         }
  61.         if(version_compare($context->getCurrentPluginVersion(), '3.3.0''<')) {
  62.             if($context->getPlugin()->isActive() === true) {
  63.                 $this->insertDefaultDownloadTab($context->getContext());
  64.                 $this->updateImportExportProfile($context->getContext());
  65.             }
  66.         }
  67.     }
  68.     public function activate(ActivateContext $context): void
  69.     {
  70.         parent::activate($context);
  71.         $this->insertDefaultImportExportProfile($context->getContext());
  72.         $this->insertDefaultValuesForImportExportPlugin($context->getContext());
  73.         $this->insertDefaultDownloadTab($context->getContext());
  74.     }
  75.     private function getDefaultMediaUploadFolder(EntityRepositoryInterface $mediaFolderRepositoryContext $context): ?MediaFolderEntity
  76.     {
  77.         return $mediaFolderRepository->search((new Criteria())->addAssociation('media')->addAssociation('configuration')->addAssociation('configuration.mediaFolders')->addFilter(new EqualsFilter('customFields.'.self::DEFAULT_MEDIA_FOLDER_CUSTOM_FIELD'true')), $context)->first();
  78.     }
  79.     private function getDefaultMediaDefaultUploadFolder(EntityRepositoryInterface $mediaDefaultFolderRepositoryContext $context): ?MediaDefaultFolderEntity
  80.     {
  81.         return $mediaDefaultFolderRepository->search((new Criteria())->addAssociation('folder')->addFilter(new EqualsFilter('customFields.'.self::DEFAULT_MEDIA_FOLDER_CUSTOM_FIELD'true')), $context)->first();
  82.     }
  83.     private function updateImportExportProfile(Context $context): void
  84.     {
  85.         /** @var EntityRepositoryInterface $profileRepository */
  86.         $profileRepository $this->container->get('import_export_profile.repository');
  87.         $profileId $this->getProfileIdByName($profileRepositoryself::DEFAULT_PRODUCT_DOWNLOADS_IMPORT_EXPORT_PROFILE_NAME$context);
  88.         if (empty($profileId)) return;
  89.         $profileRepository->update([
  90.             [
  91.                 'id' => $profileId,
  92.                 'mapping' => $this->getDefaultImportProfileMappingData()
  93.             ]
  94.         ], $context);
  95.     }
  96.     private function getDefaultImportProfileMappingData(): array
  97.     {
  98.         return [
  99.             [
  100.                 'key' => 'downloadTab.internalId',
  101.                 'mappedKey' => 'DownloadTab'
  102.             ],
  103.             [
  104.                 'key' => 'products.productNumber',
  105.                 'mappedKey' => 'ProductNumber'
  106.             ],
  107.             [
  108.                 'key' => 'media.fileName',
  109.                 'mappedKey' => 'MediaName'
  110.             ],
  111.             [
  112.                 'key' => 'position',
  113.                 'mappedKey' => 'Position'
  114.             ],
  115.             [
  116.                 'key' => 'translations.DEFAULT.title',
  117.                 'mappedKey' => 'Title'
  118.             ],
  119.             [
  120.                 'key' => 'translations.DEFAULT.description',
  121.                 'mappedKey' => 'Description'
  122.             ],
  123.             [
  124.                 'key' => 'languages',
  125.                 'mappedKey' => 'Languages'
  126.             ]
  127.         ];
  128.     }
  129.     private function getProfileIdByName(EntityRepositoryInterface $repositorystring $profileNameContext $context): ?string
  130.     {
  131.         return $repository->searchIds((new Criteria())->addFilter(new EqualsFilter('name'$profileName)), $context)->firstId();
  132.     }
  133.     private function cleanupDatabase(): void
  134.     {
  135.         $connection $this->container->get(Connection::class);
  136.         $connection->executeStatement('DROP TABLE IF EXISTS acris_product_download_language');
  137.         $connection->executeStatement('DROP TABLE IF EXISTS acris_product_download_translation');
  138.         $connection->executeStatement('DROP TABLE IF EXISTS acris_product_download');
  139.         $connection->executeStatement('DROP TABLE IF EXISTS acris_download_tab_translation');
  140.         $connection->executeStatement('DROP TABLE IF EXISTS acris_download_tab_rule');
  141.         $connection->executeStatement('DROP TABLE IF EXISTS acris_download_tab');
  142.         $this->removeInheritance($connection'rule''acrisDownloadTabs');
  143.         $this->removeInheritance($connection'product''acrisDownloads');
  144.         $this->removeInheritance($connection'media''acrisDownloads');
  145.         $this->removeInheritance($connection'language''acrisDownloads');
  146.         $connection->executeStatement('DROP TABLE IF EXISTS acris_product_link_language');
  147.         $connection->executeStatement('DROP TABLE IF EXISTS acris_product_link_translation');
  148.         $connection->executeStatement('DROP TABLE IF EXISTS acris_product_link');
  149.         $this->removeInheritance($connection'product''acrisLinks');
  150.         $this->removeInheritance($connection'language''acrisLinks');
  151.     }
  152.     private function removeMediaUploadFolder(Context $context): void
  153.     {
  154.         $mediaFolderRepository $this->container->get('media_folder.repository');
  155.         $defaultMediaFolderRepository $this->container->get('media_default_folder.repository');
  156.         $defaultMediaUploadFolder $this->getDefaultMediaUploadFolder($mediaFolderRepository$context);
  157.         $defaultMediaDefaultUploadFolder $this->getDefaultMediaDefaultUploadFolder($defaultMediaFolderRepository$context);
  158.         if($defaultMediaUploadFolder instanceof MediaFolderEntity) {
  159.             if($defaultMediaUploadFolder->getMedia() && $defaultMediaUploadFolder->getMedia()->count() > 0) {
  160.                 return;
  161.             }
  162.             if (!$defaultMediaDefaultUploadFolder instanceof MediaDefaultFolderEntity) {
  163.                 return;
  164.             }
  165.             $defaultMediaUploadFolderConfiguration $defaultMediaUploadFolder->getConfiguration();
  166.             $deleteConfigurationId null;
  167.             if($defaultMediaUploadFolderConfiguration && $defaultMediaUploadFolderConfiguration->getMediaFolders()) {
  168.                 if($defaultMediaUploadFolderConfiguration->getMediaFolders()->count() < 2) {
  169.                     $deleteConfigurationId $defaultMediaUploadFolderConfiguration->getId();
  170.                 }
  171.             }
  172.             $mediaFolderRepository->delete([['id' => $defaultMediaUploadFolder->getId()]], $context);
  173.             $defaultMediaFolderRepository->delete([['id' => $defaultMediaDefaultUploadFolder->getId()]], $context);
  174.             if($deleteConfigurationId !== null) {
  175.                 $this->container->get('media_folder_configuration.repository')->delete([['id' => $deleteConfigurationId]], $context);
  176.             }
  177.         }
  178.     }
  179.     private function insertDefaultImportExportProfile(Context $context): void
  180.     {
  181.         $importExportProfileRepository $this->container->get('import_export_profile.repository');
  182.         $defaultImportExportProfiles = [
  183.             [
  184.                 'name' => self::DEFAULT_PRODUCT_DOWNLOADS_IMPORT_EXPORT_PROFILE_NAME,
  185.                 'label' => self::DEFAULT_PRODUCT_DOWNLOADS_IMPORT_EXPORT_PROFILE_NAME,
  186.                 'systemDefault' => false,
  187.                 'sourceEntity' => 'acris_product_download',
  188.                 'fileType' => 'text/csv',
  189.                 'delimiter' => ';',
  190.                 'enclosure' => '"',
  191.                 'mapping' => [
  192.                     [
  193.                         'key' => 'products.productNumber',
  194.                         'mappedKey' => 'ProductNumber'
  195.                     ],
  196.                     [
  197.                         'key' => 'media.fileName',
  198.                         'mappedKey' => 'MediaName'
  199.                     ],
  200.                     [
  201.                         'key' => 'position',
  202.                         'mappedKey' => 'Position'
  203.                     ],
  204.                     [
  205.                         'key' => 'translations.DEFAULT.title',
  206.                         'mappedKey' => 'Title'
  207.                     ],
  208.                     [
  209.                         'key' => 'translations.DEFAULT.description',
  210.                         'mappedKey' => 'Description'
  211.                     ],
  212.                     [
  213.                         'key' => 'languages',
  214.                         'mappedKey' => 'Languages'
  215.                     ]
  216.                 ]
  217.             ]
  218.         ];
  219.         foreach ($defaultImportExportProfiles as $defaultImportExportProfile) {
  220.             $this->createIfNotExists($importExportProfileRepository, [['name' => 'name''value' => $defaultImportExportProfile['name']]], $defaultImportExportProfile$context);
  221.         }
  222.     }
  223.     protected function removeInheritance(Connection $connectionstring $entitystring $propertyName): void
  224.     {
  225.         $sql str_replace(
  226.             ['#table#''#column#'],
  227.             [$entity$propertyName],
  228.             'ALTER TABLE `#table#` DROP `#column#`'
  229.         );
  230.         $connection->executeStatement($sql);
  231.     }
  232.     private function createIfNotExists(EntityRepositoryInterface $repository, array $equalFields, array $dataContext $context): void
  233.     {
  234.         $filters = [];
  235.         foreach ($equalFields as $equalField) {
  236.             $filters[] = new EqualsFilter($equalField['name'], $equalField['value']);
  237.         }
  238.         if(sizeof($filters) > 1) {
  239.             $filter = new MultiFilter(MultiFilter::CONNECTION_OR$filters);
  240.         } else {
  241.             $filter array_shift($filters);
  242.         }
  243.         $searchResult $repository->search((new Criteria())->addFilter($filter), $context);
  244.         if($searchResult->count() == 0) {
  245.             $repository->create([$data], $context);
  246.         } elseif ($searchResult->count() > 0) {
  247.             $data['id'] = $searchResult->first()->getId();
  248.             $repository->update([$data], $context);
  249.         }
  250.     }
  251.     private function removeImportExportProfiles(Context $contextCriteria $criteria): void
  252.     {
  253.         $connection $this->container->get(Connection::class);
  254.         $importExportProfileRepository $this->container->get('import_export_profile.repository');
  255.         $importExportLogRepository $this->container->get('import_export_log.repository');
  256.         /** @var EntitySearchResult $searchResult */
  257.         $searchResult $importExportProfileRepository->search($criteria$context);
  258.         $ids = [];
  259.         /** @var \Shopware\Core\Framework\Uuid\Uuid $uuid */
  260.         $uuid = new \Shopware\Core\Framework\Uuid\Uuid();
  261.         if($searchResult->getTotal() > && $searchResult->first()) {
  262.             /** @var ImportExportProfileEntity $entity */
  263.             foreach ($searchResult->getEntities()->getElements() as $entity) {
  264.                 if ($entity->getSystemDefault() === true) {
  265.                     $importExportProfileRepository->update([
  266.                         ['id' => $entity->getId(), 'systemDefault' => false ]
  267.                     ], $context);
  268.                 }
  269.                 /** @var EntitySearchResult $logResult */
  270.                 $logResult $importExportLogRepository->search((new Criteria())->addFilter(new EqualsFilter('profileId'$entity->getId())), $context);
  271.                 if ($logResult->getTotal() > && $logResult->first()) {
  272.                     /** @var ImportExportLogEntity $logEntity */
  273.                     foreach ($logResult->getEntities() as $logEntity) {
  274.                         $stmt $connection->prepare("UPDATE import_export_log SET profile_id = :profileId WHERE id = :id");
  275.                         $stmt->execute(['profileId' => null'id' => $uuid::fromHexToBytes($logEntity->getId()) ]);
  276.                     }
  277.                 }
  278.                 $ids[] = ['id' => $entity->getId()];
  279.             }
  280.             $importExportProfileRepository->delete($ids$context);
  281.         }
  282.     }
  283.     private function insertDefaultValuesForImportExportPlugin(Context $context): void
  284.     {
  285.         $kernelPluginCollection $this->container->get('Shopware\Core\Framework\Plugin\KernelPluginCollection');
  286.         /** @var AcrisImportExport $importExportPlugin */
  287.         $importExportPlugin $kernelPluginCollection->get(AcrisImportExport::class);
  288.         /** @var AcrisImportExportCS $importExportPlugin */
  289.         $importExportPluginCS $kernelPluginCollection->get(AcrisImportExportCS::class);
  290.         if (($importExportPlugin === null || $importExportPlugin->isActive() === false) && ($importExportPluginCS === null || $importExportPluginCS->isActive() === false)) {
  291.             return;
  292.         }
  293.         $this->insertDefaultIdentifiers($context);
  294.         $this->insertDefaultProcess($context);
  295.     }
  296.     private function insertDefaultIdentifiers(Context $context): void
  297.     {
  298.         /** @var EntityRepositoryInterface $identifierRepository */
  299.         $identifierRepository $this->container->get('acris_import_export_identifier.repository');
  300.         $defaultIdentifiers = [
  301.             [
  302.                 'entity' => 'product',
  303.                 'identifier' => 'productNumber',
  304.                 'priority' => 10,
  305.                 'active' => true
  306.             ],[
  307.                 'entity' => 'media',
  308.                 'identifier' => 'fileName',
  309.                 'priority' => 10,
  310.                 'active' => true
  311.             ]
  312.         ];
  313.         foreach ($defaultIdentifiers as $defaultIdentifier) {
  314.             $this->createIdentifierIfNotExists($identifierRepository$context$defaultIdentifier);
  315.         }
  316.     }
  317.     private function insertDefaultProcess(Context $context): void
  318.     {
  319.         /** @var EntityRepositoryInterface $processRepository */
  320.         $processRepository $this->container->get('acris_import_export_process.repository');
  321.         $defaultProductDownloadsProcessFields = [
  322.             [
  323.                 'name' => 'id',
  324.                 'active' => true,
  325.                 'addIfNotExists' => true,
  326.                 'conversion' => '$productKey = $data["products"]["productNumber"]; if( array_key_exists($productKey, $this->preparedData) ) { $rowData = $this->preparedData[$productKey]; if ($rowData && array_key_exists(\'productId\', $rowData) && array_key_exists(\'mediaId\', $rowData)) if ($value !== $rowData["productId"] && $value !== $rowData["mediaId"] ) { $value = $rowData["id"]; } }',
  327.                 'dataType' => 'string',
  328.                 'required' => false
  329.             ],
  330.             [
  331.                 'name' => 'media',
  332.                 'active' => true,
  333.                 'conversion' => 'if ($value && array_key_exists(\'fileName\', $value)) { $fileName = $value[\'fileName\']; $mediaRepository = $this->container->get(\'media.repository\'); $searchResult = $context->disableCache(function ($context) use ($mediaRepository, $fileName) { return $mediaRepository->searchIds((new Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria())->addFilter(new Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter(\'fileName\', $fileName)), $context); }); $mediaId = $searchResult->firstId(); if($mediaId) { $value[\'id\'] = $mediaId; } unset($value[\'fileName\']); }',
  334.                 'dataType' => 'array',
  335.                 'required' => false
  336.             ]
  337.         ];
  338.         $defaultProcesses = [
  339.             [
  340.                 'name' => self::DEFAULT_PRODUCT_DOWNLOADS_PROCESS_NAME,
  341.                 'fileName' => self::DEFAULT_PRODUCT_DOWNLOADS_FILE_NAME ".csv",
  342.                 'profileName' => self::DEFAULT_PRODUCT_DOWNLOADS_IMPORT_EXPORT_PROFILE_NAME,
  343.                 'mode' => 'import',
  344.                 'importType' =>'file',
  345.                 'priority' => 10,
  346.                 'active' => true,
  347.                 'prepareData' => '$rowKey = $row["ProductNumber"]; if ($row && array_key_exists(\'ProductNumber\', $row) && array_key_exists(\'MediaName\', $row)) { $productNumber = $row[\'ProductNumber\']; $productRepository = $this->container->get(\'product.repository\'); $searchResult = $context->disableCache(function ($context) use ($productRepository, $productNumber) { return $productRepository->searchIds((new Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria())->addFilter(new Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter(\'productNumber\', $productNumber)), $context); }); $productId = $searchResult->firstId(); if($productId) { $fileName = $row[\'MediaName\']; $mediaRepository = $this->container->get(\'media.repository\'); $searchResult = $context->disableCache(function ($context) use ($mediaRepository, $fileName) { return $mediaRepository->searchIds((new Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria())->addFilter(new Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter(\'fileName\', $fileName)), $context); }); $mediaId = $searchResult->firstId(); if($mediaId) { $productDownloadsRepository = $this->container->get(\'acris_product_download.repository\'); $searchResult = $context->disableCache(function ($context) use ($productDownloadsRepository, $productId, $mediaId) { return $productDownloadsRepository->searchIds((new Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria())->addFilter(new Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter(\'productId\', $productId))->addFilter(new Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter(\'mediaId\', $mediaId)), $context); }); $productDownloadsId = $searchResult->firstId(); if ($productDownloadsId) { $row[\'productId\'] = $productId; $row[\'mediaId\'] = $mediaId; $row[\'id\'] = $productDownloadsId; } } } } $this->preparedData[$rowKey] = $row;',
  348.                 'processFields' => $defaultProductDownloadsProcessFields
  349.             ]
  350.         ];
  351.         foreach ($defaultProcesses as $defaultProcess) {
  352.             $this->createProcessIfNotExists($processRepository$context$defaultProcess);
  353.         }
  354.     }
  355.     /**
  356.      * @param EntityRepositoryInterface $entityRepository
  357.      * @param Context $context
  358.      * @param array $identifierData
  359.      */
  360.     private function createIdentifierIfNotExists(EntityRepositoryInterface $entityRepositoryContext $context, array $identifierData): void
  361.     {
  362.         $exists $entityRepository->search((new Criteria())->addFilter(new MultiFilter(MultiFilter::CONNECTION_AND, [new EqualsFilter('entity'$identifierData['entity']), new EqualsFilter('identifier'$identifierData['identifier'])])), $context);
  363.         if($exists->getTotal() === 0) {
  364.             $entityRepository->create([$identifierData], $context);
  365.         }
  366.     }
  367.     /**
  368.      * @param EntityRepositoryInterface $entityRepository
  369.      * @param Context $context
  370.      * @param array $processData
  371.      */
  372.     private function createProcessIfNotExists(EntityRepositoryInterface $entityRepositoryContext $context, array $processData): void
  373.     {
  374.         $exists $entityRepository->search((new Criteria())->addFilter(new EqualsFilter('name'$processData['name'])), $context);
  375.         if($exists->getTotal() === 0) {
  376.             $entityRepository->create([$processData], $context);
  377.         }
  378.     }
  379.     private function removeDefaultValuesForImportExportPlugin(Context $context): void
  380.     {
  381.         $kernelPluginCollection $this->container->get('Shopware\Core\Framework\Plugin\KernelPluginCollection');
  382.         /** @var AcrisImportExport $importExportPlugin */
  383.         $importExportPlugin $kernelPluginCollection->get(AcrisImportExport::class);
  384.         /** @var AcrisImportExportCS $importExportPlugin */
  385.         $importExportPluginCS $kernelPluginCollection->get(AcrisImportExportCS::class);
  386.         if (($importExportPlugin === null || $importExportPlugin->isActive() === false) && ($importExportPluginCS === null || $importExportPluginCS->isActive() === false)) {
  387.             return;
  388.         }
  389.         $this->removeDefaultProcess($context);
  390.     }
  391.     private function removeDefaultProcess(Context $context): void
  392.     {
  393.         /** @var EntityRepositoryInterface $processRepository */
  394.         $processRepository $this->container->get('acris_import_export_process.repository');
  395.         $searchResult $processRepository->searchIds((new Criteria())->addFilter(
  396.             new EqualsFilter('name'self::DEFAULT_PRODUCT_DOWNLOADS_PROCESS_NAME)
  397.         ), $context);
  398.         $ids = [];
  399.         if ($searchResult->getTotal() > 0) {
  400.             foreach ($searchResult->getIds() as $id) {
  401.                 $ids[] = ['id' => $id];
  402.             }
  403.             $processRepository->delete($ids$context);
  404.         }
  405.     }
  406.     private function insertUpdateConfigValues(Context $context): void
  407.     {
  408.         $systemConfiguration $this->container->get('system_config.repository');
  409.         /** @var SystemConfigEntity $configValue */
  410.         $configValue $systemConfiguration->search((new Criteria())->addFilter(new EqualsFilter('configurationKey''AcrisProductDownloadsCS.config.acrisShowDownloadsAsTab')), $context)->first();
  411.         /** @var SystemConfigEntity $configNewValue */
  412.         $configNewValue $systemConfiguration->search((new Criteria())->addFilter(new EqualsFilter('configurationKey''AcrisProductDownloadsCS.config.displayPosition')), $context)->first();
  413.         if (!empty($configValue) && !empty($configValue->getConfigurationValue()) && is_bool($configValue->getConfigurationValue()) && $configValue->getConfigurationValue() === true) {
  414.             if (!empty($configNewValue)) {
  415.                 $systemConfiguration->upsert([
  416.                     [
  417.                         'id' => $configNewValue->getId(),
  418.                         'configurationKey' => 'AcrisProductDownloadsCS.config.displayPosition',
  419.                         'configurationValue' => 'afterReviews',
  420.                         'salesChannelId' => null
  421.                     ]
  422.                 ], $context);
  423.             } else {
  424.                 $systemConfiguration->upsert([
  425.                     [
  426.                         'configurationKey' => 'AcrisProductDownloadsCS.config.displayPosition',
  427.                         'configurationValue' => 'afterReviews',
  428.                         'salesChannelId' => null
  429.                     ]
  430.                 ], $context);
  431.             }
  432.         } else {
  433.             if (!empty($configNewValue)) {
  434.                 $systemConfiguration->upsert([
  435.                     [
  436.                         'id' => $configNewValue->getId(),
  437.                         'configurationKey' => 'AcrisProductDownloadsCS.config.displayPosition',
  438.                         'configurationValue' => 'noDisplay',
  439.                         'salesChannelId' => null
  440.                     ]
  441.                 ], $context);
  442.             } else {
  443.                 $systemConfiguration->upsert([
  444.                     [
  445.                         'configurationKey' => 'AcrisProductDownloadsCS.config.displayPosition',
  446.                         'configurationValue' => 'noDisplay',
  447.                         'salesChannelId' => null
  448.                     ]
  449.                 ], $context);
  450.             }
  451.         }
  452.     }
  453.     private function removeOldImportExportProfile(Context $context): void
  454.     {
  455.         $criteria = new Criteria();
  456.         $criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_AND, [
  457.             new EqualsFilter('sourceEntity''acris_product_download'),
  458.             new EqualsFilter('name'self::DEFAULT_PRODUCT_DOWNLOADS_IMPORT_EXPORT_NO_IMPORT_PLUGIN_PROFILE_NAME)
  459.         ]));
  460.         $this->removeImportExportProfiles($context$criteria);
  461.     }
  462.     private function getCriteriaForRemovingImportExportProfiles(): Criteria
  463.     {
  464.         $criteria = new Criteria();
  465.         $criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_OR, [
  466.             new EqualsFilter('sourceEntity''acris_product_download')
  467.         ]));
  468.         return $criteria;
  469.     }
  470.     private function insertDefaultDownloadTab(Context $context): void
  471.     {
  472.         $downloadTabRepository $this->container->get('acris_download_tab.repository');
  473.         /** @var IdSearchResult $IdSearchResult */
  474.         $IdSearchResult $downloadTabRepository->searchIds((new Criteria()), $context);
  475.         if($IdSearchResult->getTotal() == 0) {
  476.             $downloadTabRepository->create($this->getDefaultDownloadTabData(), $context);
  477.         }
  478.     }
  479.     private function getDefaultDownloadTabData(): array
  480.     {
  481.         return [
  482.             [
  483.                 'internalId' => 'downloadgroup_1',
  484.                 'priority' => 10,
  485.                 'translations' => [
  486.                     'en-GB' => [
  487.                         'displayName' => "Default download tab"
  488.                     ],
  489.                     'de-DE' => [
  490.                         'displayName' => "Standard-Download-Registerkarte"
  491.                     ],
  492.                     [
  493.                         'displayName' => "Default download tab",
  494.                         'languageId' => Defaults::LANGUAGE_SYSTEM
  495.                     ]
  496.                 ]
  497.             ]
  498.         ];
  499.     }
  500. }