1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Console\Migrations; |
6
|
|
|
|
7
|
|
|
use Illuminate\Console\ConfirmableTrait; |
8
|
|
|
use Illuminate\Database\Console\Migrations\BaseCommand; |
9
|
|
|
use Illuminate\Database\Migrations\Migrator; |
10
|
|
|
|
11
|
|
|
class MigrationsConvertCommand extends BaseCommand |
12
|
|
|
{ |
13
|
|
|
use ConfirmableTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The name and signature of the console command. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $signature = 'convert:migrations |
21
|
|
|
{--path= : The path to the migrations files to be converted} |
22
|
|
|
{--realpath : Indicate any provided migration file paths are pre-resolved absolute paths}'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The console command description. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Convert existing migrations to ArangoDB migrations'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The migrator instance. |
33
|
|
|
* |
34
|
|
|
* @var \Illuminate\Database\Migrations\Migrator |
35
|
|
|
*/ |
36
|
|
|
protected $migrator; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a new migration command instance. |
40
|
|
|
* |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function __construct(Migrator $migrator) |
45
|
|
|
{ |
46
|
|
|
parent::__construct(); |
47
|
|
|
|
48
|
|
|
$this->migrator = $migrator; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Execute the console command. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function handle() |
57
|
|
|
{ |
58
|
|
|
if (!$this->confirmToProceed()) { |
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$files = $this->migrator->getMigrationFiles($this->getMigrationPaths()); |
63
|
|
|
foreach ($files as $file) { |
64
|
|
|
$this->convertMigrationFile($file); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function convertMigrationFile(string $filePath): void |
69
|
|
|
{ |
70
|
|
|
$replacements = [ |
71
|
|
|
'Illuminate\Support\Facades\Schema' => 'LaravelFreelancerNL\Aranguent\Facades\Schema', |
72
|
|
|
'Illuminate\Database\Schema\Blueprint' => 'LaravelFreelancerNL\Aranguent\Schema\Blueprint', |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
$content = file_get_contents($filePath); |
76
|
|
|
|
77
|
|
|
if ($content !== false) { |
78
|
|
|
$content = str_replace(array_keys($replacements), $replacements, $content); |
79
|
|
|
file_put_contents($filePath, $content); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|