1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Elimuswift\DbExporter; |
4
|
|
|
|
5
|
|
|
class DbExportHandler |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var DbMigrations |
9
|
|
|
*/ |
10
|
|
|
protected $migrator; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var DbSeeding |
14
|
|
|
*/ |
15
|
|
|
protected $seeder; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Inject the DbMigrations class. |
19
|
|
|
* |
20
|
|
|
* @param DbMigrations $DbMigrations |
21
|
|
|
* @param DbSeeding $DbSeeding |
22
|
|
|
*/ |
23
|
|
|
public function __construct(DbMigrations $DbMigrations, DbSeeding $DbSeeding) |
24
|
|
|
{ |
25
|
|
|
$this->migrator = $DbMigrations; |
26
|
|
|
$this->seeder = $DbSeeding; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
//end __construct() |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Create migrations from the given DB. |
33
|
|
|
* |
34
|
|
|
* @param string null $database |
35
|
|
|
* |
36
|
|
|
* @return $this |
37
|
|
|
*/ |
38
|
|
|
public function migrate($database = null) |
39
|
|
|
{ |
40
|
|
|
$this->migrator->convert($database)->write(); |
41
|
|
|
|
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
//end migrate() |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param null $database |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function seed($database = null) |
53
|
|
|
{ |
54
|
|
|
$this->seeder->convert($database)->write(); |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
//end seed() |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Helper function to generate the migration and the seed in one command. |
63
|
|
|
* |
64
|
|
|
* @param null $database |
65
|
|
|
* |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
|
|
public function migrateAndSeed($database = null) |
69
|
|
|
{ |
70
|
|
|
// Run the migrator generator |
71
|
|
|
$this->migrator->convert($database)->write(); |
72
|
|
|
|
73
|
|
|
// Run the seeder generator |
74
|
|
|
$this->seeder->convert($database)->write(); |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
//end migrateAndSeed() |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Add tables to the ignore array. |
83
|
|
|
* |
84
|
|
|
* @param $tables |
85
|
|
|
* |
86
|
|
|
* @return $this |
87
|
|
|
*/ |
88
|
|
|
public function ignore(...$tables) |
89
|
|
|
{ |
90
|
|
|
DbExporter::$ignore = array_merge(DbExporter::$ignore, (array)$tables); |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
//end ignore() |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return mixed |
99
|
|
|
*/ |
100
|
|
|
public function getMigrationsFilePath() |
101
|
|
|
{ |
102
|
|
|
return DbMigrations::$filePath; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
//end getMigrationsFilePath() |
106
|
|
|
|
107
|
|
|
public function uploadTo($remote) |
108
|
|
|
{ |
109
|
|
|
DbExporter::$remote = $remote; |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
//end uploadTo() |
115
|
|
|
}//end class |
116
|
|
|
|