Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit da23618

Browse files
committed
sorting migrations so they run in order on ubuntu
1 parent 0bb04d5 commit da23618

File tree

1 file changed

+54
-53
lines changed

1 file changed

+54
-53
lines changed

core/lib/PatternLab/Migrator.php

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,66 +27,70 @@ public function __construct() {
2727
*/
2828
public function migrate($diffVersion = false) {
2929

30-
$migrations = new \DirectoryIterator(__DIR__."/../../migrations/");
30+
$migrations = new \DirectoryIterator(__DIR__."/../../migrations/");
31+
$migrationsValid = array();
3132

3233
foreach ($migrations as $migration) {
33-
3434
$filename = $migration->getFilename();
35-
3635
if (!$migration->isDot() && $migration->isFile() && ($filename[0] != "_")) {
36+
$migrationsValid[] = $filename;
37+
}
38+
}
39+
40+
asort($migrationsValid);
41+
42+
foreach ($migrationsValid as $filename) {
43+
44+
$basePath = __DIR__."/../../../";
45+
$migrationData = json_decode(file_get_contents(__DIR__."/../../migrations/".$filename));
46+
$checkType = $migrationData->checkType;
47+
$sourcePath = ($checkType == "fileExists") ? $basePath.$migrationData->sourcePath : $basePath.$migrationData->sourcePath.DIRECTORY_SEPARATOR;
48+
$destinationPath = ($checkType == "fileExists") ? $basePath.$migrationData->destinationPath : $basePath.$migrationData->destinationPath.DIRECTORY_SEPARATOR;
49+
50+
if ($checkType == "dirEmpty") {
3751

38-
$basePath = __DIR__."/../../../";
39-
$migrationData = json_decode(file_get_contents($migration->getPathname()));
40-
$checkType = $migrationData->checkType;
41-
$sourcePath = ($checkType == "fileExists") ? $basePath.$migrationData->sourcePath : $basePath.$migrationData->sourcePath.DIRECTORY_SEPARATOR;
42-
$destinationPath = ($checkType == "fileExists") ? $basePath.$migrationData->destinationPath : $basePath.$migrationData->destinationPath.DIRECTORY_SEPARATOR;
43-
44-
if ($checkType == "dirEmpty") {
45-
46-
$emptyDir = true;
47-
$objects = new \DirectoryIterator($destinationPath);
48-
foreach ($objects as $object) {
49-
if (!$object->isDot() && ($object->getFilename() != "README") && ($object->getFilename() != ".DS_Store")) {
50-
$emptyDir = false;
51-
}
52+
$emptyDir = true;
53+
$objects = new \DirectoryIterator($destinationPath);
54+
foreach ($objects as $object) {
55+
if (!$object->isDot() && ($object->getFilename() != "README") && ($object->getFilename() != ".DS_Store")) {
56+
$emptyDir = false;
5257
}
53-
54-
if ($emptyDir) {
55-
$this->runMigration($filename, $sourcePath, $destinationPath, false);
56-
}
57-
58-
} else if ($checkType == "dirExists") {
59-
60-
if (!is_dir($destinationPath)) {
61-
mkdir($destinationPath);
62-
}
63-
64-
} else if ($checkType == "fileExists") {
65-
66-
if (!file_exists($destinationPath)) {
67-
$this->runMigration($filename, $sourcePath, $destinationPath, true);
68-
}
69-
70-
} else if (($checkType == "versionDiffDir") && $diffVersion) {
71-
72-
// make sure the destination path exists
73-
if (!is_dir($destinationPath)) {
74-
mkdir($destinationPath);
75-
}
76-
58+
}
59+
60+
if ($emptyDir) {
7761
$this->runMigration($filename, $sourcePath, $destinationPath, false);
78-
79-
} else if (($checkType == "versionDiffFile") && $diffVersion) {
80-
62+
}
63+
64+
} else if ($checkType == "dirExists") {
65+
66+
if (!is_dir($destinationPath)) {
67+
mkdir($destinationPath);
68+
}
69+
70+
} else if ($checkType == "fileExists") {
71+
72+
if (!file_exists($destinationPath)) {
8173
$this->runMigration($filename, $sourcePath, $destinationPath, true);
82-
83-
} else {
84-
85-
print "Pattern Lab doesn't recognize a checkType of ".$checkType.". The migrator class is pretty thin at the moment.\n";
86-
exit;
87-
8874
}
8975

76+
} else if (($checkType == "versionDiffDir") && $diffVersion) {
77+
78+
// make sure the destination path exists
79+
if (!is_dir($destinationPath)) {
80+
mkdir($destinationPath);
81+
}
82+
83+
$this->runMigration($filename, $sourcePath, $destinationPath, false);
84+
85+
} else if (($checkType == "versionDiffFile") && $diffVersion) {
86+
87+
$this->runMigration($filename, $sourcePath, $destinationPath, true);
88+
89+
} else {
90+
91+
print "Pattern Lab doesn't recognize a checkType of ".$checkType.". The migrator class is pretty thin at the moment.\n";
92+
exit;
93+
9094
}
9195

9296
}
@@ -111,10 +115,7 @@ protected function runMigration($filename, $sourcePath, $destinationPath, $singl
111115

112116
} else {
113117

114-
// iterate over all of the other files in the source directory and move them if their modified time has changed
115118
$objects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourcePath), \RecursiveIteratorIterator::SELF_FIRST);
116-
117-
// make sure dots are skipped
118119
$objects->setFlags(\FilesystemIterator::SKIP_DOTS);
119120

120121
foreach ($objects as $object) {

0 commit comments

Comments
 (0)