@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $this->line("\n"); |
37 | 37 | $this->info(ucfirst($type)); |
38 | 38 | foreach ($files as $file) { |
39 | - $this->sectionMessage($type, $file.' uploaded.'); |
|
39 | + $this->sectionMessage($type, $file . ' uploaded.'); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
@@ -80,19 +80,18 @@ discard block |
||
80 | 80 | |
81 | 81 | protected function upload($what) |
82 | 82 | { |
83 | - $localPath = Config::get('db-exporter.export_path.'.$what); |
|
83 | + $localPath = Config::get('db-exporter.export_path.' . $what); |
|
84 | 84 | $dir = scandir($localPath); |
85 | - $remotePath = Config::get('db-exporter.remote.'.$what); |
|
85 | + $remotePath = Config::get('db-exporter.remote.' . $what); |
|
86 | 86 | $this->line("\n"); |
87 | 87 | $this->info(ucfirst($what)); |
88 | 88 | // Reset file coounter |
89 | 89 | static::$filesCount = 0; |
90 | 90 | // Prepare the progress bar |
91 | - array_walk($dir, function ($file) { |
|
91 | + array_walk($dir, function($file) { |
|
92 | 92 | if ($this->ignoredFile($file)) { |
93 | 93 | return; |
94 | - } |
|
95 | - ++static::$filesCount; |
|
94 | + }++static::$filesCount; |
|
96 | 95 | }); |
97 | 96 | $progress = $this->output->createProgressBar(static::$filesCount); |
98 | 97 | foreach ($dir as $file) { |
@@ -102,12 +101,12 @@ discard block |
||
102 | 101 | } |
103 | 102 | |
104 | 103 | // Capture the uploaded files for displaying later |
105 | - $this->uploadedFiles[$what][] = $remotePath.$file; |
|
104 | + $this->uploadedFiles[$what][] = $remotePath . $file; |
|
106 | 105 | |
107 | 106 | // Copy the files |
108 | 107 | Storage::disk($this->getDiskName())->put( |
109 | - $remotePath.$file, |
|
110 | - $localPath.'/'.$file |
|
108 | + $remotePath . $file, |
|
109 | + $localPath . '/' . $file |
|
111 | 110 | ); |
112 | 111 | $progress->advance(); |
113 | 112 | } |
@@ -32,6 +32,9 @@ discard block |
||
32 | 32 | |
33 | 33 | //end getDatabaseName() |
34 | 34 | |
35 | + /** |
|
36 | + * @param string $title |
|
37 | + */ |
|
35 | 38 | protected function blockMessage($title, $message, $style = 'info') |
36 | 39 | { |
37 | 40 | // Symfony style block messages |
@@ -46,6 +49,9 @@ discard block |
||
46 | 49 | |
47 | 50 | //end blockMessage() |
48 | 51 | |
52 | + /** |
|
53 | + * @param string $message |
|
54 | + */ |
|
49 | 55 | protected function sectionMessage($title, $message) |
50 | 56 | { |
51 | 57 | $formatter = $this->getHelperSet()->get('formatter'); |
@@ -86,6 +92,9 @@ discard block |
||
86 | 92 | |
87 | 93 | //end getOptions() |
88 | 94 | |
95 | + /** |
|
96 | + * @param string $action |
|
97 | + */ |
|
89 | 98 | protected function fireAction($action, $database) |
90 | 99 | { |
91 | 100 | // Grab the options |
@@ -38,7 +38,7 @@ |
||
38 | 38 | $this->fireAction('migrate', $database); |
39 | 39 | |
40 | 40 | // Symfony style block messages |
41 | - $this->blockMessage('Success!', 'Database migrations generated in: '.$this->handler->getMigrationsFilePath()); |
|
41 | + $this->blockMessage('Success!', 'Database migrations generated in: ' . $this->handler->getMigrationsFilePath()); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | //end fire() |
@@ -53,9 +53,9 @@ |
||
53 | 53 | |
54 | 54 | private function getFilename() |
55 | 55 | { |
56 | - $filename = ucfirst(Str::camel($this->database)).'DatabaseSeeder'; |
|
56 | + $filename = ucfirst(Str::camel($this->database)) . 'DatabaseSeeder'; |
|
57 | 57 | |
58 | - return Config::get('db-exporter.export_path.seeds')."/{$filename}.php"; |
|
58 | + return Config::get('db-exporter.export_path.seeds') . "/{$filename}.php"; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | //end getFilename() |
@@ -27,17 +27,17 @@ |
||
27 | 27 | * @var array |
28 | 28 | **/ |
29 | 29 | protected $selects = [ |
30 | - 'column_name as Field', |
|
31 | - 'column_type as Type', |
|
32 | - 'is_nullable as Nullable', |
|
33 | - 'column_key as Key', |
|
34 | - 'column_default as Default', |
|
35 | - 'extra as Extra', |
|
36 | - 'data_type as Data_Type', |
|
37 | - 'CHARACTER_MAXIMUM_LENGTH as Length', |
|
38 | - 'NUMERIC_PRECISION as Precision', |
|
39 | - 'NUMERIC_SCALE as Scale', |
|
40 | - ]; |
|
30 | + 'column_name as Field', |
|
31 | + 'column_type as Type', |
|
32 | + 'is_nullable as Nullable', |
|
33 | + 'column_key as Key', |
|
34 | + 'column_default as Default', |
|
35 | + 'extra as Extra', |
|
36 | + 'data_type as Data_Type', |
|
37 | + 'CHARACTER_MAXIMUM_LENGTH as Length', |
|
38 | + 'NUMERIC_PRECISION as Precision', |
|
39 | + 'NUMERIC_SCALE as Scale', |
|
40 | + ]; |
|
41 | 41 | /** |
42 | 42 | * Select fields from constraints. |
43 | 43 | * |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | { |
57 | 57 | $pdo = DB::connection()->getPdo(); |
58 | 58 | |
59 | - return $pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema="'.$this->database.'"'); |
|
59 | + return $pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema="' . $this->database . '"'); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | public function getTableIndexes($table) |
63 | 63 | { |
64 | 64 | $pdo = DB::connection()->getPdo(); |
65 | 65 | |
66 | - return $pdo->query('SHOW INDEX FROM '.$this->database.'.'.$table.' WHERE Key_name != "PRIMARY"'); |
|
66 | + return $pdo->query('SHOW INDEX FROM ' . $this->database . '.' . $table . ' WHERE Key_name != "PRIMARY"'); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | protected function getTableData($table) |
109 | 109 | { |
110 | - return DB::table($this->database.'.'.$table)->get(); |
|
110 | + return DB::table($this->database . '.' . $table)->get(); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $directories = explode($del, $path); |
123 | 123 | foreach ($directories as $directory) { |
124 | 124 | if (!empty($directory)) { |
125 | - $dir .= $del.$directory; |
|
125 | + $dir .= $del . $directory; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | if (!is_dir($dir)) { |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $schema = $this->compile(); |
109 | 109 | $absolutePath = Config::get('db-exporter.export_path.migrations'); |
110 | 110 | $this->makePath($absolutePath); |
111 | - $this->filename = date('Y_m_d_His').'_create_'.$this->database.'_database.php'; |
|
112 | - static::$filePath = $absolutePath."/{$this->filename}"; |
|
111 | + $this->filename = date('Y_m_d_His') . '_create_' . $this->database . '_database.php'; |
|
112 | + static::$filePath = $absolutePath . "/{$this->filename}"; |
|
113 | 113 | file_put_contents(static::$filePath, $schema); |
114 | 114 | |
115 | 115 | return static::$filePath; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | $down = "Schema::dropIfExists('{$value['table_name']}');"; |
145 | - $up = "Schema::create('{$value['table_name']}', function(Blueprint $"."table) {\n"; |
|
145 | + $up = "Schema::create('{$value['table_name']}', function(Blueprint $" . "table) {\n"; |
|
146 | 146 | |
147 | 147 | $tableDescribes = $this->getTableDescribes($value['table_name']); |
148 | 148 | // Loop over the tables fields |
@@ -162,15 +162,15 @@ discard block |
||
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | - $up .= ' $'."table->{$this->methodName}('{$values->Field}'{$this->defaultLength}){$this->primaryKey}{$nullable}{$default}{$unsigned};\n"; |
|
165 | + $up .= ' $' . "table->{$this->methodName}('{$values->Field}'{$this->defaultLength}){$this->primaryKey}{$nullable}{$default}{$unsigned};\n"; |
|
166 | 166 | $this->unsetData(); |
167 | 167 | }//end foreach |
168 | 168 | |
169 | - $tableIndexes = (array) $this->getTableIndexes($value['table_name']); |
|
169 | + $tableIndexes = (array)$this->getTableIndexes($value['table_name']); |
|
170 | 170 | if (!is_null($tableIndexes) && count($tableIndexes)) { |
171 | 171 | foreach ($tableIndexes as $index) { |
172 | 172 | if (Str::endsWith(@$index['Key_name'], '_index')) { |
173 | - $up .= ' $'."table->index('".$index['Column_name']."');\n"; |
|
173 | + $up .= ' $' . "table->index('" . $index['Column_name'] . "');\n"; |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | } |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | $tableConstraints = $this->getTableConstraints($value['table_name']); |
184 | 184 | if (!is_null($tableConstraints) && $tableConstraints->count()) { |
185 | 185 | $Constraint = $ConstraintDown = " |
186 | - Schema::table('{$value['table_name']}', function(Blueprint $"."table) {\n"; |
|
186 | + Schema::table('{$value['table_name']}', function(Blueprint $" . "table) {\n"; |
|
187 | 187 | $tables = []; |
188 | 188 | foreach ($tableConstraints as $foreign) { |
189 | 189 | if (!in_array($foreign->Field, $tables)) { |
190 | 190 | $field = "{$foreign->Table}_{$foreign->Field}_foreign"; |
191 | - $ConstraintDown .= ' $'."table->dropForeign('".$field."');\n"; |
|
192 | - $Constraint .= ' $'."table->foreign('".$foreign->Field."')->references('".$foreign->References."')->on('".$foreign->ON."')->onDelete('".$foreign->onDelete."');\n"; |
|
191 | + $ConstraintDown .= ' $' . "table->dropForeign('" . $field . "');\n"; |
|
192 | + $Constraint .= ' $' . "table->foreign('" . $foreign->Field . "')->references('" . $foreign->References . "')->on('" . $foreign->ON . "')->onDelete('" . $foreign->onDelete . "');\n"; |
|
193 | 193 | $tables[$foreign->Field] = $foreign->Field; |
194 | 194 | } |
195 | 195 | } |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | }//end if |
257 | 257 | |
258 | 258 | // Grab the template |
259 | - $template = File::get(__DIR__.'/stubs/migration.stub'); |
|
259 | + $template = File::get(__DIR__ . '/stubs/migration.stub'); |
|
260 | 260 | |
261 | 261 | // Replace the classname |
262 | - $template = str_replace('{{name}}', 'Create'.ucfirst(Str::camel($this->database)).'Database', $template); |
|
262 | + $template = str_replace('{{name}}', 'Create' . ucfirst(Str::camel($this->database)) . 'Database', $template); |
|
263 | 263 | |
264 | 264 | // Replace the up and down values |
265 | 265 | $template = str_replace('{{up}}', $upSchema, $template); |
@@ -281,14 +281,14 @@ discard block |
||
281 | 281 | $values = substr($column->Type, ($hasSize + 1), -1); |
282 | 282 | switch ($type) { |
283 | 283 | case 'enum': |
284 | - $this->defaultLength = ', array('.$values.')'; |
|
284 | + $this->defaultLength = ', array(' . $values . ')'; |
|
285 | 285 | break; |
286 | 286 | case 'char': |
287 | 287 | case 'varchar': |
288 | 288 | case 'text': |
289 | 289 | case 'mediumtext': |
290 | 290 | case 'longtext': |
291 | - $this->defaultLength = ', '.$column->Length; |
|
291 | + $this->defaultLength = ', ' . $column->Length; |
|
292 | 292 | break; |
293 | 293 | case 'double': |
294 | 294 | case 'float': |
@@ -128,7 +128,7 @@ |
||
128 | 128 | /** |
129 | 129 | * Compile the current seedingStub with the seed template. |
130 | 130 | * |
131 | - * @return mixed |
|
131 | + * @return string |
|
132 | 132 | */ |
133 | 133 | protected function compile($table) |
134 | 134 | { |
@@ -85,23 +85,23 @@ discard block |
||
85 | 85 | // Get tables to ignore |
86 | 86 | $config = config('db-exporter.seeds'); |
87 | 87 | $ignore_tables = collect([]); |
88 | - if(!is_null($config) && isset($config['ignore_tables']) && !is_null($config['ignore_tables'])) { |
|
88 | + if (!is_null($config) && isset($config['ignore_tables']) && !is_null($config['ignore_tables'])) { |
|
89 | 89 | $ignore_tables = collect($config['ignore_tables']); |
90 | 90 | } |
91 | 91 | |
92 | 92 | $show_tables = collect([]); |
93 | - if(!is_null($config) && isset($config['use_tables']) && !is_null($config['use_tables'])) { |
|
93 | + if (!is_null($config) && isset($config['use_tables']) && !is_null($config['use_tables'])) { |
|
94 | 94 | $show_tables = collect($config['use_tables']); |
95 | 95 | } |
96 | 96 | |
97 | 97 | // Loop over the tables |
98 | 98 | foreach ($tables as $key => $value) |
99 | 99 | { |
100 | - if($show_tables->count() > 0 && !$show_tables->contains($value['table_name'])) { |
|
100 | + if ($show_tables->count() > 0 && !$show_tables->contains($value['table_name'])) { |
|
101 | 101 | continue; |
102 | 102 | } |
103 | 103 | |
104 | - if($ignore_tables->contains($value['table_name'])) { |
|
104 | + if ($ignore_tables->contains($value['table_name'])) { |
|
105 | 105 | continue; |
106 | 106 | } |
107 | 107 | |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | ];"; |
135 | 135 | |
136 | 136 | if ($this->hasTableData($tableData)) { |
137 | - $stub = $insertStub.' |
|
137 | + $stub = $insertStub . ' |
|
138 | 138 | |
139 | 139 | foreach($data as $item) |
140 | 140 | { |
141 | - $this->saveData("'.$tableName.'", $item); |
|
141 | + $this->saveData("'.$tableName . '", $item); |
|
142 | 142 | }'; |
143 | 143 | $result[$tableName] = $stub; |
144 | 144 | } |
@@ -172,13 +172,13 @@ discard block |
||
172 | 172 | |
173 | 173 | private function insertPropertyAndValue($prop, $value) |
174 | 174 | { |
175 | - if(strlen($prop) > 0) { |
|
175 | + if (strlen($prop) > 0) { |
|
176 | 176 | $prop = "'{$prop}'"; |
177 | 177 | } else { |
178 | 178 | $prop = 'null'; |
179 | 179 | } |
180 | 180 | |
181 | - if(strlen($value) > 0) { |
|
181 | + if (strlen($value) > 0) { |
|
182 | 182 | $value = str_replace("'", "\'", $value); |
183 | 183 | $value = "'{$value}'"; |
184 | 184 | } else { |
@@ -7,42 +7,42 @@ |
||
7 | 7 | |
8 | 8 | public function saveData($table, $item) |
9 | 9 | { |
10 | - // If have primary id |
|
11 | - if(isset($item['id'])) |
|
12 | - { |
|
13 | - if(\DB::table($table)->where('id', $item['id'])->count() > 0) |
|
14 | - { |
|
15 | - \DB::table($table)->where('id', $item['id'])->update($item); |
|
16 | - } |
|
17 | - else |
|
18 | - { |
|
19 | - \DB::table($table)->insert($item); |
|
20 | - } |
|
10 | + // If have primary id |
|
11 | + if(isset($item['id'])) |
|
12 | + { |
|
13 | + if(\DB::table($table)->where('id', $item['id'])->count() > 0) |
|
14 | + { |
|
15 | + \DB::table($table)->where('id', $item['id'])->update($item); |
|
16 | + } |
|
17 | + else |
|
18 | + { |
|
19 | + \DB::table($table)->insert($item); |
|
20 | + } |
|
21 | 21 | } |
22 | 22 | else |
23 | 23 | { |
24 | - $ids = collect($item)->filter(function($item, $key) { |
|
25 | - return str_contains($key, '_id'); |
|
26 | - })->keys()->values(); |
|
24 | + $ids = collect($item)->filter(function($item, $key) { |
|
25 | + return str_contains($key, '_id'); |
|
26 | + })->keys()->values(); |
|
27 | 27 | |
28 | - // If there isnt any column with _id, so check that every column matches |
|
29 | - if($ids->count() <= 0) { |
|
30 | - $ids = collect($item)->keys()->values(); |
|
31 | - } |
|
32 | - $object = \DB::table($table); |
|
33 | - foreach ($ids as $id) { |
|
34 | - $object = $object->where($id, $item[$id]); |
|
35 | - } |
|
28 | + // If there isnt any column with _id, so check that every column matches |
|
29 | + if($ids->count() <= 0) { |
|
30 | + $ids = collect($item)->keys()->values(); |
|
31 | + } |
|
32 | + $object = \DB::table($table); |
|
33 | + foreach ($ids as $id) { |
|
34 | + $object = $object->where($id, $item[$id]); |
|
35 | + } |
|
36 | 36 | |
37 | - // save or update |
|
38 | - if($object->count() > 0) |
|
39 | - { |
|
40 | - $object->update($item); |
|
41 | - } |
|
42 | - else |
|
43 | - { |
|
44 | - $object->insert($item); |
|
45 | - } |
|
37 | + // save or update |
|
38 | + if($object->count() > 0) |
|
39 | + { |
|
40 | + $object->update($item); |
|
41 | + } |
|
42 | + else |
|
43 | + { |
|
44 | + $object->insert($item); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
48 | 48 | } |
@@ -8,9 +8,9 @@ discard block |
||
8 | 8 | public function saveData($table, $item) |
9 | 9 | { |
10 | 10 | // If have primary id |
11 | - if(isset($item['id'])) |
|
11 | + if (isset($item['id'])) |
|
12 | 12 | { |
13 | - if(\DB::table($table)->where('id', $item['id'])->count() > 0) |
|
13 | + if (\DB::table($table)->where('id', $item['id'])->count() > 0) |
|
14 | 14 | { |
15 | 15 | \DB::table($table)->where('id', $item['id'])->update($item); |
16 | 16 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | })->keys()->values(); |
27 | 27 | |
28 | 28 | // If there isnt any column with _id, so check that every column matches |
29 | - if($ids->count() <= 0) { |
|
29 | + if ($ids->count() <= 0) { |
|
30 | 30 | $ids = collect($item)->keys()->values(); |
31 | 31 | } |
32 | 32 | $object = \DB::table($table); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | // save or update |
38 | - if($object->count() > 0) |
|
38 | + if ($object->count() > 0) |
|
39 | 39 | { |
40 | 40 | $object->update($item); |
41 | 41 | } |
@@ -13,13 +13,11 @@ discard block |
||
13 | 13 | if(\DB::table($table)->where('id', $item['id'])->count() > 0) |
14 | 14 | { |
15 | 15 | \DB::table($table)->where('id', $item['id'])->update($item); |
16 | - } |
|
17 | - else |
|
16 | + } else |
|
18 | 17 | { |
19 | 18 | \DB::table($table)->insert($item); |
20 | 19 | } |
21 | - } |
|
22 | - else |
|
20 | + } else |
|
23 | 21 | { |
24 | 22 | $ids = collect($item)->filter(function($item, $key) { |
25 | 23 | return str_contains($key, '_id'); |
@@ -38,8 +36,7 @@ discard block |
||
38 | 36 | if($object->count() > 0) |
39 | 37 | { |
40 | 38 | $object->update($item); |
41 | - } |
|
42 | - else |
|
39 | + } else |
|
43 | 40 | { |
44 | 41 | $object->insert($item); |
45 | 42 | } |