mirror of
https://github.com/macintoshplus/yaml-migrations.git
synced 2026-03-24 00:42:18 +01:00
Working
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
# location of the files used for the migrations
|
||||
migrations: sample/migrations
|
||||
checkpoint: sample/migrations/checkpoint.txt
|
||||
|
||||
# Folder of the source files
|
||||
source: sample/source
|
||||
|
||||
# Target folder of the processed files. Set this to the same as 'source' to overwrite
|
||||
target: sample/target
|
||||
target: sample/target
|
||||
|
||||
|
||||
@@ -14,38 +14,35 @@ class ArrayMerge
|
||||
/**
|
||||
* @see https://api.drupal.org/api/drupal/vendor%21wikimedia%21composer-merge-plugin%21src%21Merge%21NestedArray.php/function/NestedArray%3A%3AmergeDeepArray/8.7.x
|
||||
*/
|
||||
public static function mergeDeepArray(array $arrays, $preserveIntegerKeys = false) {
|
||||
public static function mergeDeepArray(array $arrays, $preserveIntegerKeys = false): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($arrays as $array) {
|
||||
foreach ($array as $key => $value) {
|
||||
|
||||
// Don't add duplicates of objects here
|
||||
if (in_array($value, $result) && is_object($value)) {
|
||||
if (\in_array($value, $result, true) && \is_object($value)) {
|
||||
continue;
|
||||
}
|
||||
// Renumber integer keys as array_merge_recursive() does
|
||||
// unless $preserveIntegerKeys is set to TRUE. Note that PHP
|
||||
// automatically converts array keys that are integer strings
|
||||
// (e.g., '1') to integers.
|
||||
if (is_integer($key) && !$preserveIntegerKeys) {
|
||||
if (\is_int($key) && ! $preserveIntegerKeys) {
|
||||
$result[] = $value;
|
||||
}
|
||||
elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
|
||||
|
||||
} elseif (isset($result[$key]) && \is_array($result[$key]) && \is_array($value)) {
|
||||
// Recurse when both values are arrays.
|
||||
$result[$key] = self::mergeDeepArray(array(
|
||||
$result[$key] = self::mergeDeepArray([
|
||||
$result[$key],
|
||||
$value,
|
||||
), $preserveIntegerKeys);
|
||||
}
|
||||
else {
|
||||
|
||||
], $preserveIntegerKeys);
|
||||
} else {
|
||||
// Otherwise, use the latter value, overriding any
|
||||
// previous value.
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ class Migrate
|
||||
die("Config file ${configFilename} not found.");
|
||||
}
|
||||
|
||||
if (file_exists($this->config['migrations'].'/checkpoint.txt')) {
|
||||
$this->checkpoint = trim(file_get_contents($this->config['migrations'].'/checkpoint.txt'));
|
||||
if (file_exists($this->checkpointFilename())) {
|
||||
$this->checkpoint = trim(file_get_contents($this->checkpointFilename()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class Migrate
|
||||
// We only update the checkpoint if we process the list, not a single file
|
||||
if (! $onlyFilename && $this->statistics['updated'] > 0) {
|
||||
$this->output('Updating checkpoint to '.$this->checkpoint, true);
|
||||
FileWriter::writeFile($this->config['migrations'].'/checkpoint.txt', $this->checkpoint);
|
||||
FileWriter::writeFile($this->checkpointFilename(), $this->checkpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,6 +270,15 @@ class Migrate
|
||||
];
|
||||
}
|
||||
|
||||
private function checkpointFilename(): string
|
||||
{
|
||||
if ($this->config['checkpoint']) {
|
||||
return $this->config['checkpoint'];
|
||||
}
|
||||
|
||||
return $this->config['migrations'].'/checkpoint.txt';
|
||||
}
|
||||
|
||||
private function setMaxCheckpoint(string $version): void
|
||||
{
|
||||
if (Comparator::greaterThan($version, $this->checkpoint)) {
|
||||
|
||||
Reference in New Issue
Block a user