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
14 changes: 0 additions & 14 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ parameters:
paths:
- tests/**/*Test.php

- # Ignore hash functions rule for the following files because we use it in another context
message: '#Do not use .* function, use class Shopware\\Core\\Framework\\Util\\Hasher instead#'
paths:
- src/Migration/Media/Processor/HttpDownloadServiceBase.php
- src/Migration/Service/MigrationDataConverter.php
- src/Profile/Shopware/Converter/OrderConverter.php
- src/Profile/Shopware/Converter/ProductConverter.php
- src/Profile/Shopware/Converter/ProductOptionRelationConverter.php
- src/Profile/Shopware/Converter/ProductPropertyRelationConverter.php
- src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php
- src/Profile/Shopware/Converter/ShippingMethodConverter.php
- src/Profile/Shopware/Media/Strategy/Md5StrategyResolver.php
- src/Migration/Converter/Converter.php

- # To fix those issues, the AbstractProvider needs a generic type, which could then be used further down in the methods as typehints for other generic typed parameters
message: '#(readTotalFromRepo|readTableFromRepo|cleanupSearchResult)\(\) has parameter .* with generic class#'
path: src/DataProvider/Provider/Data/AbstractProvider.php
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 @@ -9,6 +9,7 @@

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface;
use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface;
use SwagMigrationAssistant\Migration\MigrationContextInterface;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function getMediaUuids(array $converted): ?array
*/
protected function generateChecksum(array $data): void
{
$this->checksum = \md5(\serialize($data));
$this->checksum = Hasher::hash(\serialize($data));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Migration/Media/Processor/HttpDownloadServiceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use Shopware\Core\Framework\Uuid\Uuid;
use SwagMigrationAssistant\Exception\MigrationException;
use SwagMigrationAssistant\Migration\Gateway\HttpClientInterface;
Expand Down Expand Up @@ -321,13 +322,13 @@ private function persistFileToMedia(string $filePath, string $uuid, string $name
return;
}

$fileHash = \hash_file('md5', $filePath);
$fileHash = Hasher::hashFile($filePath);
$mediaFile = new MediaFile(
$filePath,
$mimeType,
$fileExtension,
$fileSize,
$fileHash === false ? null : $fileHash
$fileHash
);
$name = \preg_replace('/[^a-zA-Z0-9_-]+/', '-', \mb_strtolower($name)) ?? $uuid;

Expand Down
3 changes: 2 additions & 1 deletion src/Migration/Service/MigrationDataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriterInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteContext;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use SwagMigrationAssistant\Migration\Converter\ConverterInterface;
use SwagMigrationAssistant\Migration\Converter\ConverterRegistryInterface;
use SwagMigrationAssistant\Migration\DataSelection\DataSet\DataSet;
Expand Down Expand Up @@ -153,7 +154,7 @@ private function filterDeltas(array $data, ConverterInterface $converter, Migrat

foreach ($data as $dataSet) {
$mappedData[$converter->getSourceIdentifier($dataSet)] = $dataSet;
$checksums[$converter->getSourceIdentifier($dataSet)] = \md5(\serialize($dataSet));
$checksums[$converter->getSourceIdentifier($dataSet)] = Hasher::hash(\serialize($dataSet));
}

$dataSet = $migrationContext->getDataSet();
Expand Down
3 changes: 2 additions & 1 deletion src/Profile/Shopware/Converter/OrderConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use Shopware\Core\System\SalesChannel\SalesChannelCollection;
use SwagMigrationAssistant\Exception\AssociationEntityRequiredMissingException;
use SwagMigrationAssistant\Exception\MigrationException;
Expand Down Expand Up @@ -386,7 +387,7 @@ public function convert(
}
unset($data['locale']);

$converted['deepLinkCode'] = \md5($converted['id']);
$converted['deepLinkCode'] = Hasher::hash($converted['id']);

// Legacy data which don't need a mapping or there is no equivalent field
unset(
Expand Down
9 changes: 5 additions & 4 deletions src/Profile/Shopware/Converter/ProductConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Rule\Container\AndRule;
use Shopware\Core\Framework\Rule\Container\OrRule;
use Shopware\Core\Framework\Util\Hasher;
use Shopware\Core\Framework\Uuid\Uuid;
use SwagMigrationAssistant\Exception\MigrationException;
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
Expand Down Expand Up @@ -672,14 +673,14 @@ private function applyOptions(array &$converted, array &$data): void
$optionMapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP_OPTION,
\hash('md5', \mb_strtolower($option['name'] . '_' . $option['group']['name'])),
Hasher::hash(\mb_strtolower($option['name'] . '_' . $option['group']['name']), 'md5'),
$this->context
);
$this->mappingIds[] = $optionMapping['id'];
$optionGroupMapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP,
\hash('md5', \mb_strtolower($option['group']['name'])),
Hasher::hash(\mb_strtolower($option['group']['name']), 'md5'),
$this->context
);
$this->mappingIds[] = $optionGroupMapping['id'];
Expand Down Expand Up @@ -1228,7 +1229,7 @@ private function applyOptionTranslation(array &$option, array $data): void
$mapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP_OPTION_TRANSLATION,
\hash('md5', \mb_strtolower($data['name'] . '_' . $data['group']['name'])) . ':' . $this->locale,
Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name']), 'md5') . ':' . $this->locale,
$this->context
);
$localeOptionTranslation['id'] = $mapping['entityId'];
Expand All @@ -1240,7 +1241,7 @@ private function applyOptionTranslation(array &$option, array $data): void
$mapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP_TRANSLATION,
\hash('md5', \mb_strtolower($data['group']['name'])) . ':' . $this->locale,
Hasher::hash(\mb_strtolower($data['group']['name']), 'md5') . ':' . $this->locale,
$this->context
);
$localeGroupTranslation['id'] = $mapping['entityId'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\MigrationContextInterface;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function convert(array $data, Context $context, MigrationContextInterface
$optionMapping = $this->mappingService->getMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP_OPTION,
\hash('md5', \mb_strtolower($data['name'] . '_' . $data['group']['name'])),
Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name']), 'md5'),
$context
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\MigrationContextInterface;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function convert(array $data, Context $context, MigrationContextInterface
$optionMapping = $this->mappingService->getMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP_OPTION,
\hash('md5', \mb_strtolower($data['name'] . '_' . $data['group']['name'])),
Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name']), 'md5'),
$context
);

Expand Down
11 changes: 6 additions & 5 deletions src/Profile/Shopware/Converter/PropertyGroupOptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Shopware\Core\Content\Property\PropertyGroupDefinition;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\Logging\Log\Builder\SwagMigrationLogBuilder;
Expand Down Expand Up @@ -49,7 +50,7 @@ public function getSourceIdentifier(array $data): string
$group = $data['group']['name'];
}

return \hash('md5', \mb_strtolower($data['name'] . '_' . $group . '_' . $data['type']));
return Hasher::hash(\mb_strtolower($data['name'] . '_' . $group . '_' . $data['type']), 'md5');
}

public function getMediaUuids(array $converted): ?array
Expand Down Expand Up @@ -92,15 +93,15 @@ public function convert(array $data, Context $context, MigrationContextInterface
$mapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP_OPTION,
\hash('md5', \mb_strtolower($data['name'] . '_' . $data['group']['name'])),
Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name']), 'md5'),
$context
);
$this->mappingIds[] = $mapping['id'];

$propertyGroupMapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP,
\hash('md5', \mb_strtolower($data['group']['name'])),
Hasher::hash(\mb_strtolower($data['group']['name']), 'md5'),
$context
);
$this->mappingIds[] = $propertyGroupMapping['id'];
Expand Down Expand Up @@ -257,15 +258,15 @@ protected function createAndDeleteNecessaryMappings(array $data, array $converte
$this->mainMapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP_OPTION,
\hash('md5', \mb_strtolower($data['name'] . '_' . $data['group']['name'] . '_' . $data['type'])),
Hasher::hash(\mb_strtolower($data['name'] . '_' . $data['group']['name'] . '_' . $data['type']), 'md5'),
$this->context,
$this->checksum
);

$mapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
DefaultEntities::PROPERTY_GROUP_OPTION,
\hash('md5', \mb_strtolower($data['group']['name'] . '_' . $data['type'])),
Hasher::hash(\mb_strtolower($data['group']['name'] . '_' . $data['type']), 'md5'),
$this->context
);
$this->mappingIds[] = $mapping['id'];
Expand Down
3 changes: 2 additions & 1 deletion src/Profile/Shopware/Converter/ShippingMethodConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Rule\Container\AndRule;
use Shopware\Core\Framework\Rule\Container\OrRule;
use Shopware\Core\Framework\Util\Hasher;
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\Logging\Log\Builder\SwagMigrationLogBuilder;
Expand Down Expand Up @@ -748,7 +749,7 @@ private function setCustomAvailabilityRule(array $data, array &$converted): void
$ruleData = $this->getRelevantDataForAvailabilityRule($data);

$jsonRuleData = \json_encode($ruleData, \JSON_THROW_ON_ERROR);
$hash = \md5($jsonRuleData);
$hash = Hasher::hash($jsonRuleData, 'md5');

$mainRuleMapping = $this->mappingService->getOrCreateMapping(
$this->connectionId,
Expand Down
3 changes: 2 additions & 1 deletion src/Profile/Shopware/Media/Strategy/Md5StrategyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace SwagMigrationAssistant\Profile\Shopware\Media\Strategy;

use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use SwagMigrationAssistant\Migration\MigrationContextInterface;

#[Package('fundamentals@after-sales')]
Expand Down Expand Up @@ -40,7 +41,7 @@ public function resolve(string $path, MigrationContextInterface $migrationContex
$path = \ltrim($path, '/');
$pathElements = \explode('/', $path);
$pathInfo = \pathinfo($path);
$md5hash = \md5($path);
$md5hash = Hasher::hash($path, 'md5');

if (empty($pathInfo['extension'])) {
return '';
Expand Down
13 changes: 7 additions & 6 deletions tests/Migration/Mapping/MappingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriter;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour;
use Shopware\Core\Framework\Util\Hasher;
use Shopware\Core\Framework\Uuid\Uuid;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\Mapping\MappingService;
Expand Down Expand Up @@ -244,7 +245,7 @@ public function testWriteMapping(array $dataset): void
$set['entity'],
$set['oldIdentifier'],
Context::createDefaultContext(),
\md5($set['entity'] . $set['oldIdentifier']),
Hasher::hash($set['entity'] . $set['oldIdentifier']),
null,
Uuid::randomHex(),
$set['value']
Expand All @@ -265,7 +266,7 @@ public function testWriteMapping(array $dataset): void
if ($set['oldIdentifier'] === $resultEntry['old_identifier']) {
static::assertSame($set['entity'], $resultEntry['entity']);
static::assertSame($set['value'], $resultEntry['entity_value']);
static::assertSame(\md5($set['entity'] . $set['oldIdentifier']), $resultEntry['checksum']);
static::assertSame(Hasher::hash($set['entity'] . $set['oldIdentifier']), $resultEntry['checksum']);
}
}
}
Expand All @@ -289,7 +290,7 @@ public function testWriteMapping(array $dataset): void
if ($set['oldIdentifier'] === $resultEntry['old_identifier']) {
static::assertSame($set['entity'], $resultEntry['entity']);
static::assertSame('EV_newValue', $resultEntry['entity_value']);
static::assertSame(\md5($set['entity'] . $set['oldIdentifier']), $resultEntry['checksum']);
static::assertSame(Hasher::hash($set['entity'] . $set['oldIdentifier']), $resultEntry['checksum']);
}
}
}
Expand Down Expand Up @@ -345,7 +346,7 @@ public function testWritePerEntry(array $dataset): void
$set['entity'],
$set['oldIdentifier'],
Context::createDefaultContext(),
\md5($set['entity'] . $set['oldIdentifier']),
Hasher::hash($set['entity'] . $set['oldIdentifier']),
null,
Uuid::randomHex(),
$set['value']
Expand All @@ -368,7 +369,7 @@ public function testWritePerEntry(array $dataset): void
if ($set['oldIdentifier'] === $resultEntry['old_identifier']) {
static::assertSame($set['entity'], $resultEntry['entity']);
static::assertSame($set['value'], $resultEntry['entity_value']);
static::assertSame(\md5($set['entity'] . $set['oldIdentifier']), $resultEntry['checksum']);
static::assertSame(Hasher::hash($set['entity'] . $set['oldIdentifier']), $resultEntry['checksum']);
}
}
}
Expand All @@ -388,7 +389,7 @@ public function testWritePerEntry(array $dataset): void
if ($set['oldIdentifier'] === $resultEntry['old_identifier']) {
static::assertSame($set['entity'], $resultEntry['entity']);
static::assertSame('EV_newValue', $resultEntry['entity_value']);
static::assertSame(\md5($set['entity'] . $set['oldIdentifier']), $resultEntry['checksum']);
static::assertSame(Hasher::hash($set['entity'] . $set['oldIdentifier']), $resultEntry['checksum']);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions tests/Mock/Migration/Mapping/Dummy6MappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Util\Hasher;
use Shopware\Core\Framework\Uuid\Uuid;
use SwagMigrationAssistant\Migration\Mapping\MappingService;
use SwagMigrationAssistant\Migration\Mapping\SwagMigrationMappingCollection;
Expand Down Expand Up @@ -49,17 +50,17 @@ public function getUuidsByEntity(string $connectionId, string $entityName, Conte

public function getValue(string $connectionId, string $entityName, string $oldIdentifier, Context $context): ?string
{
if (!isset($this->mappings[\md5($entityName . $oldIdentifier)])) {
if (!isset($this->mappings[Hasher::hash($entityName . $oldIdentifier)])) {
return null;
}

return $this->mappings[\md5($entityName . $oldIdentifier)]['entityValue'];
return $this->mappings[Hasher::hash($entityName . $oldIdentifier)]['entityValue'];
}

public function getUuidList(string $connectionId, string $entityName, string $identifier, Context $context): array
{
return isset($this->mappings[\md5($entityName . $identifier)])
? \array_column($this->mappings[\md5($entityName . $identifier)], 'entityId')
return isset($this->mappings[Hasher::hash($entityName . $identifier)])
? \array_column($this->mappings[Hasher::hash($entityName . $identifier)], 'entityId')
: [];
}

Expand Down
Loading
Loading