@@ -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,14 +85,14 @@ 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) && !is_null($config['ignore_tables'])) { |
|
88 | + if (!is_null($config) && !is_null($config['ignore_tables'])) { |
|
89 | 89 | $ignore_tables = collect($config['ignore_tables']); |
90 | 90 | } |
91 | 91 | |
92 | 92 | // Loop over the tables |
93 | 93 | foreach ($tables as $key => $value) |
94 | 94 | { |
95 | - if($ignore_tables->contains($value['table_name'])) { |
|
95 | + if ($ignore_tables->contains($value['table_name'])) { |
|
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | ];"; |
126 | 126 | |
127 | 127 | if ($this->hasTableData($tableData)) { |
128 | - $stub = $insertStub.' |
|
128 | + $stub = $insertStub . ' |
|
129 | 129 | |
130 | 130 | foreach($data as $item) |
131 | 131 | { |
132 | - $this->saveData("'.$tableName.'", $item); |
|
132 | + $this->saveData("'.$tableName . '", $item); |
|
133 | 133 | }'; |
134 | 134 | } |
135 | 135 | |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | |
165 | 165 | private function insertPropertyAndValue($prop, $value) |
166 | 166 | { |
167 | - if(strlen($prop) > 0) { |
|
167 | + if (strlen($prop) > 0) { |
|
168 | 168 | $prop = "'{$prop}'"; |
169 | 169 | } else { |
170 | 170 | $prop = 'null'; |
171 | 171 | } |
172 | 172 | |
173 | - if(strlen($value) > 0) { |
|
173 | + if (strlen($value) > 0) { |
|
174 | 174 | $value = str_replace("'", "\'", $value); |
175 | 175 | $value = "'{$value}'"; |
176 | 176 | } 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 | } |