Skip to content
Merged
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
19 changes: 19 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ jobs:
with:
extension_name: ${{ github.event.repository.name }}
platform_branch: trunk

extension_verifier:
name: Extension Verifier (lowest)
runs-on: ubuntu-latest
steps:
- name: Checkout SwagMigrationMagento
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Remove PHPStan config
run: rm phpstan.neon.dist

- name: Allow composer to resolve advisory-affected releases
run: composer config policy.advisories.block false

- name: Run verifier
uses: shopware/github-actions/extension-verifier@main
with:
action: check
check-against: lowest
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [NEXT]
- Fixes errors when downloading media.
- Fixes errors when migrating category images.
- Fixed a fatal error that broke reading data via the local gateway on Shopware versions below 6.7.8.0.

# 13.0.0

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [NEXT]
- Behebt Fehler beim Herunterladen von Medien.
- Behebt Fehler bei der Migration von Kategoriebildern.
- Ein fataler Fehler wurde behoben, der das Lesen von Daten über das lokale Gateway auf Shopware-Versionen unter 6.7.8.0 verhindert hat.

# 13.0.0

Expand Down
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ parameters:
count: 1
path: src/Profile/Magento/Converter/MagentoConverter.php

-
message: "#^Offset 'translations' on array\\{id\\: mixed, translations\\: array\\} in isset\\(\\) always exists and is not nullable\\.$#"
count: 1
path: src/Profile/Magento/Converter/ManufacturerConverter.php

-
message: "#^Method Swag\\\\MigrationMagento\\\\Profile\\\\Magento\\\\Converter\\\\NewsletterRecipientConverter\\:\\:getSalesChannelMapping\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1245,11 +1240,6 @@ parameters:
count: 1
path: src/Profile/Magento/Gateway/Local/Reader/SalesChannelReader.php

-
message: "#^Offset 'allowedCountries' on array\\{defaultCountry\\: mixed\\} in isset\\(\\) does not exist\\.$#"
count: 1
path: src/Profile/Magento/Gateway/Local/Reader/SalesChannelReader.php

-
message: "#^Method Swag\\\\MigrationMagento\\\\Profile\\\\Magento\\\\Gateway\\\\Local\\\\Reader\\\\SeoUrlReader\\:\\:fetchSeoUrls\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1295,11 +1285,6 @@ parameters:
count: 1
path: src/Profile/Magento/Gateway/TableReaderInterface.php

-
message: "#^Call to an undefined method Swag\\\\MigrationMagento\\\\Profile\\\\Magento\\\\Gateway\\\\MagentoGatewayInterface\\:\\:readStores\\(\\)\\.$#"
count: 1
path: src/Profile/Magento/Premapping/AdminStoreReader.php

-
message: "#^Property Swag\\\\MigrationMagento\\\\Profile\\\\Magento\\\\Premapping\\\\PaymentMethodReader\\:\\:\\$preselectionDictionary type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1580,11 +1565,6 @@ parameters:
count: 1
path: src/Profile/Magento2/Gateway/Local/Reader/Magento2SalesChannelReader.php

-
message: "#^Dead catch \\- Error is never thrown in the try block\\.$#"
count: 1
path: src/Profile/Magento2/Gateway/Local/Reader/Magento2SeoUrlReader.php

-
message: "#^Method Swag\\\\MigrationMagento\\\\Profile\\\\Magento2\\\\Gateway\\\\Local\\\\Reader\\\\Magento2SeoUrlReader\\:\\:fetchSeoUrls\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
16 changes: 14 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,20 @@ parameters:
# TODO: XML config format will be migrated step by step, so we ignore errors for now, see https://github.com/shopware/shopware/issues/13072
- message: '#deprecated class Symfony\\Component\\DependencyInjection\\Loader\\XmlFileLoader#'

# TODO: MagentoMappingServiceInterface extends MappingServiceInterface with additional methods, but parent Converter class types $mappingService as MappingServiceInterface
- message: '#Call to an undefined method SwagMigrationAssistant\\Migration\\Mapping\\MappingServiceInterface::(createListItemMapping|getUuidList)\(\)#'
# TODO remove once the minimum supported Shopware version ships DBAL 4.4 (>= 6.7.8.0)
- message: '#Call to deprecated method introspectTable\(\) of class Doctrine\\DBAL\\Schema\\AbstractSchemaManager#'
paths:
- src/Profile/Magento/Gateway/Local/Reader/AbstractReader.php
- message: '#Call to deprecated method getName\(\) of class Doctrine\\DBAL\\Schema\\AbstractAsset#'
paths:
- src/Profile/Magento/Gateway/Local/Reader/AbstractReader.php

# TODO remove once the minimum supported Shopware version ships the `BCChange` attributes
- identifier: shopware.bcPlanningDeprecation
- identifier: shopware.deprecatedMethod
paths:
- src/Profile/Magento/Media/LocalMediaProcessor.php
- message: '#Call to deprecated method doNormalDownloadRequest\(\) of class Swag\\MigrationMagento\\Profile\\Magento\\Media\\LocalMediaProcessor#'

# TODO remove this for 6.8 compatibility
- message: '#Access to constant on deprecated class Shopware\\Core\\Checkout\\Payment\\Cart\\PaymentHandler\\DebitPayment#'
Expand Down
5 changes: 0 additions & 5 deletions src/Migration/Mapping/MagentoMappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Shopware\Core\System\Tax\TaxCollection;
use SwagMigrationAssistant\Migration\Mapping\MappingService;
use SwagMigrationAssistant\Migration\Mapping\SwagMigrationMappingCollection;
use SwagMigrationAssistant\Migration\Mapping\SwagMigrationMappingEntity;

#[Package('fundamentals@after-sales')]
class MagentoMappingService extends MappingService implements MagentoMappingServiceInterface
Expand Down Expand Up @@ -98,10 +97,6 @@ public function getUuidList(string $connectionId, string $entityName, string $id
$uuidList = [];

foreach ($result as $entity) {
if (!$entity instanceof SwagMigrationMappingEntity) {
continue;
}

$entityId = $entity->getEntityId();

if ($entityId === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Profile/Magento/Converter/CustomerConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function convert(array $data, Context $context, MigrationContextInterface
$context
);

if (\is_array($mapping) && \array_key_exists('entityId', $mapping)) {
if (\is_array($mapping)) {
$converted['groupId'] = $mapping['entityId'];
unset($data['group_id']);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Profile/Magento/Converter/ManufacturerConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ public function convert(array $data, Context $context, MigrationContextInterface
$context
);

if (isset($converted['translations'])) {
foreach ($converted['translations'] as &$translation) {
$translation['manufacturerId'] = $converted['id'];
}
unset($translation);
foreach ($converted['translations'] as &$translation) {
$translation['manufacturerId'] = $converted['id'];
}
unset($translation);
}
unset($data['translations']);

Expand Down
2 changes: 1 addition & 1 deletion src/Profile/Magento/Converter/OrderConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ protected function convertOrderCustomer(array &$converted, array &$data): bool
$this->context
);

if ($mapping !== null && isset($mapping['entityId'], $mapping['id'])) {
if ($mapping !== null && isset($mapping['entityId'])) {
$this->mappingIds[] = $mapping['id'];
$this->salutationUuid = $mapping['entityId'];
}
Expand Down
1 change: 1 addition & 0 deletions src/Profile/Magento/Converter/ProductConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ private function setDefaultStoreVisibility(int $status, string $productId, array
return;
}

\assert($this->mappingService instanceof MagentoMappingServiceInterface);
$uuids = $this->mappingService->getUuidList(
$this->connectionId,
MagentoDefaultEntities::STORE_DEFAULT,
Expand Down
1 change: 1 addition & 0 deletions src/Profile/Magento/Converter/SalesChannelConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function convert(array $data, Context $context, MigrationContextInterface
$this->mappingIds[] = $mapping['id'];
}

\assert($this->mappingService instanceof MagentoMappingServiceInterface);
$this->mappingService->createListItemMapping(
$this->connectionId,
MagentoDefaultEntities::STORE_DEFAULT,
Expand Down
6 changes: 4 additions & 2 deletions src/Profile/Magento/Gateway/Local/Reader/AbstractReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ protected function addTableSelection(QueryBuilder $query, string $table, string
return;
}

$table = $this->connection->createSchemaManager()->introspectTableByUnquotedName($table);
// introspectTable() is deprecated, but introspectTableByUnquotedName() needs DBAL 4.4+ (Shopware 6.7.8.0+)
$table = $this->connection->createSchemaManager()->introspectTable($table);

foreach ($table->getColumns() as $column) {
$columnName = $column->getObjectName()->toString();
// getName() is deprecated, but getObjectName() needs DBAL 4.3+ (Shopware 6.7.0/6.7.1 can lock DBAL 4.2)
$columnName = $column->getName();

$columnName = trim($columnName, '"`');

Expand Down
2 changes: 1 addition & 1 deletion src/Profile/Magento/Gateway/Local/Reader/ProductReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ protected function appendAssociatedData(array $fetchedProducts, array $ids): arr
$media = $this->fetchProductMedia($ids);
$prices = $this->fetchProductPrices($ids);
$configuratorSettings = $this->fetchConfiguratorSettings();
unset($this->combinedProductIds);
$this->combinedProductIds = null;
$visibility = $this->fetchVisibility($ids);
$locales = $this->fetchLocales();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,7 @@ protected function fetchStoreCountryConfig(array $storeIds): array
$storeCountryConfig = [];
foreach ($configurations as $key => $storeConfig) {
foreach ($storeConfig as $config) {
if ($config['path'] === 'general/country/allow') {
if (isset($storeCountryConfig[$key]['allowedCountries'])) {
$storeCountryConfig[$key]['allowedCountries'] = \explode(',', (string) $config['value']);
}
} else {
if ($config['path'] !== 'general/country/allow') {
Comment thread
jozsefdamokos marked this conversation as resolved.
$storeCountryConfig[$key]['defaultCountry'] = $config['value'];
}
}
Expand Down
47 changes: 24 additions & 23 deletions src/Profile/Magento/Media/LocalMediaProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Shopware\Core\Content\Media\MediaException;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\Deprecation\BCChange\ReturnTypeNarrowing;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Uuid\Uuid;
use Swag\MigrationMagento\Exception\MigrationMagentoException;
Expand Down Expand Up @@ -156,7 +155,9 @@ protected function doMediaDownloadRequests(array $media, array &$mappedWorkload,
return $promises;
}

#[ReturnTypeNarrowing(version: 'v14.0.0', newType: Promise\PromiseInterface::class)]
/**
* @deprecated tag:v14.0.0 - reason:return-type-change - Will return Promise\PromiseInterface
*/
protected function doNormalDownloadRequest(MediaProcessWorkloadStruct $workload, Client $client): ?Promise\PromiseInterface
{
$additionalData = $workload->getAdditionalData();
Expand Down Expand Up @@ -241,9 +242,9 @@ private function copyMediaFiles(
$sourcePath = $this->getInstallationRoot($migrationContext) . $mappedWorkload[$mediaId]->getAdditionalData()['path'];

$fileExtension = \pathinfo($sourcePath, \PATHINFO_EXTENSION);
$filePath = \tempnam(\sys_get_temp_dir(), 'SwagMigrationMagento-');
$tempFilePath = \tempnam(\sys_get_temp_dir(), 'SwagMigrationMagento-');

if ($filePath === false) {
if ($tempFilePath === false) {
$failureUuids[] = (string) $mediaId;
$mappedWorkload[$mediaId]->setState(MediaProcessWorkloadStruct::ERROR_STATE);

Expand All @@ -265,16 +266,16 @@ private function copyMediaFiles(
continue;
}

if (\copy($sourcePath, $filePath)) {
if (\copy($sourcePath, $tempFilePath)) {
try {
$fileSize = \filesize($filePath);
$fileSize = \filesize($tempFilePath);
if ($fileSize === false) {
throw MigrationMagentoException::mediaFileSizeError($filePath);
throw MigrationMagentoException::mediaFileSizeError($tempFilePath);
}

$mappedWorkload[$mediaId]->setState(MediaProcessWorkloadStruct::FINISH_STATE);
$this->persistFileToMedia(
$filePath,
$tempFilePath,
$mediaId,
$mediaFile['file_name'],
$fileSize,
Expand All @@ -293,7 +294,7 @@ private function copyMediaFiles(
->withException($e)
->withConvertedData(
[
'file_path' => $filePath,
'file_path' => $tempFilePath,
'source_path' => $sourcePath,
'media' => $media,
]
Expand All @@ -303,7 +304,7 @@ private function copyMediaFiles(
);
}

\unlink($filePath);
\unlink($tempFilePath);
} else {
$mappedWorkload[$mediaId]->setState(MediaProcessWorkloadStruct::ERROR_STATE);

Expand All @@ -313,7 +314,7 @@ private function copyMediaFiles(
->withSourceData($mediaFile)
->withConvertedData(
[
'file_path' => $filePath,
'file_path' => $tempFilePath,
'source_path' => $sourcePath,
'media' => $media,
]
Expand All @@ -338,7 +339,7 @@ private function copyMediaFiles(
* @param list<string> $failedMedia
*/
private function persistFileToMedia(
string $filePath,
string $tempFilePath,
string $mediaId,
string $fileName,
int $fileSize,
Expand All @@ -347,7 +348,7 @@ private function persistFileToMedia(
array &$failedMedia,
Context $context,
): void {
$mimeType = \mime_content_type($filePath);
$mimeType = \mime_content_type($tempFilePath);

if ($mimeType === false) {
$failedMedia[] = $mediaId;
Expand All @@ -359,7 +360,7 @@ private function persistFileToMedia(
->withFieldName('mimeType')
->withConvertedData(
[
'file_path' => $filePath,
'file_path' => $tempFilePath,
'media_id' => $mediaId,
'file_name' => $fileName,
'file_size' => $fileSize,
Expand All @@ -373,7 +374,7 @@ private function persistFileToMedia(
return;
}

$mediaFile = new MediaFile($filePath, $mimeType, $fileExtension, $fileSize);
$mediaFile = new MediaFile($tempFilePath, $mimeType, $fileExtension, $fileSize);
$fileName = (string) \preg_replace('/[^a-z0-9_-]+/', '-', \mb_strtolower($fileName));

try {
Expand Down Expand Up @@ -473,8 +474,8 @@ static function (MediaProcessWorkloadStruct $work) use ($uuid) {
/** @var Response $response */
$response = $result['value'];
$fileExtension = \pathinfo($additionalData['uri'], \PATHINFO_EXTENSION);
$filePath = \tempnam(\sys_get_temp_dir(), 'SwagMigrationMagento-');
if ($filePath === false) {
$tempFilePath = \tempnam(\sys_get_temp_dir(), 'SwagMigrationMagento-');
if ($tempFilePath === false) {
$failureUuids[] = $uuid;
$mappedWorkload[$uuid]->setState(MediaProcessWorkloadStruct::ERROR_STATE);

Expand Down Expand Up @@ -502,7 +503,7 @@ static function (MediaProcessWorkloadStruct $work) use ($uuid) {
],
]);

$fileHandle = \fopen($filePath, 'ab', false, $streamContext);
$fileHandle = \fopen($tempFilePath, 'ab', false, $streamContext);
if ($fileHandle === false) {
$failureUuids[] = $uuid;
$mappedWorkload[$uuid]->setState(MediaProcessWorkloadStruct::ERROR_STATE);
Expand All @@ -512,7 +513,7 @@ static function (MediaProcessWorkloadStruct $work) use ($uuid) {
->withEntityName(MediaDefinition::ENTITY_NAME)
->withSourceData([
'media_id' => $uuid,
'source_path' => $filePath,
'source_path' => $tempFilePath,
'media' => $media,
])
->withEntityId($uuid)
Expand All @@ -522,13 +523,13 @@ static function (MediaProcessWorkloadStruct $work) use ($uuid) {
continue;
}
\fwrite($fileHandle, $response->getBody()->getContents());
$fileSize = (int) \filesize($filePath);
$fileSize = (int) \filesize($tempFilePath);
\fclose($fileHandle);

if ($mappedWorkload[$uuid]->getState() === MediaProcessWorkloadStruct::FINISH_STATE) {
try {
$this->persistFileToMedia(
$filePath,
$tempFilePath,
$uuid,
$additionalData['file_name'],
$fileSize,
Expand All @@ -537,7 +538,7 @@ static function (MediaProcessWorkloadStruct $work) use ($uuid) {
$failureUuids,
$context
);
\unlink($filePath);
\unlink($tempFilePath);
$finishedUuids[] = $uuid;
} catch (\Exception $e) {
$failureUuids[] = $uuid;
Expand All @@ -549,7 +550,7 @@ static function (MediaProcessWorkloadStruct $work) use ($uuid) {
->withException($e)
->withConvertedData(
[
'file_path' => $filePath,
'file_path' => $tempFilePath,
'uri' => $additionalData['uri'],
'media_id' => $uuid,
'media' => $media,
Expand Down
Loading