Skip to content

Commit

Permalink
PISHPS-353: removed error when uninstalling and reinstalling plugin (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muxfeld-diw authored Sep 25, 2024
1 parent e3a135c commit 8efb5e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/Migration/Migration1725347559MollieTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = <<<SQL
INSERT INTO tag
(id, name, created_at, updated_at)
Expand All @@ -61,4 +69,21 @@ private function createTag(

$stmt->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;
}
}
12 changes: 7 additions & 5 deletions src/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ public function getSettings(?string $salesChannelId = null): MollieSettingStruct
/** @var array<mixed> $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;
}
}
}

Expand Down

0 comments on commit 8efb5e3

Please sign in to comment.