| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | /** | 
| 19 | 19 | * Get all of the migration files in a given path. | 
| 20 | 20 | * | 
| 21 | - * @param string $path | |
| 21 | + * @param string $paths | |
| 22 | 22 | * @param bool $recursive | 
| 23 | 23 | * | 
| 24 | 24 | * @return array | 
| @@ -9,68 +9,68 @@ | ||
| 9 | 9 | class Migrator extends M | 
| 10 | 10 |  { | 
| 11 | 11 | |
| 12 | - /** | |
| 13 | - * Get all of the migration files in a given path. | |
| 14 | - * | |
| 15 | - * @param string $path | |
| 16 | - * @param bool $recursive | |
| 17 | - * | |
| 18 | - * @return array | |
| 19 | - */ | |
| 20 | - public function getMigrationFiles($paths = [], $recursive = true) | |
| 21 | -    { | |
| 22 | -        if ($recursive) { | |
| 23 | - $paths = $this->getRecursiveFolders($paths); | |
| 24 | - } | |
| 12 | + /** | |
| 13 | + * Get all of the migration files in a given path. | |
| 14 | + * | |
| 15 | + * @param string $path | |
| 16 | + * @param bool $recursive | |
| 17 | + * | |
| 18 | + * @return array | |
| 19 | + */ | |
| 20 | + public function getMigrationFiles($paths = [], $recursive = true) | |
| 21 | +	{ | |
| 22 | +		if ($recursive) { | |
| 23 | + $paths = $this->getRecursiveFolders($paths); | |
| 24 | + } | |
| 25 | 25 | |
| 26 | - $files = parent::getMigrationFiles($paths); | |
| 26 | + $files = parent::getMigrationFiles($paths); | |
| 27 | 27 | |
| 28 | - return $files; | |
| 29 | - } | |
| 28 | + return $files; | |
| 29 | + } | |
| 30 | 30 | |
| 31 | - /** | |
| 32 | - * Get all subdirectories located in an array of folders | |
| 33 | - * | |
| 34 | - * @param array $folders | |
| 35 | - * | |
| 36 | - * @return array | |
| 37 | - */ | |
| 38 | - public function getRecursiveFolders($folders) | |
| 39 | -    { | |
| 31 | + /** | |
| 32 | + * Get all subdirectories located in an array of folders | |
| 33 | + * | |
| 34 | + * @param array $folders | |
| 35 | + * | |
| 36 | + * @return array | |
| 37 | + */ | |
| 38 | + public function getRecursiveFolders($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 = array($folder); | |
| 51 | -            foreach ($iter as $path => $dir) { | |
| 52 | -                if ($dir->isDir()) { | |
| 53 | - $subPaths[] = $path; | |
| 54 | - } | |
| 55 | - } | |
| 50 | + $subPaths = array($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 | - * | |
| 68 | - * @return string | |
| 69 | - */ | |
| 70 | - public function getDateFolderStructure($file) | |
| 71 | -    { | |
| 72 | -        $parts = explode('_', $file); | |
| 63 | + /** | |
| 64 | + * Add date folders to migrations path. | |
| 65 | + * | |
| 66 | + * @param string $file | |
| 67 | + * | |
| 68 | + * @return string | |
| 69 | + */ | |
| 70 | + public function getDateFolderStructure($file) | |
| 71 | +	{ | |
| 72 | +		$parts = explode('_', $file); | |
| 73 | 73 | |
| 74 | - return $parts[0].'/'.$parts[1].'/'; | |
| 75 | - } | |
| 74 | + return $parts[0].'/'.$parts[1].'/'; | |
| 75 | + } | |
| 76 | 76 | } | 
| @@ -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_name => $migration_path) { | |
| 70 | - $datePath = $this->migrator->getDateFolderStructure($migration_name); | |
| 69 | +		foreach ($migrations as $migration_name => $migration_path) { | |
| 70 | + $datePath = $this->migrator->getDateFolderStructure($migration_name); | |
| 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_name.'.php', $basePath.'/'.$datePath.$migration_name.'.php'); | |
| 79 | - } | |
| 77 | + // Move the migration into its new folder | |
| 78 | + $this->files->move($basePath.'/'.$migration_name.'.php', $basePath.'/'.$datePath.$migration_name.'.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 | } | 
| @@ -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_name => $migration_path) { | |
| 76 | - $datePath = $this->migrator->getDateFolderStructure($migration_name); | |
| 77 | - // Move the migration into base migration folder | |
| 78 | - $this->files->move($this->basePath.'/'.$datePath.$migration_name.'.php', $this->basePath.'/'.$migration_name.'.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_name => $migration_path) { | |
| 76 | + $datePath = $this->migrator->getDateFolderStructure($migration_name); | |
| 77 | + // Move the migration into base migration folder | |
| 78 | + $this->files->move($this->basePath.'/'.$datePath.$migration_name.'.php', $this->basePath.'/'.$migration_name.'.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 | } |