1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jaybizzle\MigrationsOrganiser\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Filesystem\Filesystem; |
6
|
|
|
use Jaybizzle\MigrationsOrganiser\Migrator; |
7
|
|
|
use Illuminate\Database\Console\Migrations\BaseCommand; |
8
|
|
|
|
9
|
|
|
class MigrateOrganise extends BaseCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The console command name. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'migrate:organise'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Move migrations into a yyyy/mm folder structure'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The migrator instance. |
27
|
|
|
* |
28
|
|
|
* @var \Jaybizzle\MigrationsOrganiser\Migrator |
29
|
|
|
*/ |
30
|
|
|
protected $migrator; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The filesystem instance. |
34
|
|
|
* |
35
|
|
|
* @var \Illuminate\Filesystem\Filesystem |
36
|
|
|
*/ |
37
|
|
|
protected $files; |
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
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Fire the command. (Compatibility for < 5.5). |
54
|
|
|
*/ |
55
|
|
|
public function fire() |
56
|
|
|
{ |
57
|
|
|
$this->handle(); |
58
|
|
|
} |
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); |
70
|
|
|
|
71
|
|
|
if ($count == 0) { |
72
|
|
|
$this->comment('No migrations to move'); |
73
|
|
|
|
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
foreach ($migrations as $migration_name => $migration_path) { |
78
|
|
|
$datePath = $this->migrator->getDateFolderStructure($migration_name); |
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
|
|
|
} |
84
|
|
|
|
85
|
|
|
// Move the migration into its new folder |
86
|
|
|
$this->files->move($basePath.'/'.$migration_name.'.php', $basePath.'/'.$datePath.$migration_name.'.php'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->info('Migrations organised successfully ('.$count.' migrations moved)'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: