1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Recovery\Common; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Framework\Migration\MigrationSource as CoreMigrationSource; |
6
|
|
|
use function file_exists; |
7
|
|
|
use function is_dir; |
8
|
|
|
use function sprintf; |
9
|
|
|
use const SW_PATH; |
10
|
|
|
|
11
|
|
|
class MigrationSourceCollector |
12
|
|
|
{ |
13
|
|
|
public static function collect(): array |
14
|
|
|
{ |
15
|
|
|
return [ |
16
|
|
|
new CoreMigrationSource('core', []), |
17
|
|
|
self::createMigrationSource('V6_3', true), |
18
|
|
|
self::createMigrationSource('V6_4', true), |
19
|
|
|
self::createMigrationSource('V6_5'), |
20
|
|
|
]; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
private static function createMigrationSource(string $version, bool $addReplacements = false): CoreMigrationSource |
24
|
|
|
{ |
25
|
|
|
if (file_exists(SW_PATH . '/platform/src/Core/schema.sql')) { |
26
|
|
|
$coreBasePath = SW_PATH . '/platform/src/Core'; |
27
|
|
|
$storefrontBasePath = SW_PATH . '/platform/src/Storefront'; |
28
|
|
|
$adminBasePath = SW_PATH . '/platform/src/Administration'; |
29
|
|
|
} elseif (file_exists(SW_PATH . '/src/Core/schema.sql')) { |
30
|
|
|
$coreBasePath = SW_PATH . '/src/Core'; |
31
|
|
|
$storefrontBasePath = SW_PATH . '/src/Storefront'; |
32
|
|
|
$adminBasePath = SW_PATH . '/src/Administration'; |
33
|
|
|
} else { |
34
|
|
|
$coreBasePath = SW_PATH . '/vendor/shopware/core'; |
35
|
|
|
$storefrontBasePath = SW_PATH . '/vendor/shopware/storefront'; |
36
|
|
|
$adminBasePath = SW_PATH . '/vendor/shopware/administration'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$hasStorefrontMigrations = is_dir($storefrontBasePath); |
40
|
|
|
$hasAdminMigrations = is_dir($adminBasePath); |
41
|
|
|
|
42
|
|
|
$source = new CoreMigrationSource('core.' . $version, [ |
43
|
|
|
sprintf('%s/Migration/%s', $coreBasePath, $version) => sprintf('Shopware\\Core\\Migration\\%s', $version), |
44
|
|
|
]); |
45
|
|
|
|
46
|
|
|
if ($hasStorefrontMigrations) { |
47
|
|
|
$source->addDirectory(sprintf('%s/Migration/%s', $storefrontBasePath, $version), sprintf('Shopware\\Storefront\\Migration\\%s', $version)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ($hasAdminMigrations) { |
51
|
|
|
$source->addDirectory(sprintf('%s/Migration/%s', $adminBasePath, $version), sprintf('Shopware\\Administration\\Migration\\%s', $version)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($addReplacements) { |
55
|
|
|
$source->addReplacementPattern(sprintf('#^(Shopware\\\\Core\\\\Migration\\\\)%s\\\\([^\\\\]*)$#', $version), '$1$2'); |
56
|
|
|
if ($hasStorefrontMigrations) { |
57
|
|
|
$source->addReplacementPattern(sprintf('#^(Shopware\\\\Storefront\\\\Migration\\\\)%s\\\\([^\\\\]*)$#', $version), '$1$2'); |
58
|
|
|
} |
59
|
|
|
if ($hasAdminMigrations) { |
60
|
|
|
$source->addReplacementPattern(sprintf('#^(Shopware\\\\Administration\\\\Migration\\\\)%s\\\\([^\\\\]*)$#', $version), '$1$2'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $source; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|