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

SW-671 Composer 2 runtime api fix #239

Merged
merged 5 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion src/FinSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use function is_numeric;
use function json_decode;
use function ltrim;
use function method_exists;

class FinSearch extends Plugin
{
Expand Down Expand Up @@ -93,7 +94,11 @@ public static function isCompatible(InstallContext $installContext, string $comp
private function deleteFindologicConfig(): void
{
$connection = $this->container->get(Connection::class);
$connection->executeUpdate('DROP TABLE IF EXISTS `finsearch_config`');
if (method_exists($connection, 'executeStatement')) {
$connection->executeStatement('DROP TABLE IF EXISTS `finsearch_config`');
} else {
$connection->executeUpdate('DROP TABLE IF EXISTS `finsearch_config`');
}
}

protected static function isVersionLower(string $currentVersion, array $compatibleVersions): bool
Expand Down
28 changes: 23 additions & 5 deletions src/Migration/Migration1605714035FinSearchConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace FINDOLOGIC\FinSearch\Migration;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Exception;
use FINDOLOGIC\FinSearch\Utils\Utils;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Migration\MigrationStep;
Expand Down Expand Up @@ -34,7 +34,11 @@ public function update(Connection $connection): void
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
SQL;

$connection->executeUpdate($sql);
if (method_exists($connection, 'executeStatement')) {
$connection->executeStatement($sql);
} else {
$connection->executeUpdate($sql);
}

$this->insertPreviousConfigurationIfExists($connection);
}
Expand All @@ -58,7 +62,12 @@ private function insertPreviousConfigurationIfExists(Connection $connection): vo
WHERE `configuration_key` LIKE '%FinSearch.config%'
SQL;

$configs = $connection->fetchAll($sql);
if (method_exists($connection, 'fetchAllAssociative')) {
$configs = $connection->fetchAllAssociative($sql);
} else {
$configs = $connection->fetchAll($sql);
}

if (Utils::isEmpty($configs)) {
return;
}
Expand All @@ -70,7 +79,12 @@ private function insertPreviousConfigurationIfExists(Connection $connection): vo
}

$sql = 'SELECT LOWER(HEX(`language_id`)) AS `language_id` FROM `sales_channel` WHERE `id` = UNHEX(?)';
$languageId = $connection->fetchColumn($sql, [$salesChannelId]);
if (method_exists($connection, 'fetchOne')) {
$languageId = $connection->fetchOne($sql, [$salesChannelId]);
} else {
$languageId = $connection->fetchColumn($sql, [$salesChannelId]);
}

if (!$languageId) {
continue;
}
Expand All @@ -80,7 +94,7 @@ private function insertPreviousConfigurationIfExists(Connection $connection): vo
$data['sales_channel_id'] = Uuid::fromHexToBytes($salesChannelId);
try {
$connection->insert('finsearch_config', $data);
} catch (DBALException $ignored) {
} catch (Exception $ignored) {
// Do nothing here as configuration already exists
}
}
Expand All @@ -90,6 +104,10 @@ private function getDefaultSalesChannelId(Connection $connection)
{
$sql = 'SELECT LOWER(HEX(`id`)) AS `id` FROM `sales_channel` WHERE `type_id` = UNHEX(?) AND `active` = \'1\'';

if (method_exists($connection, 'fetchOne')) {
return $connection->fetchOne($sql, [Defaults::SALES_CHANNEL_TYPE_STOREFRONT]);
}

return $connection->fetchColumn($sql, [Defaults::SALES_CHANNEL_TYPE_STOREFRONT]);
}
}
27 changes: 18 additions & 9 deletions src/Utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FINDOLOGIC\FinSearch\Utils;

use Composer\InstalledVersions;
use FINDOLOGIC\FinSearch\Definitions\Defaults;
use FINDOLOGIC\FinSearch\Findologic\Resource\ServiceConfigResource;
use FINDOLOGIC\FinSearch\Struct\Config;
Expand Down Expand Up @@ -149,15 +150,23 @@ public static function getCleanShopwareVersion(): string
*/
protected static function getShopwareVersion(): string
{
$packageVersions = Versions::VERSIONS;
$coreIsInstalled = isset($packageVersions['shopware/core']);

$shopwareVersion = $coreIsInstalled ?
Versions::getVersion('shopware/core') :
Versions::getVersion('shopware/platform');

if (!trim($shopwareVersion, 'v@')) {
return $coreIsInstalled ? $packageVersions['shopware/core'] : $packageVersions['shopware/platform'];
zaifastafa marked this conversation as resolved.
Show resolved Hide resolved
// Composer 2 runtime API uses the `InstalledVersions::class` in favor of the
// deprecated/removed `Versions::class`
if (class_exists(InstalledVersions::class)) {
$platformIsInstalled = InstalledVersions::isInstalled('shopware/platform');
if ($platformIsInstalled) {
$shopwareVersion = InstalledVersions::getPrettyVersion('shopware/platform');
} else {
$shopwareVersion = InstalledVersions::getPrettyVersion('shopware/core');
}
zaifastafa marked this conversation as resolved.
Show resolved Hide resolved
} else {
$packageVersions = Versions::VERSIONS;
$platformIsInstalled = isset($packageVersions['shopware/platform']);
if ($platformIsInstalled) {
$shopwareVersion = Versions::getVersion('shopware/platform');
} else {
$shopwareVersion = Versions::getVersion('shopware/core');
}
}

return $shopwareVersion;
Expand Down