Skip to content
Closed
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
4 changes: 3 additions & 1 deletion src/DependencyInjection/migration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@
<argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry"/>
<argument type="service" id="Symfony\Component\EventDispatcher\EventDispatcherInterface"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Logging\LoggingService"/>
<argument type="service" id="SwagMigrationAssistant\Migration\Mapping\MappingService"/>
<argument type="service" id="Doctrine\DBAL\Connection"/>

<tag name="kernel.reset" method="reset"/>
</service>
</services>
</container>
26 changes: 1 addition & 25 deletions src/Exception/MigrationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,11 @@ class MigrationException extends HttpException

final public const API_CONNECTION_ERROR = 'SWAG_MIGRATION__API_CONNECTION_ERROR';

final public const UNEXPECTED_NULL_VALUE = 'SWAG_MIGRATION__UNEXPECTED_NULL_VALUE';

final public const COULD_NOT_CONVERT_FIX = 'SWAG_MIGRATION__COULD_NOT_CONVERT_FIX';

final public const MIGRATION_NOT_IN_STEP = 'SWAG_MIGRATION__MIGRATION_NOT_IN_STEP';

final public const INVALID_ID = 'SWAG_MIGRATION__INVALID_ID';

public const DUPLICATE_SOURCE_CONNECTION = 'SWAG_MIGRATION__DUPLICATE_SOURCE_CONNECTION';
final public const DUPLICATE_SOURCE_CONNECTION = 'SWAG_MIGRATION__DUPLICATE_SOURCE_CONNECTION';

public static function associationEntityRequiredMissing(string $entity, string $missingEntity): self
{
Expand Down Expand Up @@ -452,16 +448,6 @@ public static function invalidWriteContext(Context $invalidContext): self
);
}

public static function unexpectedNullValue(string $fieldName): self
{
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::UNEXPECTED_NULL_VALUE,
'Unexpected null value for field "{{ fieldName }}".',
['fieldName' => $fieldName]
);
}

public static function couldNotConvertFix(string $missingKey): self
{
return new self(
Expand All @@ -482,16 +468,6 @@ public static function migrationNotInStep(string $runUuid, string $step): self
);
}

public static function invalidId(string $entityId, string $entityName): self
{
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::INVALID_ID,
'The id "{{ entityId }}" for entity "{{ entityName }}" is not a valid Uuid',
['entityId' => $entityId, 'entityName' => $entityName]
);
}

public static function duplicateSourceConnection(): self
{
return new self(
Expand Down
18 changes: 0 additions & 18 deletions src/Migration/Mapping/MappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
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\DataAbstractionLayer\Write\EntityWriterInterface;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Uuid\Uuid;
Expand Down Expand Up @@ -214,22 +212,6 @@ public function getMappings(string $connectionId, string $entityName, array $ids
return $this->migrationMappingRepo->search($criteria, $context);
}

public function hasValidMappingByEntityId(string $connectionId, string $entityName, string $entityId, Context $context): bool
{
$criteria = new Criteria();
$criteria->addFilter(
new EqualsFilter('connectionId', $connectionId),
new EqualsFilter('entity', $entityName),
new EqualsFilter('entityId', $entityId),
new NotFilter(MultiFilter::CONNECTION_AND, [
new EqualsFilter('oldIdentifier', null),
]),
);
$criteria->setLimit(1);

return $this->migrationMappingRepo->searchIds($criteria, $context)->getTotal() > 0;
}

public function preloadMappings(array $mappingIds, Context $context): void
{
if (empty($mappingIds)) {
Expand Down
2 changes: 0 additions & 2 deletions src/Migration/Mapping/MappingServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,5 @@ public function writeMapping(): void;
*/
public function getMappings(string $connectionId, string $entityName, array $ids, Context $context): EntitySearchResult;

public function hasValidMappingByEntityId(string $connectionId, string $entityName, string $entityId, Context $context): bool;

public function preloadMappings(array $mappingIds, Context $context): void;
}
1 change: 1 addition & 0 deletions src/Migration/Service/MediaFileProcessorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private function getMediaFiles(MigrationContextInterface $migrationContext): arr
->from('swag_migration_media_file')
->where('run_id = :runId')
->andWhere('written = 1')
->andWhere('processed = 0')
->orderBy('entity, file_size')
->setFirstResult($migrationContext->getOffset())
->setMaxResults($migrationContext->getLimit())
Expand Down
5 changes: 3 additions & 2 deletions src/Migration/Service/MigrationDataWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function writeData(MigrationContextInterface $migrationContext, Context $
$criteria->addFilter(new EqualsFilter('entity', $dataSet::getEntity()));
$criteria->addFilter(new EqualsFilter('runId', $migrationContext->getRunUuid()));
$criteria->addFilter(new EqualsFilter('convertFailure', false));
$criteria->addFilter(new EqualsFilter('written', false));
$criteria->setOffset($migrationContext->getOffset());
$criteria->setLimit($migrationContext->getLimit());
$criteria->addSorting(new FieldSorting('autoIncrement', FieldSorting::ASCENDING));
Expand Down Expand Up @@ -133,7 +134,7 @@ public function writeData(MigrationContextInterface $migrationContext, Context $
}
unset($data);

return $migrationData->getTotal();
return $migrationData->count();
} catch (WriteException $exception) {
$this->handleWriteException(
$exception,
Expand Down Expand Up @@ -165,7 +166,7 @@ public function writeData(MigrationContextInterface $migrationContext, Context $
$context
);

return $migrationData->getTotal();
return $migrationData->count();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\Migration\Validation\Exception;

use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Migration\MigrationException;
use Symfony\Component\HttpFoundation\Response;

/**
* @codeCoverageIgnore
*/
#[Package('fundamentals@after-sales')]
class MigrationValidationException extends MigrationException
{
final public const VALIDATION_UNEXPECTED_NULL_VALUE = 'SWAG_MIGRATION_VALIDATION__UNEXPECTED_NULL_VALUE';

final public const VALIDATION_INVALID_ID = 'SWAG_MIGRATION_VALIDATION__INVALID_ID';

final public const VALIDATION_INVALID_REQUIRED_FIELD_VALUE = 'SWAG_MIGRATION_VALIDATION__INVALID_REQUIRED_FIELD_VALUE';

final public const VALIDATION_INVALID_OPTIONAL_FIELD_VALUE = 'SWAG_MIGRATION_VALIDATION__INVALID_OPTIONAL_FIELD_VALUE';

final public const VALIDATION_INVALID_TRANSLATION = 'SWAG_MIGRATION_VALIDATION__INVALID_TRANSLATION';

final public const VALIDATION_INVALID_ASSOCIATION = 'SWAG_MIGRATION_VALIDATION__INVALID_ASSOCIATION';

public static function unexpectedNullValue(string $fieldName): self
{
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::VALIDATION_UNEXPECTED_NULL_VALUE,
'Unexpected null value for field "{{ fieldName }}".',
['fieldName' => $fieldName]
);
}

public static function invalidId(string $entityId, string $entityName): self
{
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::VALIDATION_INVALID_ID,
'The id "{{ entityId }}" for entity "{{ entityName }}" is not a valid Uuid',
['entityId' => $entityId, 'entityName' => $entityName]
);
}

public static function invalidRequiredFieldValue(string $entityName, string $fieldName, string $message): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::VALIDATION_INVALID_REQUIRED_FIELD_VALUE,
'Invalid value for required field "{{ fieldName }}" in entity "{{ entityName }}": {{ message }}',
['fieldName' => $fieldName, 'entityName' => $entityName, 'message' => $message]
);
}

public static function invalidOptionalFieldValue(string $entityName, string $fieldName, string $message): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::VALIDATION_INVALID_OPTIONAL_FIELD_VALUE,
'Invalid value for optional field "{{ fieldName }}" in entity "{{ entityName }}": {{ message }}',
['fieldName' => $fieldName, 'entityName' => $entityName, 'message' => $message]
);
}

public static function invalidTranslation(string $entityName, string $fieldName, string $message): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::VALIDATION_INVALID_TRANSLATION,
'Invalid translation for field "{{ fieldName }}" in entity "{{ entityName }}": {{ message }}',
['fieldName' => $fieldName, 'entityName' => $entityName, 'message' => $message]
);
}

public static function invalidAssociation(string $entityName, string $fieldName, string $message): self
{
return new self(
Response::HTTP_BAD_REQUEST,
self::VALIDATION_INVALID_ASSOCIATION,
'Invalid association "{{ fieldName }}" in entity "{{ entityName }}": {{ message }}',
['fieldName' => $fieldName, 'entityName' => $entityName, 'message' => $message]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SwagMigrationAssistant\Migration\Logging\Log\Builder\AbstractMigrationLogEntry;

#[Package('fundamentals@after-sales')]
readonly class MigrationValidationInvalidFieldValueLog extends AbstractMigrationLogEntry
readonly class MigrationValidationInvalidAssociationLog extends AbstractMigrationLogEntry
{
public function isUserFixable(): bool
{
Expand All @@ -25,6 +25,6 @@ public function getLevel(): string

public function getCode(): string
{
return 'SWAG_MIGRATION_VALIDATION_INVALID_FIELD_VALUE';
return 'SWAG_MIGRATION_VALIDATION_INVALID_ASSOCIATION';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SwagMigrationAssistant\Migration\Logging\Log\Builder\AbstractMigrationLogEntry;

#[Package('fundamentals@after-sales')]
readonly class MigrationValidationInvalidForeignKeyLog extends AbstractMigrationLogEntry
readonly class MigrationValidationInvalidOptionalFieldValueLog extends AbstractMigrationLogEntry
{
public function isUserFixable(): bool
{
Expand All @@ -25,6 +25,6 @@ public function getLevel(): string

public function getCode(): string
{
return 'SWAG_MIGRATION_VALIDATION_INVALID_FOREIGN_KEY';
return 'SWAG_MIGRATION_VALIDATION_INVALID_OPTIONAL_FIELD_VALUE';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SwagMigrationAssistant\Migration\Logging\Log\Builder\AbstractMigrationLogEntry;

#[Package('fundamentals@after-sales')]
readonly class MigrationValidationUnexpectedFieldLog extends AbstractMigrationLogEntry
readonly class MigrationValidationInvalidRequiredFieldValueLog extends AbstractMigrationLogEntry
{
public function isUserFixable(): bool
{
Expand All @@ -20,11 +20,11 @@ public function isUserFixable(): bool

public function getLevel(): string
{
return self::LOG_LEVEL_WARNING;
return self::LOG_LEVEL_ERROR;
}

public function getCode(): string
{
return 'SWAG_MIGRATION_VALIDATION_UNEXPECTED_FIELD';
return 'SWAG_MIGRATION_VALIDATION_INVALID_REQUIRED_FIELD_VALUE';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationAssistant\Migration\Validation\Log;

use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Migration\Logging\Log\Builder\AbstractMigrationLogEntry;

#[Package('fundamentals@after-sales')]
readonly class MigrationValidationInvalidRequiredTranslation extends AbstractMigrationLogEntry
{
public function isUserFixable(): bool
{
return false;
}

public function getLevel(): string
{
return self::LOG_LEVEL_ERROR;
}

public function getCode(): string
{
return 'SWAG_MIGRATION_VALIDATION_INVALID_REQUIRED_TRANSLATION';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
public function isUserFixable(): bool
{
return false;
return true;
}

public function getLevel(): string
Expand Down
Loading
Loading