Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PISHPS-353: removed errors when uninstalling and reinstalling plugin #842

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading