@@ -37,7 +37,7 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | public function getRecursiveFolders($folders) |
| 39 | 39 | { |
| 40 | - if (! is_array($folders)) { |
|
| 40 | + if ( ! is_array($folders)) { |
|
| 41 | 41 | $folders = [$folders]; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -8,68 +8,68 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Migrator extends M |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Get all of the migration files in a given path. |
|
| 13 | - * |
|
| 14 | - * @param string|array $paths |
|
| 15 | - * @param bool $recursive |
|
| 16 | - * @return array |
|
| 17 | - */ |
|
| 18 | - public function getMigrationFiles($paths = [], $recursive = true) |
|
| 19 | - { |
|
| 20 | - if ($recursive) { |
|
| 21 | - $paths = $this->getRecursiveFolders($paths); |
|
| 22 | - } |
|
| 11 | + /** |
|
| 12 | + * Get all of the migration files in a given path. |
|
| 13 | + * |
|
| 14 | + * @param string|array $paths |
|
| 15 | + * @param bool $recursive |
|
| 16 | + * @return array |
|
| 17 | + */ |
|
| 18 | + public function getMigrationFiles($paths = [], $recursive = true) |
|
| 19 | + { |
|
| 20 | + if ($recursive) { |
|
| 21 | + $paths = $this->getRecursiveFolders($paths); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - $files = parent::getMigrationFiles($paths); |
|
| 24 | + $files = parent::getMigrationFiles($paths); |
|
| 25 | 25 | |
| 26 | - return $files; |
|
| 27 | - } |
|
| 26 | + return $files; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Get all subdirectories located in an array of folders. |
|
| 31 | - * |
|
| 32 | - * @param string|array $folders |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - public function getRecursiveFolders($folders) |
|
| 36 | - { |
|
| 37 | - if (! is_array($folders)) { |
|
| 38 | - $folders = [$folders]; |
|
| 39 | - } |
|
| 29 | + /** |
|
| 30 | + * Get all subdirectories located in an array of folders. |
|
| 31 | + * |
|
| 32 | + * @param string|array $folders |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + public function getRecursiveFolders($folders) |
|
| 36 | + { |
|
| 37 | + if (! is_array($folders)) { |
|
| 38 | + $folders = [$folders]; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $paths = []; |
|
| 41 | + $paths = []; |
|
| 42 | 42 | |
| 43 | - foreach ($folders as $folder) { |
|
| 44 | - $iter = new Iterator( |
|
| 45 | - new DirectoryIterator($folder, DirectoryIterator::SKIP_DOTS), |
|
| 46 | - Iterator::SELF_FIRST, |
|
| 47 | - Iterator::CATCH_GET_CHILD // Ignore "Permission denied" |
|
| 48 | - ); |
|
| 43 | + foreach ($folders as $folder) { |
|
| 44 | + $iter = new Iterator( |
|
| 45 | + new DirectoryIterator($folder, DirectoryIterator::SKIP_DOTS), |
|
| 46 | + Iterator::SELF_FIRST, |
|
| 47 | + Iterator::CATCH_GET_CHILD // Ignore "Permission denied" |
|
| 48 | + ); |
|
| 49 | 49 | |
| 50 | - $subPaths = [$folder]; |
|
| 51 | - foreach ($iter as $path => $dir) { |
|
| 52 | - if ($dir->isDir()) { |
|
| 53 | - $subPaths[] = $path; |
|
| 54 | - } |
|
| 55 | - } |
|
| 50 | + $subPaths = [$folder]; |
|
| 51 | + foreach ($iter as $path => $dir) { |
|
| 52 | + if ($dir->isDir()) { |
|
| 53 | + $subPaths[] = $path; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $paths = array_merge($paths, $subPaths); |
|
| 58 | - } |
|
| 57 | + $paths = array_merge($paths, $subPaths); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return $paths; |
|
| 61 | - } |
|
| 60 | + return $paths; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Add date folders to migrations path. |
|
| 65 | - * |
|
| 66 | - * @param string $file |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function getDateFolderStructure($file) |
|
| 70 | - { |
|
| 71 | - $parts = explode('_', $file); |
|
| 63 | + /** |
|
| 64 | + * Add date folders to migrations path. |
|
| 65 | + * |
|
| 66 | + * @param string $file |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function getDateFolderStructure($file) |
|
| 70 | + { |
|
| 71 | + $parts = explode('_', $file); |
|
| 72 | 72 | |
| 73 | - return $parts[0].'/'.$parts[1].'/'; |
|
| 74 | - } |
|
| 73 | + return $parts[0].'/'.$parts[1].'/'; |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | $datePath = $this->migrator->getDateFolderStructure($migration_name); |
| 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 | |
@@ -8,84 +8,84 @@ |
||
| 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 Migrator |
|
| 29 | - */ |
|
| 30 | - protected $migrator; |
|
| 25 | + /** |
|
| 26 | + * The migrator instance. |
|
| 27 | + * |
|
| 28 | + * @var Migrator |
|
| 29 | + */ |
|
| 30 | + protected $migrator; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The filesystem instance. |
|
| 34 | - * |
|
| 35 | - * @var Filesystem |
|
| 36 | - */ |
|
| 37 | - protected $files; |
|
| 32 | + /** |
|
| 33 | + * The filesystem instance. |
|
| 34 | + * |
|
| 35 | + * @var Filesystem |
|
| 36 | + */ |
|
| 37 | + protected $files; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Create a new migrator instance. |
|
| 41 | - * |
|
| 42 | - * @param Filesystem $files |
|
| 43 | - * @param 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 Filesystem $files |
|
| 43 | + * @param 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 | - * Fire the command. (Compatibility for < 5.5). |
|
| 54 | - */ |
|
| 55 | - public function fire() |
|
| 56 | - { |
|
| 57 | - $this->handle(); |
|
| 58 | - } |
|
| 52 | + /** |
|
| 53 | + * Fire the command. (Compatibility for < 5.5). |
|
| 54 | + */ |
|
| 55 | + public function fire() |
|
| 56 | + { |
|
| 57 | + $this->handle(); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Create date folder structure and move migrations into. |
|
| 62 | - * |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - public function handle() |
|
| 66 | - { |
|
| 67 | - $basePath = $this->getMigrationPath(); |
|
| 68 | - $migrations = $this->migrator->getMigrationFiles($basePath, false); |
|
| 69 | - $count = count($migrations); |
|
| 60 | + /** |
|
| 61 | + * Create date folder structure and move migrations into. |
|
| 62 | + * |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + public function handle() |
|
| 66 | + { |
|
| 67 | + $basePath = $this->getMigrationPath(); |
|
| 68 | + $migrations = $this->migrator->getMigrationFiles($basePath, false); |
|
| 69 | + $count = count($migrations); |
|
| 70 | 70 | |
| 71 | - if ($count == 0) { |
|
| 72 | - $this->comment('No migrations to move'); |
|
| 71 | + if ($count == 0) { |
|
| 72 | + $this->comment('No migrations to move'); |
|
| 73 | 73 | |
| 74 | - return; |
|
| 75 | - } |
|
| 74 | + return; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - foreach ($migrations as $migration_name => $migration_path) { |
|
| 78 | - $datePath = $this->migrator->getDateFolderStructure($migration_name); |
|
| 77 | + foreach ($migrations as $migration_name => $migration_path) { |
|
| 78 | + $datePath = $this->migrator->getDateFolderStructure($migration_name); |
|
| 79 | 79 | |
| 80 | - // Create folder if it does not already exist |
|
| 81 | - if (! $this->files->exists($basePath.'/'.$datePath)) { |
|
| 82 | - $this->files->makeDirectory($basePath.'/'.$datePath, 0775, true); |
|
| 83 | - } |
|
| 80 | + // Create folder if it does not already exist |
|
| 81 | + if (! $this->files->exists($basePath.'/'.$datePath)) { |
|
| 82 | + $this->files->makeDirectory($basePath.'/'.$datePath, 0775, true); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // Move the migration into its new folder |
|
| 86 | - $this->files->move($basePath.'/'.$migration_name.'.php', $basePath.'/'.$datePath.$migration_name.'.php'); |
|
| 87 | - } |
|
| 85 | + // Move the migration into its new folder |
|
| 86 | + $this->files->move($basePath.'/'.$migration_name.'.php', $basePath.'/'.$datePath.$migration_name.'.php'); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - $this->info('Migrations organised successfully ('.$count.' migrations moved)'); |
|
| 90 | - } |
|
| 89 | + $this->info('Migrations organised successfully ('.$count.' migrations moved)'); |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -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'], $app->path('stubs')); |
|
| 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'], $app->path('stubs')); |
|
| 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'], $app->path('stubs')); |
| 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 | } |
@@ -7,30 +7,30 @@ |
||
| 7 | 7 | |
| 8 | 8 | class MigrationCreator extends MC |
| 9 | 9 | { |
| 10 | - protected function ensureMigrationDoesntAlreadyExist($name, $migrationPath = null) |
|
| 11 | - { |
|
| 12 | - if (! empty($migrationPath)) { |
|
| 13 | - $migrationPath = $migrationPath.'/'.date('Y').'/'.date('m'); |
|
| 14 | - $migrationFiles = $this->files->glob($migrationPath.'/*.php'); |
|
| 15 | - |
|
| 16 | - foreach ($migrationFiles as $migrationFile) { |
|
| 17 | - $this->files->requireOnce($migrationFile); |
|
| 18 | - } |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - if (class_exists($className = $this->getClassName($name))) { |
|
| 22 | - throw new InvalidArgumentException("A {$className} class already exists."); |
|
| 23 | - } |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - protected function getPath($name, $path) |
|
| 27 | - { |
|
| 28 | - $path = $path.'/'.date('Y').'/'.date('m'); |
|
| 29 | - |
|
| 30 | - if (! $this->files->exists($path)) { |
|
| 31 | - $this->files->makeDirectory($path, 0775, true); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - return $path.'/'.$this->getDatePrefix().'_'.$name.'.php'; |
|
| 35 | - } |
|
| 10 | + protected function ensureMigrationDoesntAlreadyExist($name, $migrationPath = null) |
|
| 11 | + { |
|
| 12 | + if (! empty($migrationPath)) { |
|
| 13 | + $migrationPath = $migrationPath.'/'.date('Y').'/'.date('m'); |
|
| 14 | + $migrationFiles = $this->files->glob($migrationPath.'/*.php'); |
|
| 15 | + |
|
| 16 | + foreach ($migrationFiles as $migrationFile) { |
|
| 17 | + $this->files->requireOnce($migrationFile); |
|
| 18 | + } |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + if (class_exists($className = $this->getClassName($name))) { |
|
| 22 | + throw new InvalidArgumentException("A {$className} class already exists."); |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + protected function getPath($name, $path) |
|
| 27 | + { |
|
| 28 | + $path = $path.'/'.date('Y').'/'.date('m'); |
|
| 29 | + |
|
| 30 | + if (! $this->files->exists($path)) { |
|
| 31 | + $this->files->makeDirectory($path, 0775, true); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + return $path.'/'.$this->getDatePrefix().'_'.$name.'.php'; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | { |
| 10 | 10 | protected function ensureMigrationDoesntAlreadyExist($name, $migrationPath = null) |
| 11 | 11 | { |
| 12 | - if (! empty($migrationPath)) { |
|
| 12 | + if ( ! empty($migrationPath)) { |
|
| 13 | 13 | $migrationPath = $migrationPath.'/'.date('Y').'/'.date('m'); |
| 14 | 14 | $migrationFiles = $this->files->glob($migrationPath.'/*.php'); |
| 15 | 15 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | { |
| 28 | 28 | $path = $path.'/'.date('Y').'/'.date('m'); |
| 29 | 29 | |
| 30 | - if (! $this->files->exists($path)) { |
|
| 30 | + if ( ! $this->files->exists($path)) { |
|
| 31 | 31 | $this->files->makeDirectory($path, 0775, true); |
| 32 | 32 | } |
| 33 | 33 | |
@@ -9,126 +9,126 @@ |
||
| 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 Migrator |
|
| 30 | - */ |
|
| 31 | - protected $migrator; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * The filesystem instance. |
|
| 35 | - * |
|
| 36 | - * @var 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 Filesystem $files |
|
| 49 | - * @param 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 | - * Fire the command. (Compatibility for < 5.5). |
|
| 60 | - */ |
|
| 61 | - public function fire() |
|
| 62 | - { |
|
| 63 | - $this->handle(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Create date folder structure and move migrations into. |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function handle() |
|
| 72 | - { |
|
| 73 | - $this->basePath = $this->getMigrationPath(); |
|
| 74 | - $migrations = $this->migrator->getMigrationFiles($this->basePath); |
|
| 75 | - $count = count($migrations); |
|
| 76 | - |
|
| 77 | - if ($count == 0) { |
|
| 78 | - $this->comment('No migrations to move'); |
|
| 79 | - |
|
| 80 | - return; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - foreach ($migrations as $migration_name => $migration_path) { |
|
| 84 | - $datePath = $this->migrator->getDateFolderStructure($migration_name); |
|
| 85 | - // Move the migration into base migration folder |
|
| 86 | - $this->files->move($this->basePath.'/'.$datePath.$migration_name.'.php', $this->basePath.'/'.$migration_name.'.php'); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $this->info('Migrations disorganised successfully ('.$count.' migrations moved)'); |
|
| 90 | - $this->cleanup(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Decide whether or not to delete directories. |
|
| 95 | - * |
|
| 96 | - * @return void |
|
| 97 | - */ |
|
| 98 | - public function cleanup() |
|
| 99 | - { |
|
| 100 | - if ($this->option('force')) { |
|
| 101 | - $this->deleteDirs(); |
|
| 102 | - } elseif ($this->confirm('Delete all subdirectories in migrations folder?', true)) { |
|
| 103 | - $this->deleteDirs(); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Delete subdirectories in the migrations folder. |
|
| 109 | - * |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - public function deleteDirs() |
|
| 113 | - { |
|
| 114 | - $dirs = $this->files->directories($this->basePath); |
|
| 115 | - |
|
| 116 | - foreach ($dirs as $dir) { |
|
| 117 | - $this->files->deleteDirectory($dir); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $this->info('Subdirectories deleted'); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get the console command options. |
|
| 125 | - * |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - protected function getOptions() |
|
| 129 | - { |
|
| 130 | - return [ |
|
| 131 | - ['force', null, InputOption::VALUE_NONE, 'Force the operation to delete migration folder subdirectories without prompt.'], |
|
| 132 | - ]; |
|
| 133 | - } |
|
| 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 Migrator |
|
| 30 | + */ |
|
| 31 | + protected $migrator; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * The filesystem instance. |
|
| 35 | + * |
|
| 36 | + * @var 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 Filesystem $files |
|
| 49 | + * @param 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 | + * Fire the command. (Compatibility for < 5.5). |
|
| 60 | + */ |
|
| 61 | + public function fire() |
|
| 62 | + { |
|
| 63 | + $this->handle(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Create date folder structure and move migrations into. |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function handle() |
|
| 72 | + { |
|
| 73 | + $this->basePath = $this->getMigrationPath(); |
|
| 74 | + $migrations = $this->migrator->getMigrationFiles($this->basePath); |
|
| 75 | + $count = count($migrations); |
|
| 76 | + |
|
| 77 | + if ($count == 0) { |
|
| 78 | + $this->comment('No migrations to move'); |
|
| 79 | + |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + foreach ($migrations as $migration_name => $migration_path) { |
|
| 84 | + $datePath = $this->migrator->getDateFolderStructure($migration_name); |
|
| 85 | + // Move the migration into base migration folder |
|
| 86 | + $this->files->move($this->basePath.'/'.$datePath.$migration_name.'.php', $this->basePath.'/'.$migration_name.'.php'); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $this->info('Migrations disorganised successfully ('.$count.' migrations moved)'); |
|
| 90 | + $this->cleanup(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Decide whether or not to delete directories. |
|
| 95 | + * |
|
| 96 | + * @return void |
|
| 97 | + */ |
|
| 98 | + public function cleanup() |
|
| 99 | + { |
|
| 100 | + if ($this->option('force')) { |
|
| 101 | + $this->deleteDirs(); |
|
| 102 | + } elseif ($this->confirm('Delete all subdirectories in migrations folder?', true)) { |
|
| 103 | + $this->deleteDirs(); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Delete subdirectories in the migrations folder. |
|
| 109 | + * |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + public function deleteDirs() |
|
| 113 | + { |
|
| 114 | + $dirs = $this->files->directories($this->basePath); |
|
| 115 | + |
|
| 116 | + foreach ($dirs as $dir) { |
|
| 117 | + $this->files->deleteDirectory($dir); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $this->info('Subdirectories deleted'); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get the console command options. |
|
| 125 | + * |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + protected function getOptions() |
|
| 129 | + { |
|
| 130 | + return [ |
|
| 131 | + ['force', null, InputOption::VALUE_NONE, 'Force the operation to delete migration folder subdirectories without prompt.'], |
|
| 132 | + ]; |
|
| 133 | + } |
|
| 134 | 134 | } |