Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 0 additions & 10 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ parameters:
paths:
- tests/**/*Test.php

- # TODO remove with #11883
message: '#Strict comparison using === between SwagMigrationAssistant\\Migration\\Connection\\SwagMigrationConnectionEntity and null will always evaluate to false\.#'
paths:
- **/*.php

- # TODO remove with #11883
message: '#Strict comparison using !== between SwagMigrationAssistant\\Migration\\Connection\\SwagMigrationConnectionEntity and null will always evaluate to true\.#'
paths:
- **/*.php

rules:
# Shopware core rules
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\Deprecation\DeprecatedMethodsThrowDeprecationRule
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function getProfileInformation(Request $request): Response
return new Response();
}

$migrationContext = $this->migrationContextFactory->createByProfileName($profileName);
$gateways = $this->gatewayRegistry->getGateways($migrationContext);
$profile = $this->profileRegistry->getProfile($profileName);
$gateways = $this->gatewayRegistry->getGateways($profile);

$currentGateway = null;
foreach ($gateways as $gateway) {
Expand Down Expand Up @@ -151,8 +151,8 @@ public function getGateways(Request $request): JsonResponse
throw RoutingException::missingRequestParameter('profileName');
}

$migrationContext = $this->migrationContextFactory->createByProfileName($profileName);
$gateways = $this->gatewayRegistry->getGateways($migrationContext);
$profile = $this->profileRegistry->getProfile($profileName);
$gateways = $this->gatewayRegistry->getGateways($profile);

$gatewayNames = [];
foreach ($gateways as $gateway) {
Expand Down
3 changes: 2 additions & 1 deletion src/Migration/Converter/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ protected function updateMainMapping(MigrationContextInterface $migrationContext

$dataSet = $migrationContext->getDataSet();
$connection = $migrationContext->getConnection();
if ($dataSet === null || $connection === null) {

if ($dataSet === null) {
return;
}

Expand Down
7 changes: 1 addition & 6 deletions src/Migration/Converter/ConverterRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public function getConverter(MigrationContextInterface $migrationContext): Conve
}
}

$connection = $migrationContext->getConnection();
if ($connection === null) {
throw MigrationException::migrationContextPropertyMissing('Connection');
}

throw MigrationException::converterNotFound($connection->getProfileName());
throw MigrationException::converterNotFound($migrationContext->getProfile()->getName());
}
}
3 changes: 2 additions & 1 deletion src/Migration/Gateway/GatewayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\EnvironmentInformation;
use SwagMigrationAssistant\Migration\MigrationContextInterface;
use SwagMigrationAssistant\Migration\Profile\ProfileInterface;
use SwagMigrationAssistant\Migration\TotalStruct;

#[Package('fundamentals@after-sales')]
Expand All @@ -23,7 +24,7 @@ public function getSnippetName(): string;
/**
* Identifier for a gateway registry
*/
public function supports(MigrationContextInterface $migrationContext): bool;
public function supports(ProfileInterface $profile): bool;

/**
* Reads the given entity type from via context from its connection and returns the data
Expand Down
11 changes: 4 additions & 7 deletions src/Migration/Gateway/GatewayRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Exception\MigrationException;
use SwagMigrationAssistant\Migration\MigrationContextInterface;
use SwagMigrationAssistant\Migration\Profile\ProfileInterface;

#[Package('fundamentals@after-sales')]
class GatewayRegistry implements GatewayRegistryInterface
Expand All @@ -24,11 +25,11 @@ public function __construct(private readonly iterable $gateways)
/**
* @return GatewayInterface[]
*/
public function getGateways(MigrationContextInterface $migrationContext): array
public function getGateways(ProfileInterface $profile): array
{
$gateways = [];
foreach ($this->gateways as $gateway) {
if ($gateway->supports($migrationContext)) {
if ($gateway->supports($profile)) {
$gateways[] = $gateway;
}
}
Expand All @@ -39,15 +40,11 @@ public function getGateways(MigrationContextInterface $migrationContext): array
public function getGateway(MigrationContextInterface $migrationContext): GatewayInterface
{
$connection = $migrationContext->getConnection();
if ($connection === null) {
throw MigrationException::migrationContextPropertyMissing('Connection');
}

$profileName = $connection->getProfileName();
$gatewayName = $connection->getGatewayName();

foreach ($this->gateways as $gateway) {
if ($gateway->supports($migrationContext) && $gateway->getName() === $gatewayName) {
if ($gateway->supports($migrationContext->getProfile()) && $gateway->getName() === $gatewayName) {
return $gateway;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Migration/Gateway/GatewayRegistryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\MigrationContextInterface;
use SwagMigrationAssistant\Migration\Profile\ProfileInterface;

#[Package('fundamentals@after-sales')]
interface GatewayRegistryInterface
{
/**
* @return GatewayInterface[]
*/
public function getGateways(MigrationContextInterface $migrationContext): array;
public function getGateways(ProfileInterface $profile): array;

/**
* Selects the correct gateway by the given migration context
Expand Down
9 changes: 4 additions & 5 deletions src/Migration/Media/MediaFileProcessorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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

#[Package('fundamentals@after-sales')]
Expand All @@ -34,10 +33,10 @@ public function getProcessor(MigrationContextInterface $migrationContext): Media
}

$connection = $migrationContext->getConnection();
if ($connection === null) {
throw MigrationException::entityNotExists(SwagMigrationConnectionEntity::class, $migrationContext->getRunUuid());
}

throw MigrationException::processorNotFound($connection->getProfileName(), $connection->getGatewayName());
throw MigrationException::processorNotFound(
$connection->getProfileName(),
$connection->getGatewayName()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Exception\MigrationException;
use SwagMigrationAssistant\Migration\Data\SwagMigrationDataCollection;
use SwagMigrationAssistant\Migration\Media\SwagMigrationMediaFileCollection;
use SwagMigrationAssistant\Migration\MessageQueue\Message\MigrationProcessMessage;
Expand Down Expand Up @@ -59,10 +58,6 @@ public function process(
MigrationProgress $progress,
): void {
$connection = $migrationContext->getConnection();
if ($connection === null) {
throw MigrationException::noConnectionFound();
}

$this->runService->cleanupMappingChecksums($connection->getId(), $context);

$this->runTransitionService->forceTransitionToRunStep($migrationContext->getRunUuid(), MigrationStep::CLEANUP);
Expand Down
74 changes: 41 additions & 33 deletions src/Migration/MigrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Struct\Struct;
use SwagMigrationAssistant\Exception\MigrationException;
use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionEntity;
use SwagMigrationAssistant\Migration\DataSelection\DataSet\DataSet;
use SwagMigrationAssistant\Migration\Gateway\GatewayInterface;
Expand All @@ -19,48 +20,55 @@ class MigrationContext extends Struct implements MigrationContextInterface
{
final public const SOURCE_CONTEXT = 'MIGRATION_CONNECTION_CHECK_FOR_RUNNING_MIGRATION';

private ProfileInterface $profile;

private ?SwagMigrationConnectionEntity $connection;

private string $runUuid;
public function __construct(
private SwagMigrationConnectionEntity $connection,
private ?ProfileInterface $profile = null,
private ?GatewayInterface $gateway = null,
private ?DataSet $dataSet = null,
private readonly string $runUuid = '',
private int $offset = 0,
private int $limit = 0,
) {
}

private ?DataSet $dataSet;
public function getProfile(): ProfileInterface
{
if ($this->profile === null) {
throw MigrationException::migrationContextPropertyMissing('profile');
}

private int $offset;
return $this->profile;
}

private int $limit;
public function setProfile(ProfileInterface $profile): void
{
$this->profile = $profile;
}

private GatewayInterface $gateway;
public function getGateway(): GatewayInterface
{
if ($this->gateway === null) {
throw MigrationException::migrationContextPropertyMissing('gateway');
}

public function __construct(
ProfileInterface $profile,
?SwagMigrationConnectionEntity $connection = null,
string $runUuid = '',
?DataSet $dataSet = null,
int $offset = 0,
int $limit = 0,
) {
$this->profile = $profile;
$this->connection = $connection;
$this->runUuid = $runUuid;
$this->dataSet = $dataSet;
$this->offset = $offset;
$this->limit = $limit;
return $this->gateway;
}

public function getProfile(): ProfileInterface
public function setGateway(GatewayInterface $gateway): void
{
return $this->profile;
$this->gateway = $gateway;
}

public function getConnection(): SwagMigrationConnectionEntity
{
\assert($this->connection instanceof SwagMigrationConnectionEntity);

return $this->connection;
}

public function setConnection(SwagMigrationConnectionEntity $connection): void
{
$this->connection = $connection;
}

public function getRunUuid(): string
{
return $this->runUuid;
Expand All @@ -81,18 +89,18 @@ public function getOffset(): int
return $this->offset;
}

public function getLimit(): int
public function setOffset(int $offset): void
{
return $this->limit;
$this->offset = $offset;
}

public function getGateway(): GatewayInterface
public function getLimit(): int
{
return $this->gateway;
return $this->limit;
}

public function setGateway(GatewayInterface $gateway): void
public function setLimit(int $limit): void
{
$this->gateway = $gateway;
$this->limit = $limit;
}
}
Loading