diff --git a/src/Compatibility/DependencyLoader.php b/src/Compatibility/DependencyLoader.php index 4f2e6a166..63367a198 100644 --- a/src/Compatibility/DependencyLoader.php +++ b/src/Compatibility/DependencyLoader.php @@ -6,6 +6,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; class DependencyLoader @@ -15,13 +16,19 @@ class DependencyLoader */ private $container; + /** + * @var VersionCompare + */ + private $versionCompare; + /** * @param Container $container */ - public function __construct(Container $container) + public function __construct(ContainerInterface $container, VersionCompare $versionCompare) { $this->container = $container; + $this->versionCompare = $versionCompare; } /** @@ -29,10 +36,6 @@ public function __construct(Container $container) */ public function loadServices(): void { - /** @var string $version */ - $version = $this->container->getParameter('kernel.shopware_version'); - - $versionCompare = new VersionCompare($version); /** @var ContainerBuilder $containerBuilder */ @@ -44,21 +47,22 @@ public function loadServices(): void # load Flow Builder $loader->load('compatibility/flowbuilder/all_versions.xml'); - if ($versionCompare->gte('6.4.6.0')) { + if ($this->versionCompare->gte('6.4.6.0')) { $loader->load('compatibility/flowbuilder/6.4.6.0.xml'); } - $composerDevReqsInstalled = file_exists(__DIR__ . '/../../vendor/bin/phpunit'); + $composerDevReqsInstalled = file_exists(__DIR__.'/../../vendor/bin/phpunit'); if ($composerDevReqsInstalled) { - $dirFixtures = __DIR__ . '/../../tests/Fixtures'; + $dirFixtures = (string)realpath(__DIR__ . '/../../tests/Fixtures/'); if (is_dir($dirFixtures)) { # we need to tell Shopware to load our custom fixtures # from our TEST autoload-dev area.... $classLoader = new ClassLoader(); $classLoader->addPsr4("MolliePayments\\Fixtures\\", $dirFixtures, true); + $classLoader->register(); $loader->load('services/fixtures/fixtures.xml'); @@ -71,11 +75,6 @@ public function loadServices(): void */ public function prepareStorefrontBuild(): void { - /** @var string $version */ - $version = $this->container->getParameter('kernel.shopware_version'); - - $versionCompare = new VersionCompare($version); - $pluginRoot = __DIR__ . '/../..'; $distFileFolder = $pluginRoot . '/src/Resources/app/storefront/dist/storefront/js'; @@ -84,7 +83,7 @@ public function prepareStorefrontBuild(): void mkdir($distFileFolder, 0777, true); } - if ($versionCompare->gte('6.5')) { + if ($this->versionCompare->gte('6.5')) { $file = $pluginRoot . '/src/Resources/app/storefront/dist/mollie-payments-65.js'; $target = $distFileFolder . '/mollie-payments.js'; } else { diff --git a/src/Migration/Migration1711618833SubscriptionCurrency.php b/src/Migration/Migration1711618833SubscriptionCurrency.php index 2006daa22..785762f5a 100644 --- a/src/Migration/Migration1711618833SubscriptionCurrency.php +++ b/src/Migration/Migration1711618833SubscriptionCurrency.php @@ -21,6 +21,11 @@ public function getCreationTimestamp(): int public function update(Connection $connection): void { $utils = new MigrationUtils($connection); + + // sometimes there is a problem with migration, so we check if the currency field was removed, if it not there anymore, we dont need to run the migration + if (!$utils->columnExists('mollie_subscription', 'currency')) { + return; + } // add new columns $sql = "ALTER TABLE `mollie_subscription` ADD COLUMN `currency_id` BINARY(16) NULL AFTER `currency`, diff --git a/src/Migration/MigrationUtils.php b/src/Migration/MigrationUtils.php index f7808e73b..3bb1563d8 100644 --- a/src/Migration/MigrationUtils.php +++ b/src/Migration/MigrationUtils.php @@ -31,7 +31,7 @@ public function __construct(Connection $connection) */ public function createColumn(string $table, string $column, string $type, string $default, string $after): void { - $colQuery = $this->connection->executeQuery("SHOW COLUMNS FROM " . $table . " LIKE '" . $column . "'")->fetch(); + $colQuery = $this->columnExists($table, $column); # only create if not yet existing if ($colQuery === false) { @@ -57,7 +57,7 @@ public function createColumn(string $table, string $column, string $type, string */ public function deleteColumn(string $table, string $column): void { - $colQuery = $this->connection->executeQuery("SHOW COLUMNS FROM " . $table . " LIKE '" . $column . "'")->fetch(); + $colQuery = $this->columnExists($table, $column); # only delete if existing if ($colQuery !== false) { @@ -66,6 +66,11 @@ public function deleteColumn(string $table, string $column): void } } + public function columnExists(string $table, string $column): bool + { + return (bool)$this->connection->executeQuery("SHOW COLUMNS FROM " . $table . " LIKE '" . $column . "'")->fetchOne(); + } + /** * @param string $table * @param string $keyName diff --git a/src/MolliePayments.php b/src/MolliePayments.php index 79de05928..c12bf8ed8 100644 --- a/src/MolliePayments.php +++ b/src/MolliePayments.php @@ -4,6 +4,7 @@ use Exception; use Kiener\MolliePayments\Compatibility\DependencyLoader; +use Kiener\MolliePayments\Compatibility\VersionCompare; use Kiener\MolliePayments\Components\Installer\PluginInstaller; use Kiener\MolliePayments\Repository\CustomFieldSet\CustomFieldSetRepository; use Psr\Container\ContainerInterface; @@ -36,10 +37,13 @@ public function build(ContainerBuilder $container): void parent::build($container); $this->container = $container; - + $shopwareVersion = $this->container->getParameter('kernel.shopware_version'); + if (!is_string($shopwareVersion)) { + $shopwareVersion= Kernel::SHOPWARE_FALLBACK_VERSION; + } # load the dependencies that are compatible # with our current shopware version - $loader = new DependencyLoader($this->container); + $loader = new DependencyLoader($this->container, new VersionCompare($shopwareVersion)); $loader->loadServices(); $loader->prepareStorefrontBuild(); }