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
37 changes: 27 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
.idea
.vscode
coverage/
.phpunit.cache
.phpunit.result.cache
vendor
node_modules
phpstan.neon
# ide
.idea/
.vscode/

# os
.DS_Store

# node
node_modules/
*.hot-update.js
/var/

# php
vendor/
phpstan.neon
composer.lock
src/Resources/public/administration/
.phpunit.cache
.phpunit.result.cache

# tests
coverage/

# build
src/Resources/public/static/
src/Resources/public/administration/
src/Resources/app/administration/.tmp

# runtime
/var/
.env

# plugin
/migration_assistant.cache
635 changes: 420 additions & 215 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ parameters:
- src/Profile/Shopware/Premapping/PaymentMethodReader.php
- tests/Profile/Shopware/Premapping/PaymentMethodReaderTest.php

- # TODO remove this for 6.8 compatibility
message: '#Call to deprecated method __construct\(\) of class Shopware\\Core\\Framework\\DataAbstractionLayer\\EntityDefinition:#'
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
26 changes: 26 additions & 0 deletions src/Core/Migration/Migration1754896654TruncateMigrationLogs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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;

#[Package('fundamentals@after-sales')]
class Migration1754896654TruncateMigrationLogs extends MigrationStep
{
public function getCreationTimestamp(): int
{
return 1754896654;
}

public function update(Connection $connection): void
{
$connection->executeStatement('TRUNCATE TABLE `swag_migration_logging`');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?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 Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Migration\MigrationStep;

#[Package('fundamentals@after-sales')]
class Migration1754897550AddRequiredFieldsToMigrationLogs extends MigrationStep
{
public const MIGRATION_LOGGING_TABLE = 'swag_migration_logging';

public const REQUIRED_FIELDS = [
'id' => 'BINARY(16) NOT NULL',
'run_id' => null,
'level' => null,
'code' => null,
'profile_name' => 'VARCHAR(255) NOT NULL',
'gateway_name' => 'VARCHAR(255) NOT NULL',
'user_fixable' => 'TINYINT(1) NOT NULL DEFAULT 0',
'auto_increment' => null,
'created_at' => null,
'updated_at' => null,
];

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

/**
* @throws \Throwable
*/
public function update(Connection $connection): void
{
$schemaManager = $connection->createSchemaManager();

if (!$schemaManager->tablesExist([self::MIGRATION_LOGGING_TABLE])) {
return;
}

$this->dropForeignKeyIfExists($connection, self::MIGRATION_LOGGING_TABLE, 'fk.swag_migration_logging.run_id');
$this->dropIndexIfExists($connection, self::MIGRATION_LOGGING_TABLE, 'idx.swag_migration_logging.run_id_code');
$this->dropConstraintIfExists($connection, 'json.swag_migration_logging.log_entry');

$this->dropObsoleteColumns($connection, $schemaManager);
$this->addOrModifyRequiredColumns($connection, $schemaManager);
$this->ensureRelations($connection, $schemaManager);
}

/**
* @param AbstractSchemaManager<MySQLPlatform> $schemaManager
*/
private function dropObsoleteColumns(Connection $connection, AbstractSchemaManager $schemaManager): void
{
$columns = $schemaManager->listTableColumns(self::MIGRATION_LOGGING_TABLE);

foreach ($columns as $column) {
if (!\array_key_exists($column->getName(), self::REQUIRED_FIELDS)) {
$connection->executeStatement(
\sprintf(
'ALTER TABLE `%s` DROP COLUMN `%s`;',
self::MIGRATION_LOGGING_TABLE,
$column->getName()
)
);
}
}
}

/**
* @param AbstractSchemaManager<MySQLPlatform> $schemaManager
*/
private function addOrModifyRequiredColumns(Connection $connection, AbstractSchemaManager $schemaManager): void
{
$columns = $schemaManager->listTableColumns(self::MIGRATION_LOGGING_TABLE);

foreach (self::REQUIRED_FIELDS as $name => $type) {
if ($type === null) {
continue;
}

if (!isset($columns[$name])) {
$connection->executeStatement(
\sprintf(
'ALTER TABLE `%s` ADD COLUMN `%s` %s;',
self::MIGRATION_LOGGING_TABLE,
$name,
$type
)
);
} else {
$connection->executeStatement(
\sprintf(
'ALTER TABLE `%s` MODIFY COLUMN `%s` %s;',
self::MIGRATION_LOGGING_TABLE,
$name,
$type
)
);
}
}
}

/**
* @param AbstractSchemaManager<MySQLPlatform> $schemaManager
*/
private function ensureRelations(Connection $connection, AbstractSchemaManager $schemaManager): void
{
// ensure primary key and index
$indexes = $schemaManager->listTableIndexes(self::MIGRATION_LOGGING_TABLE);

if (isset($indexes['primary'])) {
$connection->executeStatement(
\sprintf(
'ALTER TABLE `%s` DROP PRIMARY KEY;',
self::MIGRATION_LOGGING_TABLE
)
);
}

$connection->executeStatement(
\sprintf(
'ALTER TABLE `%s` ADD PRIMARY KEY (`id`);',
self::MIGRATION_LOGGING_TABLE
)
);

$this->dropIndexIfExists(
$connection,
self::MIGRATION_LOGGING_TABLE,
'idx.run_id'
);
$connection->executeStatement(
\sprintf(
'ALTER TABLE `%s` ADD INDEX `idx.run_id` (`run_id`);',
self::MIGRATION_LOGGING_TABLE
)
);

// ensure foreign key constraint
$connection->executeStatement(
\sprintf(
'ALTER TABLE `%s` ADD CONSTRAINT `fk.swag_migration_logging.run_id` FOREIGN KEY (`run_id`) REFERENCES `swag_migration_run` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE;',
self::MIGRATION_LOGGING_TABLE
)
);
}

private function dropConstraintIfExists(Connection $connection, string $constraintName): void
{
try {
$connection->executeStatement(
\sprintf(
'ALTER TABLE `%s` DROP CONSTRAINT `%s`;',
self::MIGRATION_LOGGING_TABLE,
$constraintName
)
);
} catch (Exception) {
}
}
}
44 changes: 13 additions & 31 deletions src/Migration/History/HistoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,8 @@ public function getGroupedLogsOfRun(
null,
null,
new TermsAggregation(
'titleSnippet',
'titleSnippet',
null,
null,
new TermsAggregation(
'entity',
'entity',
null,
null,
new TermsAggregation(
'level',
'level'
)
)
'level',
'level'
)
)
);
Expand Down Expand Up @@ -114,8 +102,8 @@ public function downloadLogsOfRun(string $runUuid, Context $context): \Closure

foreach ($logChunk->getElements() as $logEntry) {
\printf('[%s] %s%s', $logEntry->getLevel(), $logEntry->getCode(), \PHP_EOL);
\printf('%s%s', $logEntry->getTitle(), \PHP_EOL);
\printf('%s%s%s', $logEntry->getDescription(), \PHP_EOL, \PHP_EOL);
\printf('%s%s', $logEntry->getProfileName(), \PHP_EOL);
\printf('%s%s%s', $logEntry->getGatewayName(), \PHP_EOL, \PHP_EOL);
}

$offset += self::LOG_FETCH_LIMIT;
Expand Down Expand Up @@ -151,31 +139,25 @@ public function isMediaProcessing(): bool
'SELECT COUNT(id) FROM swag_migration_media_file WHERE processed = 0 and process_failure != 1'
)->fetchOne();

return $unprocessedCount !== '0';
return (int) $unprocessedCount !== 0;
}

private function extractBucketInformation(Bucket $bucket): array
{
/** @var TermsResult $titleResult */
$titleResult = $bucket->getResult();
$titleBucket = $titleResult->getBuckets()[0];

/** @var TermsResult $entityResult */
$entityResult = $titleBucket->getResult();
$entityString = empty($entityResult->getBuckets()) ? '' : $entityResult->getBuckets()[0]->getKey();

/** @var TermsResult|null $levelResult */
$levelResult = $bucket->getResult();
$levelString = '';
if ($entityString !== '') {
/** @var TermsResult $levelResult */
$levelResult = $entityResult->getBuckets()[0]->getResult();
$levelString = empty($levelResult->getBuckets()) ? '' : $levelResult->getBuckets()[0]->getKey();

if ($levelResult !== null) {
$levelBuckets = $levelResult->getBuckets();
if (!empty($levelBuckets)) {
$levelString = $levelBuckets[0]->getKey();
}
}

return [
'code' => $bucket->getKey(),
'count' => $bucket->getCount(),
'titleSnippet' => $titleBucket->getKey(),
'entity' => $entityString,
'level' => $levelString,
];
}
Expand Down
Loading