@@ -2,7 +2,6 @@ |
||
| 2 | 2 | namespace Elimuswift\DbExporter; |
| 3 | 3 | |
| 4 | 4 | use Illuminate\Support\ServiceProvider; |
| 5 | -use Illuminate\Support\Facades\Config; |
|
| 6 | 5 | |
| 7 | 6 | |
| 8 | 7 | class DbExportHandlerServiceProvider extends ServiceProvider |
@@ -38,11 +38,11 @@ |
||
| 38 | 38 | public function register() |
| 39 | 39 | { |
| 40 | 40 | $this->publishes([ |
| 41 | - realpath(__DIR__ .'/../').'/config/db-exporter.php' => config_path('db-exporter.php'), |
|
| 41 | + realpath(__DIR__ . '/../') . '/config/db-exporter.php' => config_path('db-exporter.php'), |
|
| 42 | 42 | ]); |
| 43 | 43 | |
| 44 | 44 | $this->mergeConfigFrom( |
| 45 | - realpath(__DIR__ .'/../').'/config/db-exporter.php', 'db-exporter' |
|
| 45 | + realpath(__DIR__ . '/../') . '/config/db-exporter.php', 'db-exporter' |
|
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | $this->app->register(DbMigrationsServiceProvider::class); |
@@ -159,17 +159,17 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | $tableIndexes = $this->getTableIndexes($value['table_name']); |
| 161 | 161 | if (!is_null($tableIndexes) && count($tableIndexes)){ |
| 162 | - foreach ($tableIndexes as $index) { |
|
| 162 | + foreach ($tableIndexes as $index) { |
|
| 163 | 163 | if(Str::endsWith($index['Key_name'], '_index')) |
| 164 | - $up .= ' $' . "table->index('" . $index['Key_name'] . "');\n"; |
|
| 164 | + $up .= ' $' . "table->index('" . $index['Key_name'] . "');\n"; |
|
| 165 | 165 | } |
| 166 | - } |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | 168 | $up .= " });\n\n"; |
| 169 | 169 | $Constraint = $ConstraintDown = ""; |
| 170 | 170 | /** |
| 171 | - * @var array $tableConstraints |
|
| 172 | - */ |
|
| 171 | + * @var array $tableConstraints |
|
| 172 | + */ |
|
| 173 | 173 | $tableConstraints = $this->getTableConstraints($value['table_name']); |
| 174 | 174 | if (!is_null($tableConstraints) && count($tableConstraints)){ |
| 175 | 175 | $Constraint = $ConstraintDown = " |
@@ -210,24 +210,24 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | // prevent of failure when no table |
| 212 | 212 | if (!is_null($this->schema) && count($this->schema)) { |
| 213 | - foreach ($this->schema as $name => $values) { |
|
| 214 | - // check again for ignored tables |
|
| 215 | - if (in_array($name, self::$ignore)) { |
|
| 216 | - continue; |
|
| 217 | - } |
|
| 218 | - $upSchema .= " |
|
| 213 | + foreach ($this->schema as $name => $values) { |
|
| 214 | + // check again for ignored tables |
|
| 215 | + if (in_array($name, self::$ignore)) { |
|
| 216 | + continue; |
|
| 217 | + } |
|
| 218 | + $upSchema .= " |
|
| 219 | 219 | /** |
| 220 | 220 | * Table: {$name} |
| 221 | 221 | */ |
| 222 | 222 | {$values['up']}"; |
| 223 | 223 | $upConstraint.=" |
| 224 | 224 | {$values['constraint']}"; |
| 225 | - $downConstraint.=" |
|
| 225 | + $downConstraint.=" |
|
| 226 | 226 | {$values['constraint_down']}"; |
| 227 | 227 | |
| 228 | - $downSchema .= " |
|
| 228 | + $downSchema .= " |
|
| 229 | 229 | {$values['down']}"; |
| 230 | - } |
|
| 230 | + } |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // Grab the template |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $schema = $this->compile(); |
| 46 | 46 | $filename = date('Y_m_d_His') . "_create_" . $this->database . "_database.php"; |
| 47 | - static::$filePath = Config::get('db-exporter.export_path.migrations')."{$filename}"; |
|
| 47 | + static::$filePath = Config::get('db-exporter.export_path.migrations') . "{$filename}"; |
|
| 48 | 48 | |
| 49 | 49 | file_put_contents(static::$filePath, $schema); |
| 50 | 50 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $numbers = ""; |
| 87 | 87 | $nullable = $values->Null == "NO" ? "" : "->nullable()"; |
| 88 | 88 | $default = empty($values->Default) ? "" : "->default(\"{$values->Default}\")"; |
| 89 | - $unsigned = strpos($values->Type, "unsigned") === false ? '': '->unsigned()'; |
|
| 89 | + $unsigned = strpos($values->Type, "unsigned") === false ? '' : '->unsigned()'; |
|
| 90 | 90 | |
| 91 | 91 | switch ($type) { |
| 92 | 92 | case 'int': |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | $tableIndexes = $this->getTableIndexes($value['table_name']); |
| 161 | - if (!is_null($tableIndexes) && count($tableIndexes)){ |
|
| 161 | + if (!is_null($tableIndexes) && count($tableIndexes)) { |
|
| 162 | 162 | foreach ($tableIndexes as $index) { |
| 163 | - if(Str::endsWith($index['Key_name'], '_index')) |
|
| 163 | + if (Str::endsWith($index['Key_name'], '_index')) |
|
| 164 | 164 | $up .= ' $' . "table->index('" . $index['Key_name'] . "');\n"; |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -171,14 +171,14 @@ discard block |
||
| 171 | 171 | * @var array $tableConstraints |
| 172 | 172 | */ |
| 173 | 173 | $tableConstraints = $this->getTableConstraints($value['table_name']); |
| 174 | - if (!is_null($tableConstraints) && count($tableConstraints)){ |
|
| 174 | + if (!is_null($tableConstraints) && count($tableConstraints)) { |
|
| 175 | 175 | $Constraint = $ConstraintDown = " |
| 176 | 176 | Schema::table('{$value['table_name']}', function(Blueprint $" . "table) {\n"; |
| 177 | 177 | $tables = []; |
| 178 | 178 | foreach ($tableConstraints as $foreign) { |
| 179 | - if(!in_array($foreign->Field, $tables)){ |
|
| 180 | - $ConstraintDown .= ' $' . "table->dropForeign('" . $foreign->Field. "');\n"; |
|
| 181 | - $Constraint .= ' $' . "table->foreign('" . $foreign->Field. "')->references('" . $foreign->References . "')->on('" . $foreign->ON. "')->onDelete('" . $foreign->onDelete. "');\n"; |
|
| 179 | + if (!in_array($foreign->Field, $tables)) { |
|
| 180 | + $ConstraintDown .= ' $' . "table->dropForeign('" . $foreign->Field . "');\n"; |
|
| 181 | + $Constraint .= ' $' . "table->foreign('" . $foreign->Field . "')->references('" . $foreign->References . "')->on('" . $foreign->ON . "')->onDelete('" . $foreign->onDelete . "');\n"; |
|
| 182 | 182 | $tables[$foreign->Field] = $foreign->Field; |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | * Table: {$name} |
| 221 | 221 | */ |
| 222 | 222 | {$values['up']}"; |
| 223 | - $upConstraint.=" |
|
| 223 | + $upConstraint .= " |
|
| 224 | 224 | {$values['constraint']}"; |
| 225 | - $downConstraint.=" |
|
| 225 | + $downConstraint .= " |
|
| 226 | 226 | {$values['constraint_down']}"; |
| 227 | 227 | |
| 228 | 228 | $downSchema .= " |