@@ -94,6 +94,9 @@ |
||
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | + /** |
|
98 | + * @param string $what |
|
99 | + */ |
|
97 | 100 | private function upload($what) |
98 | 101 | { |
99 | 102 | $localPath = "{$what}Path"; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | protected $name = 'db-exporter:remote'; |
14 | 14 | protected $description = 'Command to copy the migrations and/or the seeds to a remote host.'; |
15 | 15 | |
16 | - protected $ignoredFiles = array('..', '.', '.gitkeep'); |
|
16 | + protected $ignoredFiles = array('..', '.', '.gitkeep'); |
|
17 | 17 | |
18 | 18 | protected $migrationsPath; |
19 | 19 | protected $seedsPath; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | foreach ($this->uploadedFiles as $type => $files) { |
42 | 42 | $this->info(ucfirst($type)); |
43 | 43 | foreach ($files as $file) { |
44 | - $this->sectionMessage($type, $file .' uploaded.'); |
|
44 | + $this->sectionMessage($type, $file . ' uploaded.'); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | $localPath = "{$what}Path"; |
100 | 100 | |
101 | 101 | $dir = scandir($this->$localPath); |
102 | - $remotePath = Config::get('db-exporter.remote.'.$what); |
|
102 | + $remotePath = Config::get('db-exporter.remote.' . $what); |
|
103 | 103 | |
104 | 104 | // Prepare the progress bar |
105 | 105 | $progress = $this->getHelperSet()->get('progress'); |
106 | 106 | $filesCount = count($dir) - count($this->ignoredFiles); |
107 | 107 | $progress->start($this->output, $filesCount); |
108 | 108 | $this->info(ucfirst($what)); |
109 | - foreach($dir as $file) { |
|
109 | + foreach ($dir as $file) { |
|
110 | 110 | if (in_array($file, $this->ignoredFiles)) { |
111 | 111 | continue; |
112 | 112 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | // Copy the files |
118 | 118 | SSH::into($this->getRemoteName())->put( |
119 | - $this->$localPath .'/' . $file, |
|
119 | + $this->$localPath . '/' . $file, |
|
120 | 120 | $remotePath . $file |
121 | 121 | ); |
122 | 122 | $progress->advance(); |
@@ -79,7 +79,9 @@ |
||
79 | 79 | $options = $this->option(); |
80 | 80 | switch ($options) { |
81 | 81 | case (($options['seeds'] === true) && ($options['migrations'] === true)): |
82 | - if (!$this->upload('migrations')) return false; |
|
82 | + if (!$this->upload('migrations')) { |
|
83 | + return false; |
|
84 | + } |
|
83 | 85 | return $this->upload('seeds'); |
84 | 86 | break; |
85 | 87 | case $options['migrations'] === true: |
@@ -76,7 +76,7 @@ |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * @return mixed |
|
79 | + * @return string |
|
80 | 80 | */ |
81 | 81 | public function getMigrationsFilePath() |
82 | 82 | { |
@@ -1,8 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Elimuswift\DbExporter; |
3 | 3 | |
4 | -use Config, DB; |
|
5 | -use Illuminate\Support\Str, File; |
|
4 | +use Config; |
|
5 | +use DB; |
|
6 | +use Illuminate\Support\Str; |
|
7 | +use File; |
|
6 | 8 | |
7 | 9 | class DbSeeding extends DbExporter |
8 | 10 | { |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | $filename = Str::camel($this->database) . "TableSeeder"; |
47 | 47 | |
48 | - file_put_contents(Config::get('db-exporter.export_path.seeds')."/{$filename}.php", $seed); |
|
48 | + file_put_contents(Config::get('db-exporter.export_path.seeds') . "/{$filename}.php", $seed); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $value = addslashes($value); |
124 | 124 | if (is_numeric($value)) { |
125 | 125 | return " '{$prop}' => {$value},\n"; |
126 | - } elseif($value == '') { |
|
126 | + } elseif ($value == '') { |
|
127 | 127 | return " '{$prop}' => NULL,\n"; |
128 | 128 | } else { |
129 | 129 | return " '{$prop}' => '{$value}',\n"; |
@@ -15,7 +15,7 @@ |
||
15 | 15 | protected function getDatabaseName() |
16 | 16 | { |
17 | 17 | $connType = Config::get('database.default'); |
18 | - $database = Config::get('database.connections.' .$connType ); |
|
18 | + $database = Config::get('database.connections.' . $connType); |
|
19 | 19 | |
20 | 20 | return $database['database']; |
21 | 21 | } |
@@ -63,7 +63,7 @@ |
||
63 | 63 | private function getFilename() |
64 | 64 | { |
65 | 65 | $filename = Str::camel($this->getDatabaseName()) . "TableSeeder"; |
66 | - return Config::get('db-exporter.export_path.seeds')."/{$filename}.php"; |
|
66 | + return Config::get('db-exporter.export_path.seeds') . "/{$filename}.php"; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | |
178 | 178 | $tableIndexes = $this->getTableIndexes($value['table_name']); |
179 | 179 | if (!is_null($tableIndexes) && count($tableIndexes)){ |
180 | - foreach ($tableIndexes as $index) { |
|
180 | + foreach ($tableIndexes as $index) { |
|
181 | 181 | if(Str::endsWith($index['Key_name'], '_index')) |
182 | - $up .= ' $' . "table->index('" . $index['Key_name'] . "');\n"; |
|
182 | + $up .= ' $' . "table->index('" . $index['Key_name'] . "');\n"; |
|
183 | 183 | } |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | 186 | $up .= " });\n\n"; |
187 | 187 | $Constraint = $ConstraintDown = ""; |
@@ -225,24 +225,24 @@ discard block |
||
225 | 225 | |
226 | 226 | // prevent of failure when no table |
227 | 227 | if (!is_null($this->schema) && count($this->schema)) { |
228 | - foreach ($this->schema as $name => $values) { |
|
229 | - // check again for ignored tables |
|
230 | - if (in_array($name, self::$ignore)) { |
|
231 | - continue; |
|
232 | - } |
|
233 | - $upSchema .= " |
|
228 | + foreach ($this->schema as $name => $values) { |
|
229 | + // check again for ignored tables |
|
230 | + if (in_array($name, self::$ignore)) { |
|
231 | + continue; |
|
232 | + } |
|
233 | + $upSchema .= " |
|
234 | 234 | /** |
235 | 235 | * Table: {$name} |
236 | 236 | */ |
237 | 237 | {$values['up']}"; |
238 | 238 | $upConstraint.=" |
239 | 239 | {$values['constraint']}"; |
240 | - $downConstraint.=" |
|
240 | + $downConstraint.=" |
|
241 | 241 | {$values['constraint_down']}"; |
242 | 242 | |
243 | - $downSchema .= " |
|
243 | + $downSchema .= " |
|
244 | 244 | {$values['down']}"; |
245 | - } |
|
245 | + } |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | // Grab the template |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | $schema = $this->compile(); |
64 | 64 | $filename = date('Y_m_d_His') . "_create_" . $this->database . "_database.php"; |
65 | - static::$filePath = Config::get('db-exporter.export_path.migrations')."{$filename}"; |
|
65 | + static::$filePath = Config::get('db-exporter.export_path.migrations') . "{$filename}"; |
|
66 | 66 | |
67 | 67 | file_put_contents(static::$filePath, $schema); |
68 | 68 | |
@@ -176,9 +176,9 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | $tableIndexes = $this->getTableIndexes($value['table_name']); |
179 | - if (!is_null($tableIndexes) && count($tableIndexes)){ |
|
179 | + if (!is_null($tableIndexes) && count($tableIndexes)) { |
|
180 | 180 | foreach ($tableIndexes as $index) { |
181 | - if(Str::endsWith($index['Key_name'], '_index')) |
|
181 | + if (Str::endsWith($index['Key_name'], '_index')) |
|
182 | 182 | $up .= ' $' . "table->index('" . $index['Key_name'] . "');\n"; |
183 | 183 | } |
184 | 184 | } |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | $up .= " });\n\n"; |
187 | 187 | $Constraint = $ConstraintDown = ""; |
188 | 188 | $tableConstraints = $this->getTableConstraints($value['table_name']); |
189 | - if (!is_null($tableConstraints) && count($tableConstraints)){ |
|
189 | + if (!is_null($tableConstraints) && count($tableConstraints)) { |
|
190 | 190 | $Constraint = $ConstraintDown = " |
191 | 191 | Schema::table('{$value['table_name']}', function(Blueprint $" . "table) {\n"; |
192 | 192 | $tables = []; |
193 | 193 | foreach ($tableConstraints as $foreign) { |
194 | - if(!in_array($foreign->Field, $tables)){ |
|
195 | - $ConstraintDown .= ' $' . "table->dropForeign('" . $foreign->Field. "');\n"; |
|
196 | - $Constraint .= ' $' . "table->foreign('" . $foreign->Field. "')->references('" . $foreign->References . "')->on('" . $foreign->ON. "')->onDelete('" . $foreign->onDelete. "');\n"; |
|
194 | + if (!in_array($foreign->Field, $tables)) { |
|
195 | + $ConstraintDown .= ' $' . "table->dropForeign('" . $foreign->Field . "');\n"; |
|
196 | + $Constraint .= ' $' . "table->foreign('" . $foreign->Field . "')->references('" . $foreign->References . "')->on('" . $foreign->ON . "')->onDelete('" . $foreign->onDelete . "');\n"; |
|
197 | 197 | $tables[$foreign->Field] = $foreign->Field; |
198 | 198 | } |
199 | 199 | } |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | * Table: {$name} |
236 | 236 | */ |
237 | 237 | {$values['up']}"; |
238 | - $upConstraint.=" |
|
238 | + $upConstraint .= " |
|
239 | 239 | {$values['constraint']}"; |
240 | - $downConstraint.=" |
|
240 | + $downConstraint .= " |
|
241 | 241 | {$values['constraint_down']}"; |
242 | 242 | |
243 | 243 | $downSchema .= " |
@@ -178,8 +178,9 @@ |
||
178 | 178 | $tableIndexes = $this->getTableIndexes($value['table_name']); |
179 | 179 | if (!is_null($tableIndexes) && count($tableIndexes)){ |
180 | 180 | foreach ($tableIndexes as $index) { |
181 | - if(Str::endsWith($index['Key_name'], '_index')) |
|
182 | - $up .= ' $' . "table->index('" . $index['Key_name'] . "');\n"; |
|
181 | + if(Str::endsWith($index['Key_name'], '_index')) { |
|
182 | + $up .= ' $' . "table->index('" . $index['Key_name'] . "');\n"; |
|
183 | + } |
|
183 | 184 | } |
184 | 185 | } |
185 | 186 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | public function register() |
31 | 31 | { |
32 | - $this->publishes([ |
|
32 | + $this->publishes([ |
|
33 | 33 | realpath(__DIR__ .'/../').'/config/db-exporter.php' => config_path('db-exporter.php'), |
34 | 34 | ]); |
35 | 35 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | realpath(__DIR__ .'/../').'/config/db-exporter.php', 'db-exporter' |
38 | 38 | ); |
39 | 39 | |
40 | - $this->app->register(DbMigrationsServiceProvider::class); |
|
40 | + $this->app->register(DbMigrationsServiceProvider::class); |
|
41 | 41 | |
42 | 42 | // Load the classes |
43 | 43 | $this->loadClasses(); |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | public function register() |
31 | 31 | { |
32 | 32 | $this->publishes([ |
33 | - realpath(__DIR__ .'/../').'/config/db-exporter.php' => config_path('db-exporter.php'), |
|
33 | + realpath(__DIR__ . '/../') . '/config/db-exporter.php' => config_path('db-exporter.php'), |
|
34 | 34 | ]); |
35 | 35 | |
36 | 36 | $this->mergeConfigFrom( |
37 | - realpath(__DIR__ .'/../').'/config/db-exporter.php', 'db-exporter' |
|
37 | + realpath(__DIR__ . '/../') . '/config/db-exporter.php', 'db-exporter' |
|
38 | 38 | ); |
39 | 39 | |
40 | 40 | $this->app->register(DbMigrationsServiceProvider::class); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | private function getDatabaseName() |
75 | 75 | { |
76 | 76 | $connType = Config::get('database.default'); |
77 | - $database = Config::get('database.connections.' .$connType ); |
|
77 | + $database = Config::get('database.connections.' . $connType); |
|
78 | 78 | |
79 | 79 | return $database['database']; |
80 | 80 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | $dir = scandir($localPath); |
23 | 23 | $remotePath = Config::get('db-exporter.remote.' . $what); |
24 | 24 | |
25 | - foreach($dir as $file) { |
|
25 | + foreach ($dir as $file) { |
|
26 | 26 | if (in_array($file, $this->ignoredFiles)) { |
27 | 27 | continue; |
28 | 28 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | // Copy the files |
34 | 34 | SSH::into($this->getRemoteName())->put( |
35 | - $localPath .'/' . $file, |
|
35 | + $localPath . '/' . $file, |
|
36 | 36 | $remotePath . $file |
37 | 37 | ); |
38 | 38 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | $this->app->singleton('DbMigrations', function() |
35 | 35 | { |
36 | 36 | $connType = Config::get('database.default'); |
37 | - $database = Config::get('database.connections.' .$connType ); |
|
37 | + $database = Config::get('database.connections.' . $connType); |
|
38 | 38 | return new DbMigrations($database); |
39 | 39 | }); |
40 | 40 |