@@ -9,118 +9,118 @@ |
||
9 | 9 | |
10 | 10 | class MigrateDisorganise extends BaseCommand |
11 | 11 | { |
12 | - /** |
|
13 | - * The console command name. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $name = 'migrate:disorganise'; |
|
18 | - |
|
19 | - /** |
|
20 | - * The console command description. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $description = 'Move migrations from a yyyy/mm folder structure back to the base migrations folder'; |
|
25 | - |
|
26 | - /** |
|
27 | - * The migrator instance. |
|
28 | - * |
|
29 | - * @var \Jaybizzle\MigrationsOrganiser\Migrator |
|
30 | - */ |
|
31 | - protected $migrator; |
|
32 | - |
|
33 | - /** |
|
34 | - * The filesystem instance. |
|
35 | - * |
|
36 | - * @var \Illuminate\Filesystem\Filesystem |
|
37 | - */ |
|
38 | - protected $files; |
|
39 | - |
|
40 | - /** |
|
41 | - * The basePath for the migrations. |
|
42 | - */ |
|
43 | - protected $basePath; |
|
44 | - |
|
45 | - /** |
|
46 | - * Create a new migrator instance. |
|
47 | - * |
|
48 | - * @param \Illuminate\Filesystem\Filesystem $files |
|
49 | - * @param \Illuminate\Database\Migrations\Migrator $migrator |
|
50 | - */ |
|
51 | - public function __construct(Filesystem $files, Migrator $migrator) |
|
52 | - { |
|
53 | - parent::__construct(); |
|
54 | - $this->migrator = $migrator; |
|
55 | - $this->files = $files; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Create date folder structure and move migrations into. |
|
60 | - * |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function fire() |
|
64 | - { |
|
65 | - $this->basePath = $this->getMigrationPath(); |
|
66 | - $migrations = $this->migrator->getMigrationFiles($this->basePath); |
|
67 | - $count = count($migrations); |
|
68 | - |
|
69 | - if ($count == 0) { |
|
70 | - $this->comment('No migrations to move'); |
|
71 | - |
|
72 | - return; |
|
73 | - } |
|
74 | - |
|
75 | - foreach ($migrations as $migration) { |
|
76 | - $datePath = $this->migrator->getDateFolderStructure($migration); |
|
77 | - // Move the migration into base migration folder |
|
78 | - $this->files->move($this->basePath.'/'.$datePath.$migration.'.php', $this->basePath.'/'.$migration.'.php'); |
|
79 | - } |
|
80 | - |
|
81 | - $this->info('Migrations disorganised successfully ('.$count.' migrations moved)'); |
|
82 | - $this->cleanup(); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Decide whether or not to delete directories. |
|
87 | - * |
|
88 | - * @return void |
|
89 | - */ |
|
90 | - public function cleanup() |
|
91 | - { |
|
92 | - if ($this->option('force')) { |
|
93 | - $this->deleteDirs(); |
|
94 | - } elseif ($this->confirm('Delete all subdirectories in migrations folder? [yes|no]', false)) { |
|
95 | - $this->deleteDirs(); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Delete subdirectories in the migrations folder. |
|
101 | - * |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - public function deleteDirs() |
|
105 | - { |
|
106 | - $dirs = $this->files->directories($this->basePath); |
|
107 | - |
|
108 | - foreach ($dirs as $dir) { |
|
109 | - $this->files->deleteDirectory($dir); |
|
110 | - } |
|
111 | - |
|
112 | - $this->info('Subdirectories deleted'); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Get the console command options. |
|
117 | - * |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - protected function getOptions() |
|
121 | - { |
|
122 | - return [ |
|
123 | - ['force', null, InputOption::VALUE_NONE, 'Force the operation to delete migration folder subdirectories without prompt.'], |
|
124 | - ]; |
|
125 | - } |
|
12 | + /** |
|
13 | + * The console command name. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $name = 'migrate:disorganise'; |
|
18 | + |
|
19 | + /** |
|
20 | + * The console command description. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $description = 'Move migrations from a yyyy/mm folder structure back to the base migrations folder'; |
|
25 | + |
|
26 | + /** |
|
27 | + * The migrator instance. |
|
28 | + * |
|
29 | + * @var \Jaybizzle\MigrationsOrganiser\Migrator |
|
30 | + */ |
|
31 | + protected $migrator; |
|
32 | + |
|
33 | + /** |
|
34 | + * The filesystem instance. |
|
35 | + * |
|
36 | + * @var \Illuminate\Filesystem\Filesystem |
|
37 | + */ |
|
38 | + protected $files; |
|
39 | + |
|
40 | + /** |
|
41 | + * The basePath for the migrations. |
|
42 | + */ |
|
43 | + protected $basePath; |
|
44 | + |
|
45 | + /** |
|
46 | + * Create a new migrator instance. |
|
47 | + * |
|
48 | + * @param \Illuminate\Filesystem\Filesystem $files |
|
49 | + * @param \Illuminate\Database\Migrations\Migrator $migrator |
|
50 | + */ |
|
51 | + public function __construct(Filesystem $files, Migrator $migrator) |
|
52 | + { |
|
53 | + parent::__construct(); |
|
54 | + $this->migrator = $migrator; |
|
55 | + $this->files = $files; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Create date folder structure and move migrations into. |
|
60 | + * |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function fire() |
|
64 | + { |
|
65 | + $this->basePath = $this->getMigrationPath(); |
|
66 | + $migrations = $this->migrator->getMigrationFiles($this->basePath); |
|
67 | + $count = count($migrations); |
|
68 | + |
|
69 | + if ($count == 0) { |
|
70 | + $this->comment('No migrations to move'); |
|
71 | + |
|
72 | + return; |
|
73 | + } |
|
74 | + |
|
75 | + foreach ($migrations as $migration) { |
|
76 | + $datePath = $this->migrator->getDateFolderStructure($migration); |
|
77 | + // Move the migration into base migration folder |
|
78 | + $this->files->move($this->basePath.'/'.$datePath.$migration.'.php', $this->basePath.'/'.$migration.'.php'); |
|
79 | + } |
|
80 | + |
|
81 | + $this->info('Migrations disorganised successfully ('.$count.' migrations moved)'); |
|
82 | + $this->cleanup(); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Decide whether or not to delete directories. |
|
87 | + * |
|
88 | + * @return void |
|
89 | + */ |
|
90 | + public function cleanup() |
|
91 | + { |
|
92 | + if ($this->option('force')) { |
|
93 | + $this->deleteDirs(); |
|
94 | + } elseif ($this->confirm('Delete all subdirectories in migrations folder? [yes|no]', false)) { |
|
95 | + $this->deleteDirs(); |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Delete subdirectories in the migrations folder. |
|
101 | + * |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + public function deleteDirs() |
|
105 | + { |
|
106 | + $dirs = $this->files->directories($this->basePath); |
|
107 | + |
|
108 | + foreach ($dirs as $dir) { |
|
109 | + $this->files->deleteDirectory($dir); |
|
110 | + } |
|
111 | + |
|
112 | + $this->info('Subdirectories deleted'); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Get the console command options. |
|
117 | + * |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + protected function getOptions() |
|
121 | + { |
|
122 | + return [ |
|
123 | + ['force', null, InputOption::VALUE_NONE, 'Force the operation to delete migration folder subdirectories without prompt.'], |
|
124 | + ]; |
|
125 | + } |
|
126 | 126 | } |
@@ -8,41 +8,41 @@ |
||
8 | 8 | |
9 | 9 | class MigrationsOrganiserServiceProvider extends MSP |
10 | 10 | { |
11 | - public function register() |
|
12 | - { |
|
13 | - parent::register(); |
|
14 | - $this->registerMigrateOrganise(); |
|
15 | - $this->registerMigrateDisorganise(); |
|
16 | - $this->commands('command.migrate.organise', 'command.migrate.disorganise'); |
|
17 | - } |
|
18 | - |
|
19 | - protected function registerCreator() |
|
20 | - { |
|
21 | - $this->app->singleton('migration.creator', function ($app) { |
|
22 | - return new MigrationCreator($app['files']); |
|
23 | - }); |
|
24 | - } |
|
25 | - |
|
26 | - protected function registerMigrator() |
|
27 | - { |
|
28 | - $this->app->singleton('migrator', function ($app) { |
|
29 | - $repository = $app['migration.repository']; |
|
30 | - |
|
31 | - return new Migrator($repository, $app['db'], $app['files']); |
|
32 | - }); |
|
33 | - } |
|
34 | - |
|
35 | - protected function registerMigrateOrganise() |
|
36 | - { |
|
37 | - $this->app->singleton('command.migrate.organise', function ($app) { |
|
38 | - return new MigrateOrganise($app['files'], $app['migrator']); |
|
39 | - }); |
|
40 | - } |
|
41 | - |
|
42 | - protected function registerMigrateDisorganise() |
|
43 | - { |
|
44 | - $this->app->singleton('command.migrate.disorganise', function ($app) { |
|
45 | - return new MigrateDisorganise($app['files'], $app['migrator']); |
|
46 | - }); |
|
47 | - } |
|
11 | + public function register() |
|
12 | + { |
|
13 | + parent::register(); |
|
14 | + $this->registerMigrateOrganise(); |
|
15 | + $this->registerMigrateDisorganise(); |
|
16 | + $this->commands('command.migrate.organise', 'command.migrate.disorganise'); |
|
17 | + } |
|
18 | + |
|
19 | + protected function registerCreator() |
|
20 | + { |
|
21 | + $this->app->singleton('migration.creator', function ($app) { |
|
22 | + return new MigrationCreator($app['files']); |
|
23 | + }); |
|
24 | + } |
|
25 | + |
|
26 | + protected function registerMigrator() |
|
27 | + { |
|
28 | + $this->app->singleton('migrator', function ($app) { |
|
29 | + $repository = $app['migration.repository']; |
|
30 | + |
|
31 | + return new Migrator($repository, $app['db'], $app['files']); |
|
32 | + }); |
|
33 | + } |
|
34 | + |
|
35 | + protected function registerMigrateOrganise() |
|
36 | + { |
|
37 | + $this->app->singleton('command.migrate.organise', function ($app) { |
|
38 | + return new MigrateOrganise($app['files'], $app['migrator']); |
|
39 | + }); |
|
40 | + } |
|
41 | + |
|
42 | + protected function registerMigrateDisorganise() |
|
43 | + { |
|
44 | + $this->app->singleton('command.migrate.disorganise', function ($app) { |
|
45 | + return new MigrateDisorganise($app['files'], $app['migrator']); |
|
46 | + }); |
|
47 | + } |
|
48 | 48 | } |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | |
19 | 19 | protected function registerCreator() |
20 | 20 | { |
21 | - $this->app->singleton('migration.creator', function ($app) { |
|
21 | + $this->app->singleton('migration.creator', function($app) { |
|
22 | 22 | return new MigrationCreator($app['files']); |
23 | 23 | }); |
24 | 24 | } |
25 | 25 | |
26 | 26 | protected function registerMigrator() |
27 | 27 | { |
28 | - $this->app->singleton('migrator', function ($app) { |
|
28 | + $this->app->singleton('migrator', function($app) { |
|
29 | 29 | $repository = $app['migration.repository']; |
30 | 30 | |
31 | 31 | return new Migrator($repository, $app['db'], $app['files']); |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | |
35 | 35 | protected function registerMigrateOrganise() |
36 | 36 | { |
37 | - $this->app->singleton('command.migrate.organise', function ($app) { |
|
37 | + $this->app->singleton('command.migrate.organise', function($app) { |
|
38 | 38 | return new MigrateOrganise($app['files'], $app['migrator']); |
39 | 39 | }); |
40 | 40 | } |
41 | 41 | |
42 | 42 | protected function registerMigrateDisorganise() |
43 | 43 | { |
44 | - $this->app->singleton('command.migrate.disorganise', function ($app) { |
|
44 | + $this->app->singleton('command.migrate.disorganise', function($app) { |
|
45 | 45 | return new MigrateDisorganise($app['files'], $app['migrator']); |
46 | 46 | }); |
47 | 47 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | return []; |
29 | 29 | } |
30 | 30 | |
31 | - $files = array_map(function ($file) { |
|
31 | + $files = array_map(function($file) { |
|
32 | 32 | return str_replace('.php', '', basename($file)); |
33 | 33 | |
34 | 34 | }, $files); |
@@ -6,166 +6,166 @@ |
||
6 | 6 | |
7 | 7 | class Migrator extends M |
8 | 8 | { |
9 | - /** |
|
10 | - * Fully qualified path to the application's migration directory. |
|
11 | - * |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - private $path; |
|
15 | - |
|
16 | - /** |
|
17 | - * Get all of the migration files in a given path. |
|
18 | - * |
|
19 | - * @param string $path |
|
20 | - * @param bool $recursive |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function getMigrationFiles($path, $recursive = true) |
|
25 | - { |
|
26 | - $this->setPath($path); |
|
27 | - |
|
28 | - if ($recursive === true) { |
|
29 | - $files = $this->rglob($this->path.'/*_*.php', 0, true); |
|
30 | - } else { |
|
31 | - $files = $this->files->glob($this->path.'/*_*.php'); |
|
32 | - } |
|
33 | - |
|
34 | - // Once we have the array of files in the directory we will just remove the |
|
35 | - // extension and take the basename of the file which is all we need when |
|
36 | - // finding the migrations that haven't been run against the databases. |
|
37 | - if ($files === false) { |
|
38 | - return []; |
|
39 | - } |
|
40 | - |
|
41 | - $files = array_map(function ($file) { |
|
42 | - return str_replace('.php', '', basename($file)); |
|
43 | - }, $files); |
|
44 | - |
|
45 | - // Once we have all of the formatted file names we will sort them and since |
|
46 | - // they all start with a timestamp this should give us the migrations in |
|
47 | - // the order they were actually created by the application developers. |
|
48 | - sort($files); |
|
49 | - |
|
50 | - return $files; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Require in all the migration files in a given path. |
|
55 | - * |
|
56 | - * @param array $files |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function requireFiles(array $files) |
|
61 | - { |
|
62 | - foreach ($files as $file) { |
|
63 | - $newPath = $this->getFilePathWithFolders($file).'.php'; |
|
64 | - $this->files->requireOnce($newPath); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Run "up" a migration instance. |
|
70 | - * |
|
71 | - * @param string $file |
|
72 | - * @param int $batch |
|
73 | - * @param bool $pretend |
|
74 | - * |
|
75 | - * @return void |
|
76 | - */ |
|
77 | - protected function runUp($file, $batch, $pretend) |
|
78 | - { |
|
79 | - // First we will resolve a "real" instance of the migration class from this |
|
80 | - // migration file name. Once we have the instances we can run the actual |
|
81 | - // command such as "up" or "down", or we can just simulate the action. |
|
82 | - $migration = $this->resolve($file); |
|
83 | - |
|
84 | - if ($pretend) { |
|
85 | - return $this->pretendToRun($migration, 'up'); |
|
86 | - } |
|
87 | - |
|
88 | - $migration->up(); |
|
89 | - |
|
90 | - // Once we have run a migrations class, we will log that it was run in this |
|
91 | - // repository so that we don't try to run it next time we do a migration |
|
92 | - // in the application. A migration repository keeps the migrate order. |
|
93 | - $this->repository->log($this->getFilePathWithoutFolders($file), $batch); |
|
94 | - |
|
95 | - $this->note("<info>Migrated:</info> $file"); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Recursive glob. |
|
100 | - * |
|
101 | - * @param string $pattern |
|
102 | - * @param int $flags |
|
103 | - * @param bool $ignore |
|
104 | - * |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - public function rglob($pattern, $flags = 0, $ignore = false) |
|
108 | - { |
|
109 | - if ($ignore === false) { |
|
110 | - $files = glob($pattern, $flags); |
|
111 | - } else { |
|
112 | - $files = []; |
|
113 | - } |
|
114 | - |
|
115 | - foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { |
|
116 | - $files = array_merge($files, $this->rglob($dir.'/'.basename($pattern), $flags)); |
|
117 | - } |
|
118 | - |
|
119 | - return $files; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Get the migration file path with our injected date folder. |
|
124 | - * |
|
125 | - * @param string $file |
|
126 | - * |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getFilePathWithFolders($file) |
|
130 | - { |
|
131 | - $datePath = $this->getDateFolderStructure($file); |
|
132 | - |
|
133 | - return $this->path.'/'.$datePath.$file; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Remove folders from file path. |
|
138 | - * |
|
139 | - * @param string $file |
|
140 | - * |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function getFilePathWithoutFolders($file) |
|
144 | - { |
|
145 | - return basename($file); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Add date folders to migrations path. |
|
150 | - * |
|
151 | - * @param string $file |
|
152 | - * |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public function getDateFolderStructure($file) |
|
156 | - { |
|
157 | - $parts = explode('_', $file); |
|
158 | - |
|
159 | - return $parts[0].'/'.$parts[1].'/'; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Set the path. |
|
164 | - * |
|
165 | - * @param array|string $path |
|
166 | - */ |
|
167 | - private function setPath($path) |
|
168 | - { |
|
169 | - $this->path = is_array($path) ? $path[0] : $path; |
|
170 | - } |
|
9 | + /** |
|
10 | + * Fully qualified path to the application's migration directory. |
|
11 | + * |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + private $path; |
|
15 | + |
|
16 | + /** |
|
17 | + * Get all of the migration files in a given path. |
|
18 | + * |
|
19 | + * @param string $path |
|
20 | + * @param bool $recursive |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function getMigrationFiles($path, $recursive = true) |
|
25 | + { |
|
26 | + $this->setPath($path); |
|
27 | + |
|
28 | + if ($recursive === true) { |
|
29 | + $files = $this->rglob($this->path.'/*_*.php', 0, true); |
|
30 | + } else { |
|
31 | + $files = $this->files->glob($this->path.'/*_*.php'); |
|
32 | + } |
|
33 | + |
|
34 | + // Once we have the array of files in the directory we will just remove the |
|
35 | + // extension and take the basename of the file which is all we need when |
|
36 | + // finding the migrations that haven't been run against the databases. |
|
37 | + if ($files === false) { |
|
38 | + return []; |
|
39 | + } |
|
40 | + |
|
41 | + $files = array_map(function ($file) { |
|
42 | + return str_replace('.php', '', basename($file)); |
|
43 | + }, $files); |
|
44 | + |
|
45 | + // Once we have all of the formatted file names we will sort them and since |
|
46 | + // they all start with a timestamp this should give us the migrations in |
|
47 | + // the order they were actually created by the application developers. |
|
48 | + sort($files); |
|
49 | + |
|
50 | + return $files; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Require in all the migration files in a given path. |
|
55 | + * |
|
56 | + * @param array $files |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function requireFiles(array $files) |
|
61 | + { |
|
62 | + foreach ($files as $file) { |
|
63 | + $newPath = $this->getFilePathWithFolders($file).'.php'; |
|
64 | + $this->files->requireOnce($newPath); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Run "up" a migration instance. |
|
70 | + * |
|
71 | + * @param string $file |
|
72 | + * @param int $batch |
|
73 | + * @param bool $pretend |
|
74 | + * |
|
75 | + * @return void |
|
76 | + */ |
|
77 | + protected function runUp($file, $batch, $pretend) |
|
78 | + { |
|
79 | + // First we will resolve a "real" instance of the migration class from this |
|
80 | + // migration file name. Once we have the instances we can run the actual |
|
81 | + // command such as "up" or "down", or we can just simulate the action. |
|
82 | + $migration = $this->resolve($file); |
|
83 | + |
|
84 | + if ($pretend) { |
|
85 | + return $this->pretendToRun($migration, 'up'); |
|
86 | + } |
|
87 | + |
|
88 | + $migration->up(); |
|
89 | + |
|
90 | + // Once we have run a migrations class, we will log that it was run in this |
|
91 | + // repository so that we don't try to run it next time we do a migration |
|
92 | + // in the application. A migration repository keeps the migrate order. |
|
93 | + $this->repository->log($this->getFilePathWithoutFolders($file), $batch); |
|
94 | + |
|
95 | + $this->note("<info>Migrated:</info> $file"); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Recursive glob. |
|
100 | + * |
|
101 | + * @param string $pattern |
|
102 | + * @param int $flags |
|
103 | + * @param bool $ignore |
|
104 | + * |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + public function rglob($pattern, $flags = 0, $ignore = false) |
|
108 | + { |
|
109 | + if ($ignore === false) { |
|
110 | + $files = glob($pattern, $flags); |
|
111 | + } else { |
|
112 | + $files = []; |
|
113 | + } |
|
114 | + |
|
115 | + foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { |
|
116 | + $files = array_merge($files, $this->rglob($dir.'/'.basename($pattern), $flags)); |
|
117 | + } |
|
118 | + |
|
119 | + return $files; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Get the migration file path with our injected date folder. |
|
124 | + * |
|
125 | + * @param string $file |
|
126 | + * |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getFilePathWithFolders($file) |
|
130 | + { |
|
131 | + $datePath = $this->getDateFolderStructure($file); |
|
132 | + |
|
133 | + return $this->path.'/'.$datePath.$file; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Remove folders from file path. |
|
138 | + * |
|
139 | + * @param string $file |
|
140 | + * |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function getFilePathWithoutFolders($file) |
|
144 | + { |
|
145 | + return basename($file); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Add date folders to migrations path. |
|
150 | + * |
|
151 | + * @param string $file |
|
152 | + * |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public function getDateFolderStructure($file) |
|
156 | + { |
|
157 | + $parts = explode('_', $file); |
|
158 | + |
|
159 | + return $parts[0].'/'.$parts[1].'/'; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Set the path. |
|
164 | + * |
|
165 | + * @param array|string $path |
|
166 | + */ |
|
167 | + private function setPath($path) |
|
168 | + { |
|
169 | + $this->path = is_array($path) ? $path[0] : $path; |
|
170 | + } |
|
171 | 171 | } |
@@ -6,14 +6,14 @@ |
||
6 | 6 | |
7 | 7 | class MigrationCreator extends MC |
8 | 8 | { |
9 | - protected function getPath($name, $path) |
|
10 | - { |
|
11 | - $path = $path.'/'.date('Y').'/'.date('m'); |
|
9 | + protected function getPath($name, $path) |
|
10 | + { |
|
11 | + $path = $path.'/'.date('Y').'/'.date('m'); |
|
12 | 12 | |
13 | - if (! $this->files->exists($path)) { |
|
14 | - $this->files->makeDirectory($path, 0775, true); |
|
15 | - } |
|
13 | + if (! $this->files->exists($path)) { |
|
14 | + $this->files->makeDirectory($path, 0775, true); |
|
15 | + } |
|
16 | 16 | |
17 | - return $path.'/'.$this->getDatePrefix().'_'.$name.'.php'; |
|
18 | - } |
|
17 | + return $path.'/'.$this->getDatePrefix().'_'.$name.'.php'; |
|
18 | + } |
|
19 | 19 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | { |
11 | 11 | $path = $path.'/'.date('Y').'/'.date('m'); |
12 | 12 | |
13 | - if (! $this->files->exists($path)) { |
|
13 | + if ( ! $this->files->exists($path)) { |
|
14 | 14 | $this->files->makeDirectory($path, 0775, true); |
15 | 15 | } |
16 | 16 |
@@ -8,76 +8,76 @@ |
||
8 | 8 | |
9 | 9 | class MigrateOrganise extends BaseCommand |
10 | 10 | { |
11 | - /** |
|
12 | - * The console command name. |
|
13 | - * |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $name = 'migrate:organise'; |
|
11 | + /** |
|
12 | + * The console command name. |
|
13 | + * |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $name = 'migrate:organise'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * The console command description. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $description = 'Move migrations into a yyyy/mm folder structure'; |
|
18 | + /** |
|
19 | + * The console command description. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $description = 'Move migrations into a yyyy/mm folder structure'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * The migrator instance. |
|
27 | - * |
|
28 | - * @var \Jaybizzle\MigrationsOrganiser\Migrator |
|
29 | - */ |
|
30 | - protected $migrator; |
|
25 | + /** |
|
26 | + * The migrator instance. |
|
27 | + * |
|
28 | + * @var \Jaybizzle\MigrationsOrganiser\Migrator |
|
29 | + */ |
|
30 | + protected $migrator; |
|
31 | 31 | |
32 | - /** |
|
33 | - * The filesystem instance. |
|
34 | - * |
|
35 | - * @var \Illuminate\Filesystem\Filesystem |
|
36 | - */ |
|
37 | - protected $files; |
|
32 | + /** |
|
33 | + * The filesystem instance. |
|
34 | + * |
|
35 | + * @var \Illuminate\Filesystem\Filesystem |
|
36 | + */ |
|
37 | + protected $files; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Create a new migrator instance. |
|
41 | - * |
|
42 | - * @param \Illuminate\Filesystem\Filesystem $files |
|
43 | - * @param \Illuminate\Database\Migrations\Migrator $migrator |
|
44 | - */ |
|
45 | - public function __construct(Filesystem $files, Migrator $migrator) |
|
46 | - { |
|
47 | - parent::__construct(); |
|
48 | - $this->migrator = $migrator; |
|
49 | - $this->files = $files; |
|
50 | - } |
|
39 | + /** |
|
40 | + * Create a new migrator instance. |
|
41 | + * |
|
42 | + * @param \Illuminate\Filesystem\Filesystem $files |
|
43 | + * @param \Illuminate\Database\Migrations\Migrator $migrator |
|
44 | + */ |
|
45 | + public function __construct(Filesystem $files, Migrator $migrator) |
|
46 | + { |
|
47 | + parent::__construct(); |
|
48 | + $this->migrator = $migrator; |
|
49 | + $this->files = $files; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Create date folder structure and move migrations into. |
|
54 | - * |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function fire() |
|
58 | - { |
|
59 | - $basePath = $this->getMigrationPath(); |
|
60 | - $migrations = $this->migrator->getMigrationFiles($basePath, false); |
|
61 | - $count = count($migrations); |
|
52 | + /** |
|
53 | + * Create date folder structure and move migrations into. |
|
54 | + * |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function fire() |
|
58 | + { |
|
59 | + $basePath = $this->getMigrationPath(); |
|
60 | + $migrations = $this->migrator->getMigrationFiles($basePath, false); |
|
61 | + $count = count($migrations); |
|
62 | 62 | |
63 | - if ($count == 0) { |
|
64 | - $this->comment('No migrations to move'); |
|
63 | + if ($count == 0) { |
|
64 | + $this->comment('No migrations to move'); |
|
65 | 65 | |
66 | - return; |
|
67 | - } |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - foreach ($migrations as $migration) { |
|
70 | - $datePath = $this->migrator->getDateFolderStructure($migration); |
|
69 | + foreach ($migrations as $migration) { |
|
70 | + $datePath = $this->migrator->getDateFolderStructure($migration); |
|
71 | 71 | |
72 | - // Create folder if it does not already exist |
|
73 | - if (! $this->files->exists($basePath.'/'.$datePath)) { |
|
74 | - $this->files->makeDirectory($basePath.'/'.$datePath, 0775, true); |
|
75 | - } |
|
72 | + // Create folder if it does not already exist |
|
73 | + if (! $this->files->exists($basePath.'/'.$datePath)) { |
|
74 | + $this->files->makeDirectory($basePath.'/'.$datePath, 0775, true); |
|
75 | + } |
|
76 | 76 | |
77 | - // Move the migration into its new folder |
|
78 | - $this->files->move($basePath.'/'.$migration.'.php', $basePath.'/'.$datePath.$migration.'.php'); |
|
79 | - } |
|
77 | + // Move the migration into its new folder |
|
78 | + $this->files->move($basePath.'/'.$migration.'.php', $basePath.'/'.$datePath.$migration.'.php'); |
|
79 | + } |
|
80 | 80 | |
81 | - $this->info('Migrations organised successfully ('.$count.' migrations moved)'); |
|
82 | - } |
|
81 | + $this->info('Migrations organised successfully ('.$count.' migrations moved)'); |
|
82 | + } |
|
83 | 83 | } |
@@ -70,7 +70,7 @@ |
||
70 | 70 | $datePath = $this->migrator->getDateFolderStructure($migration); |
71 | 71 | |
72 | 72 | // Create folder if it does not already exist |
73 | - if (! $this->files->exists($basePath.'/'.$datePath)) { |
|
73 | + if ( ! $this->files->exists($basePath.'/'.$datePath)) { |
|
74 | 74 | $this->files->makeDirectory($basePath.'/'.$datePath, 0775, true); |
75 | 75 | } |
76 | 76 |