@@ -27,66 +27,70 @@ public function __construct() {
27
27
*/
28
28
public function migrate ($ diffVersion = false ) {
29
29
30
- $ migrations = new \DirectoryIterator (__DIR__ ."/../../migrations/ " );
30
+ $ migrations = new \DirectoryIterator (__DIR__ ."/../../migrations/ " );
31
+ $ migrationsValid = array ();
31
32
32
33
foreach ($ migrations as $ migration ) {
33
-
34
34
$ filename = $ migration ->getFilename ();
35
-
36
35
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 " ) {
37
51
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 ;
52
57
}
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 ) {
77
61
$ 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 )) {
81
73
$ 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
-
88
74
}
89
75
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
+
90
94
}
91
95
92
96
}
@@ -111,10 +115,7 @@ protected function runMigration($filename, $sourcePath, $destinationPath, $singl
111
115
112
116
} else {
113
117
114
- // iterate over all of the other files in the source directory and move them if their modified time has changed
115
118
$ objects = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ sourcePath ), \RecursiveIteratorIterator::SELF_FIRST );
116
-
117
- // make sure dots are skipped
118
119
$ objects ->setFlags (\FilesystemIterator::SKIP_DOTS );
119
120
120
121
foreach ($ objects as $ object ) {
0 commit comments