-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrations.php
96 lines (88 loc) · 3.06 KB
/
migrations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
*
* Automatical migration from modules
*
* @author Dmitrij Waśkowski <[email protected]>
*
*/
/**
* Path to application
*/
$application_path = $application_path_seeds = realpath(__DIR__.'/app');
/**
* Create Laravel application
*/
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
$app->boot();
$command_m = !empty($argv[1]) ? $argv[1] : '';
$path_artisan = 'app';
echo "Start automatical migration\n";
echo "---------------------------\n";
/**
* Function for automatical migrate
*/
if(empty($command_m) || $command_m=='all'){
function searchMigrationDir($path,&$path_artisan) {
if($handle = opendir($path)){
while (false !== ($entry = readdir($handle))) {
$full_path = realpath($path."/".$entry);
if($entry!='.' && $entry!='..' && is_dir($full_path)){
$this_path_artisan = $path_artisan."/".$entry;
if($entry=='migrations'){
echo "run Artisan migrate -path=".$path_artisan."/migrations\n";
Artisan::call('migrate', array('--path' => $path_artisan.'/migrations'));
}else{
searchMigrationDir($full_path,$this_path_artisan);
}
}
}
}
}
searchMigrationDir($application_path,$path_artisan);
}
/**
* Function for automatical seeds
*/
if(!empty($command_m) && ($command_m=='all' || $command_m=='seeds')){
function searchSeedsDir($path) {
if($handle = opendir($path)){
while (false !== ($entry = readdir($handle))) {
$full_path = realpath($path."/".$entry);
if($entry!='.' && $entry!='..' && is_dir($full_path)){
if($entry=='seeds'){
if($handle = opendir($full_path)){
while (false !== ($entry = readdir($handle))) {
$seed_path = realpath($path."/".$entry);
if($entry!='.' && $entry!='..' && !is_dir($seed_path) && preg_match('/Seeder/', $entry)){
$seed = preg_replace('/\.php/', '', $entry);
echo "run Artisan db:seed -=class=".$seed."\n";
Artisan::call('db:seed', array('--class' => $seed));
}
}
}
}else{
searchSeedsDir($full_path);
}
}
}
}
}
echo "Run Artisan modules:scan\n";
Artisan::call('modules:scan');
searchSeedsDir($application_path_seeds);
}
/**
* Function for refresh application
*/
if(!empty($command_m) && $command_m=='a'){
echo "Run Artisan modules:scan\n";
Artisan::call('modules:scan');
echo "Run Artisan dump-autoload\n";
Artisan::call('dump-autoload');
}
/**
* Distroy Laravel application
*/
$app->shutdown();