Total Complexity | 60 |
Total Lines | 691 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like MigrateDatabaseCommand often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MigrateDatabaseCommand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class MigrateDatabaseCommand extends Command |
||
20 | { |
||
21 | use FileTrait; |
||
22 | |||
23 | protected $signature = 'tb_database:migrate {--y|yes}'; |
||
24 | protected $description = 'Because of the massive changes from version 5 to 6, this script is needed to properly update the database'; |
||
25 | |||
26 | protected $database; |
||
27 | protected $latestVersion; |
||
28 | |||
29 | // All of the tables in the Version 5 database |
||
30 | protected $ver5Tables = [ |
||
31 | 'customer_contact_phones', 'customer_contacts', 'customer_favs', 'customer_file_types', 'customer_files', 'customer_notes', 'customer_system_data', 'customer_systems', 'customers', |
||
32 | 'file_link_files', 'file_links', 'files', |
||
33 | 'phone_number_types', |
||
34 | 'settings', |
||
35 | 'system_categories', 'system_data_field_types', 'system_data_fields', 'system_types', |
||
36 | 'tech_tip_comments', 'tech_tip_favs', 'tech_tip_files', 'tech_tip_systems', 'tech_tip_types', 'tech_tips', |
||
37 | 'user_initializes', 'user_logins', 'user_role_permission_types', 'user_role_permissions', 'user_role_types', 'user_settings', 'users', |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * Create a new command instance |
||
42 | */ |
||
43 | public function __construct() |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Execute the console command |
||
52 | */ |
||
53 | public function handle() |
||
54 | { |
||
55 | $this->line('---------------------------------------------------------------'); |
||
56 | $this->line('| |'); |
||
57 | $this->line('| Database Migration Utility |'); |
||
58 | $this->line('| |'); |
||
59 | $this->line('---------------------------------------------------------------'); |
||
60 | |||
61 | // Make sure that this process is actually needed |
||
62 | if(!$this->isMigrationNecessary()) |
||
63 | { |
||
64 | $this->newLine(); |
||
65 | $this->info('Your Database is at the proper version'); |
||
66 | $this->info('Run `php artisan migrate` to update the tables'); |
||
67 | $this->newLine(); |
||
68 | return 0; |
||
69 | } |
||
70 | |||
71 | // Using the --yes option will bypass the confirmation message |
||
72 | if(!$this->option('yes')) |
||
73 | { |
||
74 | $this->error('-------------------------------------------------------------'); |
||
75 | $this->error('| VERY IMPORTANT: PLEASE BACKUP ALL DATA BEFORE PROCEEDING |'); |
||
76 | $this->error('| POSSIBLE DATA LOSS MAY OCCUR |'); |
||
77 | $this->error('-------------------------------------------------------------'); |
||
78 | |||
79 | if(!$this->confirm('Are you sure you want to continue?')) |
||
80 | { |
||
81 | $this->line('Exiting'); |
||
82 | return 0; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | // Check if the _old database already exists |
||
87 | $database = DB::select('SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = "'.$this->database.'_old"'); |
||
88 | if(count($database) > 0) |
||
89 | { |
||
90 | $this->error('ERROR - The MySQL Database already has a database named '.$this->database.'_old'); |
||
91 | $this->error('You must manually delete this database in order to continue'); |
||
92 | return 0; |
||
93 | } |
||
94 | |||
95 | // Check to make sure we can create a database and write to it |
||
96 | try |
||
97 | { |
||
98 | DB::statement('CREATE SCHEMA `'.$this->database.'_old`'); |
||
99 | } |
||
100 | catch(Exception $e) |
||
101 | { |
||
102 | $this->error('Unable to create temporary database'); |
||
103 | $this->error('Please check that database user has permissions to create a new Schema'); |
||
104 | $this->newLine(); |
||
105 | $this->error('Message - '.$e); |
||
106 | } |
||
107 | |||
108 | $this->info('Moving data to a temporary database'); |
||
109 | $this->moveOldData(); |
||
110 | |||
111 | // Create a default database |
||
112 | $this->info('Building Default Database'); |
||
113 | Artisan::call('migrate:fresh'); |
||
114 | $this->newLine(); |
||
115 | |||
116 | // Migrate Data |
||
117 | $this->migrateAppSettings(); |
||
118 | $this->migrateUserRoles(); |
||
119 | $this->migrateUsers(); |
||
120 | $this->migrateEquipment(); |
||
121 | $this->migrateFiles(); |
||
122 | $this->migrateCustomers(); |
||
123 | $this->migrateTechTips(); |
||
124 | $this->fileCleanup(); |
||
125 | $this->checkFileLinkModule(); |
||
126 | $this->cleanup(); |
||
127 | |||
128 | $this->line('---------------------------------------------------------------'); |
||
129 | $this->line('| |'); |
||
130 | $this->line('| Database Migration Complete |'); |
||
131 | $this->line('| |'); |
||
132 | $this->line('---------------------------------------------------------------'); |
||
133 | |||
134 | return 0; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Determine if the database needs to be migrated |
||
139 | */ |
||
140 | protected function isMigrationNecessary() |
||
141 | { |
||
142 | if(!Schema::hasTable('app_settings')) |
||
143 | { |
||
144 | return true; |
||
145 | } |
||
146 | |||
147 | return false; |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Move all existing information over to the temporary database |
||
152 | */ |
||
153 | protected function moveOldData() |
||
154 | { |
||
155 | foreach($this->ver5Tables as $table) |
||
156 | { |
||
157 | try |
||
158 | { |
||
159 | $this->line('Moving '.$this->database.'.'.$table); |
||
160 | DB::statement('RENAME TABLE `'.$this->database.'`.`'.$table.'` TO `'.$this->database.'_old`.`'.$table.'`'); |
||
161 | } |
||
162 | catch(Exception $e) |
||
163 | { |
||
164 | $this->line('Table '.$this->database.'.'.$table.' does not exist'); |
||
165 | } |
||
166 | } |
||
167 | |||
168 | DB::statement('DROP VIEW IF EXISTS `customer_contacts_view`'); |
||
169 | DB::statement('DROP VIEW IF EXISTS `navbar_view`'); |
||
170 | |||
171 | $this->newLine(); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Migrate App Settings |
||
176 | */ |
||
177 | protected function migrateAppSettings() |
||
178 | { |
||
179 | $this->info('Migrating App Settings'); |
||
180 | |||
181 | $current = DB::select('SELECT * FROM `'.$this->database.'_old`.`settings`'); |
||
182 | |||
183 | foreach($current as $cur) |
||
184 | { |
||
185 | $this->line('Adding Key - '.$cur->key); |
||
186 | DB::table('app_settings')->insert([ |
||
187 | 'key' => $cur->key, |
||
188 | 'value' => $cur->value, |
||
189 | 'created_at' => $cur->created_at, |
||
190 | 'updated_at' => NOW(), |
||
191 | ]); |
||
192 | } |
||
193 | |||
194 | $this->newLine(); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Migrate User Roles |
||
199 | */ |
||
200 | protected function migrateUserRoles() |
||
201 | { |
||
202 | // Determine if there are any roles other than the default roles |
||
203 | $current = DB::select('SELECT * FROM `'.$this->database.'_old`.`user_role_types`'); |
||
204 | if(count($current) == 4) |
||
205 | { |
||
206 | return false; |
||
207 | } |
||
208 | |||
209 | $this->info('Migrating User Roles'); |
||
210 | $roles = DB::select('SELECT * FROM `'.$this->database.'_old`.`user_role_types` WHERE `role_id` > 4'); |
||
211 | foreach($roles as $role) |
||
212 | { |
||
213 | $this->line('Creating '.$role->name.' Role'); |
||
214 | // Create the Role |
||
215 | DB::table('user_roles')->insert([ |
||
216 | 'role_id' => $role->role_id, |
||
217 | 'name' => $role->name, |
||
218 | 'description' => $role->description, |
||
219 | 'allow_edit' => 1, |
||
220 | 'created_at' => $role->created_at, |
||
221 | 'updated_at' => NOW()] |
||
222 | ); |
||
223 | |||
224 | // Create the permissions |
||
225 | $oldPermissions = DB::select('SELECT * FROM `'.$this->database.'_old`.`user_role_permissions` WHERE `role_id` ='.$role->role_id); |
||
226 | $newPermissions = [ |
||
227 | 1 => 0, |
||
228 | 2 => $this->getPermissionValue($oldPermissions, 1), |
||
229 | 3 => $this->getPermissionValue($oldPermissions, 2), |
||
230 | 4 => $this->getPermissionValue($oldPermissions, 3), |
||
231 | 5 => $this->getPermissionValue($oldPermissions, 11), |
||
232 | 6 => $this->getPermissionValue($oldPermissions, 5), |
||
233 | 7 => $this->getPermissionValue($oldPermissions, 4), |
||
234 | 8 => $this->getPermissionValue($oldPermissions, 4), |
||
235 | 9 => $this->getPermissionValue($oldPermissions, 6), |
||
236 | 10 => 0, |
||
237 | 11 => $this->getPermissionValue($oldPermissions, 4), |
||
238 | 12 => $this->getPermissionValue($oldPermissions, 4), |
||
239 | 13 => $this->getPermissionValue($oldPermissions, 4), |
||
240 | 14 => $this->getPermissionValue($oldPermissions, 4), |
||
241 | 15 => $this->getPermissionValue($oldPermissions, 4), |
||
242 | 16 => $this->getPermissionValue($oldPermissions, 4), |
||
243 | 17 => $this->getPermissionValue($oldPermissions, 4), |
||
244 | 18 => $this->getPermissionValue($oldPermissions, 4), |
||
245 | 19 => $this->getPermissionValue($oldPermissions, 4), |
||
246 | 20 => $this->getPermissionValue($oldPermissions, 4), |
||
247 | 21 => $this->getPermissionValue($oldPermissions, 4), |
||
248 | 22 => $this->getPermissionValue($oldPermissions, 4), |
||
249 | 23 => $this->getPermissionValue($oldPermissions, 8), |
||
250 | 24 => $this->getPermissionValue($oldPermissions, 9), |
||
251 | 25 => $this->getPermissionValue($oldPermissions, 10), |
||
252 | 26 => $this->getPermissionValue($oldPermissions, 9), |
||
253 | 27 => 1, |
||
254 | ]; |
||
255 | |||
256 | foreach($newPermissions as $key => $value) |
||
257 | { |
||
258 | DB::table('user_role_permissions')->insert([ |
||
259 | 'role_id' => $role->role_id, |
||
260 | 'perm_type_id' => $key, |
||
261 | 'allow' => $value, |
||
262 | 'created_at' => $oldPermissions[0]->created_at, |
||
263 | 'updated_at' => NOW(), |
||
264 | ]); |
||
265 | } |
||
266 | } |
||
267 | |||
268 | $this->newLine(); |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * Get the allow or deny of a User Role Permission Type |
||
273 | */ |
||
274 | protected function getPermissionValue($permArray, $id) |
||
275 | { |
||
276 | $obj = Arr::first($permArray, function($value, $key) use ($id) |
||
|
|||
277 | { |
||
278 | return $value->perm_type_id == $id; |
||
279 | }); |
||
280 | |||
281 | return $obj->allow; |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * Migrate all users from old database |
||
286 | */ |
||
287 | protected function migrateUsers() |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * Migrate all equipment types |
||
336 | */ |
||
337 | protected function migrateEquipment() |
||
338 | { |
||
339 | $this->info('Migrating Equipment'); |
||
340 | |||
341 | // Migrate Equipment Categories |
||
342 | $cat = DB::select('SELECT * FROM `'.$this->database.'_old`.`system_categories`'); |
||
343 | foreach($cat as $c) |
||
344 | { |
||
345 | $this->line('Adding Category - '.$c->name); |
||
346 | DB::table('equipment_categories')->insert((array) $c); |
||
347 | } |
||
348 | |||
349 | // Migrate Equipment Types |
||
350 | $equip = DB::select('SELECT * FROM `'.$this->database.'_old`.`system_types`'); |
||
351 | foreach($equip as $e) |
||
352 | { |
||
353 | $this->line('Adding Equipment - '.$e->name); |
||
354 | DB::table('equipment_types')->insert([ |
||
355 | 'equip_id' => $e->sys_id, |
||
356 | 'cat_id' => $e->cat_id, |
||
357 | 'name' => $e->name, |
||
358 | 'created_at' => $e->created_at, |
||
359 | 'updated_at' => $e->updated_at, |
||
360 | ]); |
||
361 | } |
||
362 | |||
363 | // Migrate Data Field Types |
||
364 | DB::statement('DELETE FROM `data_field_types` WHERE `name` IS NOT NULL'); |
||
365 | $types = DB::select('SELECT * FROM `'.$this->database.'_old`.`system_data_field_types`'); |
||
366 | foreach($types as $t) |
||
367 | { |
||
368 | $this->line('Adding Equipment Data Type - '.$t->name); |
||
369 | DB::table('data_field_types')->insert([ |
||
370 | 'type_id' => $t->data_type_id, |
||
371 | 'name' => $t->name, |
||
372 | 'hidden' => $t->hidden, |
||
373 | 'created_at' => $t->created_at, |
||
374 | 'updated_at' => $t->updated_at |
||
375 | ]); |
||
376 | } |
||
377 | |||
378 | $this->line('Adding Data Types to Equipment'); |
||
379 | $fields = DB::select('SELECT * FROM `'.$this->database.'_old`.`system_data_fields`'); |
||
380 | foreach($fields as $f) |
||
381 | { |
||
382 | DB::table('data_fields')->insert([ |
||
383 | 'field_id' => $f->field_id, |
||
384 | 'equip_id' => $f->sys_id, |
||
385 | 'type_id' => $f->data_type_id, |
||
386 | 'order' => $f->order, |
||
387 | 'created_at' => $f->created_at, |
||
388 | 'updated_at' => $f->updated_at, |
||
389 | ]); |
||
390 | } |
||
391 | |||
392 | $this->newLine(); |
||
393 | } |
||
394 | |||
395 | /** |
||
396 | * Migrate all files into the new database |
||
397 | */ |
||
398 | protected function migrateFiles() |
||
399 | { |
||
400 | $this->info('Migrating Files'); |
||
401 | $fileList = DB::select('SELECT * FROM `'.$this->database.'_old`.`files`'); |
||
402 | foreach($fileList as $file) |
||
403 | { |
||
404 | $this->line('Adding File '.$file->file_name); |
||
405 | DB::table('file_uploads')->insert([ |
||
406 | 'file_id' => $file->file_id, |
||
407 | 'disk' => 'local', |
||
408 | 'folder' => $file->file_link, |
||
409 | 'file_name' => $file->file_name, |
||
410 | 'public' => 0, |
||
411 | 'created_at' => $file->created_at, |
||
412 | 'updated_at' => $file->updated_at, |
||
413 | ]); |
||
414 | } |
||
415 | |||
416 | $this->newLine(); |
||
417 | } |
||
418 | |||
419 | /** |
||
420 | * Migrate all customer information |
||
421 | */ |
||
422 | protected function migrateCustomers() |
||
423 | { |
||
424 | $this->info('Migrating Customers'); |
||
425 | |||
426 | // Migrate the primary customer information |
||
427 | $customers = DB::select('SELECT * FROM `'.$this->database.'_old`.`customers`'); |
||
428 | |||
429 | // Temporarily disable all foreign keys |
||
430 | DB::statement('SET FOREIGN_KEY_CHECKS=0'); |
||
431 | |||
432 | foreach($customers as $cust) |
||
433 | { |
||
434 | $this->line('Adding Customer '.$cust->name); |
||
435 | DB::table('customers')->insert([ |
||
436 | 'cust_id' => $cust->cust_id, |
||
437 | 'parent_id' => $cust->parent_id, |
||
438 | 'name' => $cust->name, |
||
439 | 'dba_name' => $cust->dba_name, |
||
440 | 'slug' => STR::slug($cust->name), |
||
441 | 'address' => $cust->address, |
||
442 | 'city' => $cust->city, |
||
443 | 'state' => $cust->state, |
||
444 | 'zip' => $cust->zip, |
||
445 | 'deleted_at' => $cust->deleted_at, |
||
446 | 'created_at' => $cust->created_at, |
||
447 | 'updated_at' => $cust->updated_at, |
||
448 | ]); |
||
449 | } |
||
450 | |||
451 | // Re-enable all foreign keys |
||
452 | DB::statement('SET FOREIGN_KEY_CHECKS=1'); |
||
453 | $this->newLine(); |
||
454 | |||
455 | // Migrate customer equipment |
||
456 | $this->line('Adding Customer Equipment'); |
||
457 | $oldEquip = DB::select('SELECT * FROM `'.$this->database.'_old`.`customer_systems`'); |
||
458 | foreach($oldEquip as $equip) |
||
459 | { |
||
460 | DB::table('customer_equipment')->insert([ |
||
461 | 'cust_equip_id' => $equip->cust_sys_id, |
||
462 | 'cust_id' => $equip->cust_id, |
||
463 | 'equip_id' => $equip->sys_id, |
||
464 | 'shared' => $equip->shared, |
||
465 | 'deleted_at' => $equip->deleted_at, |
||
466 | 'created_at' => $equip->created_at, |
||
467 | 'updated_at' => $equip->updated_at, |
||
468 | ]); |
||
469 | } |
||
470 | |||
471 | // Migrate customer equipment data |
||
472 | $this->line('Adding Customer Equipment Data'); |
||
473 | $oldData = DB::select('SELECT * FROM `'.$this->database.'_old`.`customer_system_data`'); |
||
474 | foreach($oldData as $data) |
||
475 | { |
||
476 | DB::table('customer_equipment_data')->insert([ |
||
477 | 'cust_equip_id' => $data->cust_sys_id, |
||
478 | 'field_id' => $data->field_id, |
||
479 | 'value' => $data->value, |
||
480 | 'created_at' => $data->created_at, |
||
481 | 'updated_at' => $data->updated_at, |
||
482 | ]); |
||
483 | } |
||
484 | |||
485 | // Migrate Customer Contacts |
||
486 | $this->line('Adding Customer Contacts'); |
||
487 | $oldCont = DB::select('SELECT * FROM `'.$this->database.'_old`.`customer_contacts`'); |
||
488 | foreach($oldCont as $cont) |
||
489 | { |
||
490 | DB::table('customer_contacts')->insert((array) $cont); |
||
491 | } |
||
492 | |||
493 | // Migrate Customer Contact Phone Numbers |
||
494 | $oldPhone = DB::select('SELECT * FROM `'.$this->database.'_old`.`customer_contact_phones`'); |
||
495 | foreach($oldPhone as $phone) |
||
496 | { |
||
497 | DB::table('customer_contact_phones')->insert((array) $phone); |
||
498 | } |
||
499 | |||
500 | // Migrate Customer File Types |
||
501 | $this->line('Adding Customer Files'); |
||
502 | DB::statement('DELETE FROM `customer_file_types` WHERE `description` IS NOT NULL'); |
||
503 | $fileTypes = DB::select('SELECT * FROM `'.$this->database.'_old`.`customer_file_types`'); |
||
504 | foreach($fileTypes as $type) |
||
505 | { |
||
506 | DB::table('customer_file_types')->insert((array) $type); |
||
507 | } |
||
508 | |||
509 | // Migrate Customer Files |
||
510 | $oldFiles = DB::select('SELECT * FROM `'.$this->database.'_old`.`customer_files`'); |
||
511 | foreach($oldFiles as $file) |
||
512 | { |
||
513 | DB::table('customer_files')->insert((array) $file); |
||
514 | } |
||
515 | |||
516 | // Migrate Customer Notes |
||
517 | $this->line('Adding Customer Notes'); |
||
518 | $oldNotes = DB::select('SELECT * FROM `'.$this->database.'_old`.`customer_notes`'); |
||
519 | foreach($oldNotes as $note) |
||
520 | { |
||
521 | DB::table('customer_notes')->insert([ |
||
522 | 'note_id' => $note->note_id, |
||
523 | 'cust_id' => $note->cust_id, |
||
524 | 'created_by' => $note->user_id, |
||
525 | 'updated_by' => null, |
||
526 | 'urgent' => $note->urgent, |
||
527 | 'shared' => $note->shared, |
||
528 | 'subject' => $note->subject, |
||
529 | 'details' => $note->description, |
||
530 | 'deleted_at' => null, |
||
531 | 'created_at' => $note->created_at, |
||
532 | 'updated_at' => $note->updated_at, |
||
533 | ]); |
||
534 | } |
||
535 | |||
536 | // Migrate Customer Bookmarks |
||
537 | $this->line('Adding Customer Bookmarks'); |
||
538 | $oldBookmarks = DB::select('SELECT * FROM `'.$this->database.'_old`.`customer_favs`'); |
||
539 | foreach($oldBookmarks as $b) |
||
540 | { |
||
541 | DB::table('user_customer_bookmarks')->insert((array) $b); |
||
542 | } |
||
543 | |||
544 | $this->newLine(); |
||
545 | } |
||
546 | |||
547 | /** |
||
548 | * Migrate all Tech Tip data |
||
549 | */ |
||
550 | protected function migrateTechTips() |
||
551 | { |
||
552 | $this->info('Migrating Tech Tips'); |
||
553 | |||
554 | // Add the Tech Tip Types |
||
555 | DB::statement('DELETE FROM `tech_tip_types` WHERE `description` IS NOT NULL'); |
||
556 | $oldTypes = DB::select('SELECT * FROM `'.$this->database.'_old`.`tech_tip_types`'); |
||
557 | foreach($oldTypes as $type) |
||
558 | { |
||
559 | DB::table('tech_tip_types')->insert((array) $type); |
||
560 | } |
||
561 | |||
562 | $oldTips = DB::select('SELECT * FROM `'.$this->database.'_old`.`tech_tips`'); |
||
563 | foreach($oldTips as $tip) |
||
564 | { |
||
565 | // TODO - Make all images responsive |
||
566 | $this->line('Adding Tech Tip '.$tip->subject); |
||
567 | DB::table('tech_tips')->insert([ |
||
568 | 'tip_id' => $tip->tip_id, |
||
569 | 'user_id' => $tip->user_id, |
||
570 | 'updated_id' => isset($tip->updated_id) ? $tip->updated_id : null, |
||
571 | 'tip_type_id' => $tip->tip_type_id, |
||
572 | 'sticky' => isset($tip->sticky) ? $tip->sticky : false, |
||
573 | 'subject' => $tip->subject, |
||
574 | 'slug' => Str::slug($tip->subject), |
||
575 | 'details' => str_replace('<img ', '<img class="fluid-img" ', $tip->description), |
||
576 | 'deleted_at' => $tip->deleted_at, |
||
577 | 'created_at' => $tip->created_at, |
||
578 | 'updated_at' => $tip->updated_at, |
||
579 | ]); |
||
580 | } |
||
581 | |||
582 | // Add Tech Tip Equipment |
||
583 | $this->newLine(); |
||
584 | $this->line('Adding Tech Tip Equipment'); |
||
585 | $oldEquipment = DB::select('SELECT * FROM `'.$this->database.'_old`.`tech_tip_systems`'); |
||
586 | foreach($oldEquipment as $equip) |
||
587 | { |
||
588 | DB::table('tech_tip_equipment')->insert([ |
||
589 | 'tip_equip_id' => $equip->tip_tag_id, |
||
590 | 'tip_id' => $equip->tip_id, |
||
591 | 'equip_id' => $equip->sys_id, |
||
592 | ]); |
||
593 | } |
||
594 | |||
595 | // Add Tech Tip Files |
||
596 | $this->line('Adding Tech Tip Files'); |
||
597 | $oldFiles = DB::select('SELECT * FROM `'.$this->database.'_old`.`tech_tip_files`'); |
||
598 | foreach($oldFiles as $file) |
||
599 | { |
||
600 | DB::table('tech_tip_files')->insert((array) $file); |
||
601 | } |
||
602 | |||
603 | // Add Tech Tip Comments |
||
604 | $this->line('Adding Tech Tip Comments'); |
||
605 | $oldComments = DB::select('SELECT * FROM `'.$this->database.'_old`.`tech_tip_comments`'); |
||
606 | foreach($oldComments as $com) |
||
607 | { |
||
608 | DB::table('tech_tip_comments')->insert([ |
||
609 | 'id' => $com->comment_id, |
||
610 | 'tip_id' => $com->tip_id, |
||
611 | 'user_id' => $com->user_id, |
||
612 | 'comment' => $com->comment, |
||
613 | 'created_at' => $com->created_at, |
||
614 | 'updated_at' => $com->updated_at, |
||
615 | ]); |
||
616 | } |
||
617 | |||
618 | // Add Tech Tip Bookmarks |
||
619 | $this->line('Adding Tech Tip Bookmarks'); |
||
620 | $oldBookmarks = DB::select('SELECT * FROM `'.$this->database.'_old`.`tech_tip_favs`'); |
||
621 | foreach($oldBookmarks as $b) |
||
622 | { |
||
623 | DB::table('user_tech_tip_bookmarks')->insert((array) $b); |
||
624 | } |
||
625 | |||
626 | $this->newLine(); |
||
627 | } |
||
628 | |||
629 | /** |
||
630 | * Cleanup files and move them into the proper folders |
||
631 | */ |
||
632 | protected function fileCleanup() |
||
633 | { |
||
634 | $this->info('Cleaning up Filesystem'); |
||
635 | |||
636 | $customerFiles = CustomerFile::all(); |
||
637 | foreach($customerFiles as $file) |
||
638 | { |
||
639 | if(!$this->moveStoredFile($file->file_id, $file->cust_id, 'customers')) |
||
640 | { |
||
641 | $this->error('FILE MISSING ON DISK '.$file->disk.' - '.$file->FileUpload->folder.DIRECTORY_SEPARATOR.$file->FileUpload->file_name); |
||
642 | } |
||
643 | } |
||
644 | |||
645 | $techTipFiles = TechTipFile::all(); |
||
646 | foreach($techTipFiles as $file) |
||
647 | { |
||
648 | if(!$this->moveStoredFile($file->file_id, $file->cust_id, 'tips')) |
||
649 | { |
||
650 | $this->error('FILE MISSING ON DISK '.$file->disk.' - '.$file->FileUpload->folder.DIRECTORY_SEPARATOR.$file->FileUpload->file_name); |
||
651 | } |
||
652 | } |
||
653 | |||
654 | $this->newLine(); |
||
655 | } |
||
656 | |||
657 | /** |
||
658 | * Check if the File Link Add-on is installed, |
||
659 | * If it is, migrate those tables |
||
660 | */ |
||
661 | protected function checkFileLinkModule() |
||
700 | } |
||
701 | |||
702 | /** |
||
703 | * Cleanup |
||
704 | */ |
||
705 | protected function cleanup() |
||
710 | } |
||
711 | } |
||
712 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.