Skip to content
Open
Show file tree
Hide file tree
Changes from 16 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\Core\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Migration\MigrationStep;

/**
* @internal
*/
#[Package('fundamentals@after-sales')]
class Migration1764145444AddFingerprintToConnectionTable extends MigrationStep
{
public const TABLE = 'swag_migration_connection';

public const COLUMN = 'source_system_fingerprint';

public function getCreationTimestamp(): int
{
return 1764145444;
}

public function update(Connection $connection): void
{
$this->addColumn(
connection: $connection,
table: self::TABLE,
column: self::COLUMN,
type: 'VARCHAR(255)',
);
}
}
17 changes: 16 additions & 1 deletion src/DataProvider/Service/EnvironmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Shopware\Core\Defaults;
use Shopware\Core\Framework\Api\Context\SystemSource;
use Shopware\Core\Framework\App\ShopId\ShopIdProvider;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
Expand All @@ -18,6 +19,7 @@
use Shopware\Core\Framework\Store\Services\StoreClient;
use Shopware\Core\System\Currency\CurrencyCollection;
use Shopware\Core\System\Language\LanguageCollection;
use Shopware\Core\System\SystemConfig\SystemConfigService;

#[Package('fundamentals@after-sales')]
class EnvironmentService implements EnvironmentServiceInterface
Expand All @@ -33,11 +35,12 @@ public function __construct(
private readonly string $shopwareRevision,
private readonly StoreClient $storeClient,
private readonly AbstractExtensionDataProvider $extensionDataProvider,
private readonly SystemConfigService $systemConfigService,
) {
}

/**
* @return array<string, string|bool|array<mixed>>
* @return array<string, string|bool|array<string, mixed>|null>
*/
public function getEnvironmentData(Context $context): array
{
Expand Down Expand Up @@ -72,9 +75,21 @@ public function getEnvironmentData(Context $context): array
'revision' => $this->shopwareRevision,
'additionalData' => [],
'updateAvailable' => $updateAvailable,
'shopIdV2' => $this->getShopIdV2(),
];
}

private function getShopIdV2(): ?string
{
$response = $this->systemConfigService->get(ShopIdProvider::SHOP_ID_SYSTEM_CONFIG_KEY_V2);

if (\is_array($response) && isset($response['id'])) {
return $response['id'];
}

return null;
}

private function isPluginUpdateAvailable(Context $context): bool
{
$criteria = new Criteria();
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/dataProvider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
<argument>%kernel.shopware_version_revision%</argument>
<argument type="service" id="Shopware\Core\Framework\Store\Services\StoreClient"/>
<argument type="service" id="Shopware\Core\Framework\Store\Services\AbstractExtensionDataProvider"/>
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
</service>

</services>
Expand Down
19 changes: 19 additions & 0 deletions src/DependencyInjection/migration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@
<tag name="kernel.reset" method="reset"/>
</service>

<service id="SwagMigrationAssistant\Migration\Connection\Fingerprint\Provider\Shopware5FingerprintProvider">
<argument type="service" id="SwagMigrationAssistant\Migration\MigrationContextFactory"/>
<argument type="service" id="SwagMigrationAssistant\Profile\Shopware\Gateway\Api\Reader\EnvironmentReader"/>
<argument type="service" id="SwagMigrationAssistant\Profile\Shopware\Gateway\Local\Reader\EnvironmentReader"/>
<tag name="shopware.migration.fingerprint_provider"/>
</service>

<service id="SwagMigrationAssistant\Migration\Connection\Fingerprint\Provider\Shopware6FingerprintProvider">
<argument type="service" id="SwagMigrationAssistant\Migration\MigrationContextFactory"/>
<argument type="service" id="SwagMigrationAssistant\Profile\Shopware6\Gateway\Api\Reader\EnvironmentReader"/>
<tag name="shopware.migration.fingerprint_provider"/>
</service>

<service id="SwagMigrationAssistant\Migration\Connection\Fingerprint\MigrationFingerprintService">
<argument type="tagged_iterator" tag="shopware.migration.fingerprint_provider"/>
<argument type="service" id="swag_migration_connection.repository"/>
</service>

<service id="SwagMigrationAssistant\Migration\Run\RunService">
<argument type="service" id="swag_migration_run.repository"/>
<argument type="service" id="swag_migration_connection.repository"/>
Expand All @@ -192,6 +210,7 @@
<argument type="service" id="SwagMigrationAssistant\Migration\MigrationContextFactory"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Service\PremappingService"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Run\RunTransitionService"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Connection\Fingerprint\MigrationFingerprintService"/>
</service>

<service id="SwagMigrationAssistant\Migration\Run\RunTransitionService">
Expand Down
14 changes: 14 additions & 0 deletions src/Exception/MigrationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Shopware\Core\Framework\Log\Package;
use Symfony\Component\HttpFoundation\Response;

/**
* @codeCoverageIgnore
*/
#[Package('fundamentals@after-sales')]
class MigrationException extends HttpException
{
Expand Down Expand Up @@ -110,6 +113,8 @@ class MigrationException extends HttpException

public const INVALID_ID = 'SWAG_MIGRATION__INVALID_ID';

public const DUPLICATE_SOURCE_CONNECTION = 'SWAG_MIGRATION__DUPLICATE_SOURCE_CONNECTION';

public static function associationEntityRequiredMissing(string $entity, string $missingEntity): self
{
return new AssociationEntityRequiredMissingException(
Expand Down Expand Up @@ -581,4 +586,13 @@ public static function invalidId(string $entityId, string $entityName): self
['entityId' => $entityId, 'entityName' => $entityName]
);
}

public static function duplicateSourceConnection(): self
{
return new self(
Response::HTTP_CONFLICT,
self::DUPLICATE_SOURCE_CONNECTION,
'A connection to this source system already exists.',
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\Migration\Connection\Fingerprint;

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\Connection\Fingerprint\Provider\MigrationFingerprintProviderInterface;
use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionCollection;
use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionEntity;

#[Package('fundamentals@after-sales')]
readonly class MigrationFingerprintService implements MigrationFingerprintServiceInterface
{
/**
* @internal
*
* @param MigrationFingerprintProviderInterface[] $providers
* @param EntityRepository<SwagMigrationConnectionCollection> $connectionRepo
*/
public function __construct(
private iterable $providers,
private EntityRepository $connectionRepo,
) {
}

/**
* @param array<string, mixed>|null $credentialFields
*/
public function generate(?array $credentialFields, SwagMigrationConnectionEntity $connection): ?string
{
if (empty($credentialFields)) {
return null;
}

foreach ($this->providers as $provider) {
if ($provider->supports($connection->getProfileName())) {
try {
return $provider->provide($credentialFields, $connection);
} catch (\Throwable) {
return null;
}
}
}

return null;
}

public function check(?string $fingerprint, Context $context, ?string $excludeConnectionId): bool
{
if (empty($fingerprint)) {
return false;
}

$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('sourceSystemFingerprint', $fingerprint));

if (isset($excludeConnectionId)) {
$criteria->addFilter(new NotFilter(MultiFilter::CONNECTION_AND, [
new EqualsFilter('id', $excludeConnectionId),
]));
}

return $this->connectionRepo->searchIds($criteria, $context)->getTotal() > 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\Migration\Connection\Fingerprint;

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionEntity;

#[Package('fundamentals@after-sales')]
interface MigrationFingerprintServiceInterface
{
/**
* @param array<string, mixed>|null $credentialFields
*/
public function generate(?array $credentialFields, SwagMigrationConnectionEntity $connection): ?string;

public function check(?string $fingerprint, Context $context, ?string $excludeConnectionId): bool;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\Migration\Connection\Fingerprint\Provider;

use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionEntity;

#[Package('fundamentals@after-sales')]
interface MigrationFingerprintProviderInterface
{
public static function supports(string $profileName): bool;

/**
* @param array<string, mixed>|null $credentialFields
*/
public function provide(?array $credentialFields, SwagMigrationConnectionEntity $connection): ?string;
}
Loading
Loading