-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
ExecuteMigration.php
96 lines (84 loc) · 2.91 KB
/
ExecuteMigration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
* This file is part of the Neos.ContentRepository package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
declare(strict_types=1);
namespace Neos\ContentRepository\NodeMigration\Command;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
/**
* Execute a Content Repository migration (which is defined in a YAML file)
*/
final class ExecuteMigration
{
/**
* @var MigrationConfiguration
*/
private $migrationConfiguration;
/**
* @var WorkspaceName
*/
private $workspaceName;
/**
* This property exists mostly for testing, to make the command handler fully deterministic.
*
* A migration file is structured like this:
* migrations: [
* {filters: ... transformations: ...},
* {filters: ... transformations: ...}
* ]
* For every "submigration" (i.e. every "line" from above), we fork a new content stream,
* to make the migration roll-back-able.
* In the first "submigration", we use the base content stream identifier (of $workspaceName) for *reading*, and
* use the first content stream identifier of this list for writing.
* In the second "submigration", we use the content stream of the *first* submigration for reading, and the next one
* from this list for writing.
*
* This effectively makes all changes of the first submigration visible in the next submigration.
*
* @var ContentStreamId[]
*/
private $contentStreamIdsForWriting;
/**
* ExecuteMigration constructor.
* @param MigrationConfiguration $migrationConfiguration
* @param WorkspaceName $workspaceName
* @param ContentStreamId[] $contentStreamIdsForWriting
*/
public function __construct(
MigrationConfiguration $migrationConfiguration,
WorkspaceName $workspaceName,
array $contentStreamIdsForWriting = []
) {
$this->migrationConfiguration = $migrationConfiguration;
$this->workspaceName = $workspaceName;
$this->contentStreamIdsForWriting = array_values($contentStreamIdsForWriting);
}
/**
* @return MigrationConfiguration
*/
public function getMigrationConfiguration(): MigrationConfiguration
{
return $this->migrationConfiguration;
}
/**
* @return WorkspaceName
*/
public function getWorkspaceName(): WorkspaceName
{
return $this->workspaceName;
}
public function getOrCreateContentStreamIdForWriting(int $index): ContentStreamId
{
if (isset($this->contentStreamIdsForWriting[$index])) {
return $this->contentStreamIdsForWriting[$index];
}
return ContentStreamId::create();
}
}