From bb42d32dc63a9f266e83d57afaa1ec98cb5dbcfc Mon Sep 17 00:00:00 2001 From: Marvin Muxfeld Date: Tue, 24 Sep 2024 15:17:05 +0200 Subject: [PATCH] PISHPS-353: removed error when uninstalling and reinstalling plugin --- .../Migration1725347559MollieTags.php | 25 +++++++++++++++++++ src/Service/SettingsService.php | 12 +++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Migration/Migration1725347559MollieTags.php b/src/Migration/Migration1725347559MollieTags.php index 1450f70fb..28cabbe4f 100644 --- a/src/Migration/Migration1725347559MollieTags.php +++ b/src/Migration/Migration1725347559MollieTags.php @@ -3,6 +3,7 @@ namespace Kiener\MolliePayments\Migration; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Result; use Kiener\MolliePayments\Struct\Tags\AbstractTag; use Kiener\MolliePayments\Struct\Tags\SubscriptionTag; use Shopware\Core\Framework\Log\Package; @@ -44,6 +45,13 @@ private function createTag( string $id, string $name ): void { + // migration must be able to run multiple times in succession + // with every install of the mollie plugin all migrations are run + // since tags don't count as plugin data, they're not purged and they must not be created again + if ($this->tagExists($connection, $id)) { + return; + } + $query = <<execute($parameters); } + + private function tagExists(Connection $connection, string $id): bool + { + $qb = $connection->createQueryBuilder(); + $qb->select('id') + ->from('tag') + ->where('id = :id') + ->setParameter('id', Uuid::fromHexToBytes($id)); + + $result = $qb->execute(); + + if ($result instanceof Result) { + return $result->rowCount() > 0; + } + + return false; + } } diff --git a/src/Service/SettingsService.php b/src/Service/SettingsService.php index 244fb83a9..424b645af 100644 --- a/src/Service/SettingsService.php +++ b/src/Service/SettingsService.php @@ -82,11 +82,13 @@ public function getSettings(?string $salesChannelId = null): MollieSettingStruct /** @var array $systemConfigData */ $systemConfigData = $this->systemConfigService->get(self::SYSTEM_CONFIG_DOMAIN, $salesChannelId); - foreach ($systemConfigData as $key => $value) { - if (stripos($key, self::SYSTEM_CONFIG_DOMAIN) !== false) { - $structData[substr($key, strlen(self::SYSTEM_CONFIG_DOMAIN))] = $value; - } else { - $structData[$key] = $value; + if (count($systemConfigData) !== 0) { + foreach ($systemConfigData as $key => $value) { + if (stripos($key, self::SYSTEM_CONFIG_DOMAIN) !== false) { + $structData[substr($key, strlen(self::SYSTEM_CONFIG_DOMAIN))] = $value; + } else { + $structData[$key] = $value; + } } }