Total Complexity | 81 |
Total Lines | 849 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like DatabaseCheck 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 DatabaseCheck, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class DatabaseCheck extends Command |
||
20 | { |
||
21 | // Command Name |
||
22 | protected $signature = 'dbcheck |
||
23 | {--fix : Automatically fix any issues that arrise} |
||
24 | {--report : Place all results in a downloadable PDF}'; |
||
25 | |||
26 | // Command description |
||
27 | protected $description = 'Verify database and file structure matches'; |
||
28 | |||
29 | // Report Data |
||
30 | protected $repData, $fix, $rep; |
||
31 | protected $fileArr = []; |
||
32 | |||
33 | // Constructor |
||
34 | public function __construct() |
||
35 | { |
||
36 | parent::__construct(); |
||
37 | } |
||
38 | |||
39 | // Run the DB Check |
||
40 | public function handle() |
||
41 | { |
||
42 | // Shortcut for options being on or off |
||
43 | $this->fix = $this->option('fix'); |
||
44 | $this->rep = $this->option('report'); |
||
45 | $brk = '<br />'; |
||
|
|||
46 | |||
47 | $today = Carbon::now(); |
||
48 | |||
49 | // Extend the Max Execution time for the script |
||
50 | ini_set('max_execution_time', 600); //600 seconds = 10 minutes |
||
51 | |||
52 | $this->line('Running DB Check...'); |
||
53 | $this->line(''); |
||
54 | |||
55 | $this->repData = "***********************************************************\n"; |
||
56 | $this->repData .= "* *\n"; |
||
57 | $this->repData .= "* Database Report $today->year-$today->month-$today->day *\n"; |
||
58 | $this->repData .= "* *\n"; |
||
59 | $this->repData .= "***********************************************************\n\n"; |
||
60 | |||
61 | /***************************** |
||
62 | * * |
||
63 | * User Portion of DB Check * |
||
64 | * * |
||
65 | ******************************/ |
||
66 | // List all system administrators |
||
67 | $admins = $this->getAdmins(); |
||
68 | $this->output($admins); |
||
69 | |||
70 | // Count both active and non active users |
||
71 | $users = $this->countUsers(); |
||
72 | $this->output($users); |
||
73 | |||
74 | // Make sure all users have a settings table |
||
75 | $settings = $this->userSettings(); |
||
76 | $this->output($settings); |
||
77 | |||
78 | // Check for active User Initialization links |
||
79 | $links = $this->initializationLinks(); |
||
80 | $this->output($links); |
||
81 | |||
82 | /***************************** |
||
83 | * * |
||
84 | * File Portion of DB Check * |
||
85 | * * |
||
86 | ******************************/ |
||
87 | // Get all of the files in the file table |
||
88 | $this->fileArr = $this->getFiles(); |
||
89 | |||
90 | // Check for system files that are in the files table but missing actual file |
||
91 | $sysFiles = $this->systemFiles(); |
||
92 | $this->output($sysFiles); |
||
93 | |||
94 | // Check for customer files that are in the files table but missing the actual file |
||
95 | $custFiles = $this->customerFiles(); |
||
96 | $this->output($custFiles); |
||
97 | |||
98 | // Check for file link files that are in the files table but missing the actual file |
||
99 | $linkFiles = $this->linkFiles(); |
||
100 | $this->output($linkFiles); |
||
101 | |||
102 | // Check for tech tip files that are in the files table but missing the actual file |
||
103 | $tipFiles = $this->tipFiles(); |
||
104 | $this->output($tipFiles); |
||
105 | |||
106 | // For all remaining files in 'files' table - verify file exists |
||
107 | $remainingFiles = $this->remainingFiles(); |
||
108 | $this->output($remainingFiles); |
||
109 | |||
110 | // Determine any rogue files |
||
111 | $rogueFiles = $this->rogueFiles(); |
||
112 | $this->output($rogueFiles); |
||
113 | |||
114 | /***************************** |
||
115 | * * |
||
116 | * Wrap up * |
||
117 | * * |
||
118 | ******************************/ |
||
119 | $output = []; |
||
120 | $output[] = [ |
||
121 | 'type' => 'info', |
||
122 | 'value' => 'Database Report Completed' |
||
123 | ]; |
||
124 | |||
125 | $this->output($output); |
||
126 | |||
127 | // Generate a PDF report if the option is selected |
||
128 | if($this->rep) |
||
129 | { |
||
130 | Storage::disk('logs')->append('dbCheck-'.$today->year.'-'.$today->month.'-'.$today->day.'.log', $this->repData); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | // Print the output to the screen and write for PDF report |
||
135 | private function output($data) |
||
136 | { |
||
137 | foreach($data as $d) |
||
138 | { |
||
139 | // Console Output |
||
140 | if(!isset($d['repOnly'])) |
||
141 | { |
||
142 | $type = $d['type']; |
||
143 | $this->$type($d['value']); |
||
144 | } |
||
145 | |||
146 | // Report Output |
||
147 | $this->repData .= $d['value']."\n"; |
||
148 | } |
||
149 | |||
150 | // Line Break |
||
151 | $this->line(''); |
||
152 | $this->repData .= "\n"; |
||
153 | } |
||
154 | |||
155 | // List all system administrators |
||
156 | private function getAdmins() |
||
157 | { |
||
158 | $res = []; |
||
159 | |||
160 | $admins = User::where('active', 1) |
||
161 | ->join('user_role', 'users.user_id', '=', 'user_role.user_id') |
||
162 | ->where('user_role.role_id', '<=', 2) |
||
163 | ->get(); |
||
164 | |||
165 | $res[] = [ 'type' => 'info', 'value' => 'System Administrators ('.count($admins).')']; |
||
166 | foreach($admins as $admin) |
||
167 | { |
||
168 | $res[] = [ |
||
169 | 'type' => 'line', 'value' => ' '.$admin->first_name.' '.$admin->last_name |
||
170 | ]; |
||
171 | } |
||
172 | |||
173 | return $res; |
||
174 | } |
||
175 | |||
176 | // Count active and non-active users |
||
177 | private function countUsers() |
||
178 | { |
||
179 | $res = []; |
||
180 | |||
181 | $activeUsers = User::where('active', 1)->count(); |
||
182 | $inactiveUsr = User::where('active', 0)->count(); |
||
183 | |||
184 | $res[] = [ |
||
185 | 'type' => 'line', |
||
186 | 'value' => 'Active Users.................................'.$activeUsers |
||
187 | ]; |
||
188 | $res[] = [ |
||
189 | 'type' => 'line', |
||
190 | 'value' => 'Inactive Users...............................'.$inactiveUsr |
||
191 | ]; |
||
192 | |||
193 | return $res; |
||
194 | } |
||
195 | |||
196 | // Verify all users have a settings table |
||
197 | private function userSettings() |
||
198 | { |
||
199 | $res = []; |
||
200 | |||
201 | $users = User::all(); |
||
202 | $settings = UserSettings::all(); |
||
203 | |||
204 | $failedItems = []; |
||
205 | foreach($users as $user) |
||
206 | { |
||
207 | $match = false; |
||
208 | foreach($settings as $setting) |
||
209 | { |
||
210 | if($user->user_id == $setting->user_id) |
||
211 | { |
||
212 | $match = true; |
||
213 | break; |
||
214 | } |
||
215 | } |
||
216 | |||
217 | if(!$match) |
||
218 | { |
||
219 | $failedItems[] = [ |
||
220 | 'user_id' => $user->user_id, |
||
221 | 'name' => $user->first_name.' '.$user->last_name |
||
222 | ]; |
||
223 | } |
||
224 | } |
||
225 | |||
226 | if($failedItems) |
||
227 | { |
||
228 | $res[] = [ |
||
229 | 'type' => 'error', |
||
230 | 'value' => count($failedItems).' user(s) missing settings information' |
||
231 | ]; |
||
232 | |||
233 | foreach($failedItems as $item) |
||
234 | { |
||
235 | $res[] = [ |
||
236 | 'type' => 'line', |
||
237 | 'value' => ' User ID - '.$item['user_id'].'-'.$item['name'] |
||
238 | ]; |
||
239 | |||
240 | if($this->fix) |
||
241 | { |
||
242 | UserSettings::create([ |
||
243 | 'user_id' => $item['user_id'] |
||
244 | ]); |
||
245 | |||
246 | $res[] = [ |
||
247 | 'type' => 'info', |
||
248 | 'value' => ' corrected' |
||
249 | ]; |
||
250 | } |
||
251 | } |
||
252 | } |
||
253 | |||
254 | return $res; |
||
255 | } |
||
256 | |||
257 | // Verify User Initialization links |
||
258 | private function initializationLinks() |
||
259 | { |
||
260 | $res = []; |
||
261 | |||
262 | $initLinks = UserInitialize::all(); |
||
263 | |||
264 | $links = []; |
||
265 | $over = []; |
||
266 | if(!empty($initLinks)) |
||
267 | { |
||
268 | // List each expired link |
||
269 | foreach($initLinks as $link) |
||
270 | { |
||
271 | $links[] = [ |
||
272 | 'username' => $link->username, |
||
273 | 'age' => $link->created_at->diffInDays(Carbon::now()) |
||
274 | ]; |
||
275 | |||
276 | // See if the link is more than two weeks old |
||
277 | if($link->created_at->diffInDays(Carbon::now()) > 14) |
||
278 | { |
||
279 | $over[] = [ |
||
280 | 'username' => $link->username, |
||
281 | 'age' => $link->created_at->diffInDays(Carbon::now()) |
||
282 | ]; |
||
283 | } |
||
284 | } |
||
285 | |||
286 | $res[] = [ |
||
287 | 'type' => 'line', |
||
288 | 'value' => count($links).' Users are awaiting to be initialized' |
||
289 | ]; |
||
290 | |||
291 | if(!empty($over)) |
||
292 | { |
||
293 | foreach($over as $ov) |
||
294 | { |
||
295 | $res[] = [ |
||
296 | 'type' => 'error', |
||
297 | 'value' => ' Link for '.$ov['username'].' is '.$ov['age'].' days old' |
||
298 | ]; |
||
299 | |||
300 | if($this->fix) |
||
301 | { |
||
302 | UserInitialize::where('username', $ov['username'])->delete(); |
||
303 | $res[] = [ |
||
304 | 'type' => 'info', |
||
305 | 'value' => ' Corrected' |
||
306 | ]; |
||
307 | } |
||
308 | } |
||
309 | } |
||
310 | } |
||
311 | |||
312 | return $res; |
||
313 | } |
||
314 | |||
315 | // Get all of the files in the "Files" table |
||
316 | private function getFiles() |
||
317 | { |
||
318 | $files = Files::all(); |
||
319 | |||
320 | $fileArr = []; |
||
321 | foreach($files as $f) |
||
322 | { |
||
323 | $fileArr[] = $f->file_id; |
||
324 | } |
||
325 | |||
326 | return $fileArr; |
||
327 | } |
||
328 | |||
329 | // Check that all system files exist |
||
330 | private function systemFiles() |
||
331 | { |
||
332 | $res = []; |
||
333 | $res2 = []; |
||
334 | |||
335 | $badPointer = 0; |
||
336 | $missingFile = 0; |
||
337 | |||
338 | $sysFiles = SystemFiles::all(); |
||
339 | |||
340 | $res[] = [ |
||
341 | 'type' => 'line', |
||
342 | 'value' => 'System Files......................'.count($sysFiles) |
||
343 | ]; |
||
344 | |||
345 | // Verify all files have a database pointer and a valid file |
||
346 | foreach($sysFiles as $file) |
||
347 | { |
||
348 | // Verify database pointer |
||
349 | if(!in_array($file->file_id, $this->fileArr)) |
||
350 | { |
||
351 | $badPointer++; |
||
352 | $res2[] = [ |
||
353 | 'type' => 'error', |
||
354 | 'value' => ' File ID '.$file->file_id.' missing in files table', |
||
355 | 'repOnly' => true |
||
356 | ]; |
||
357 | |||
358 | if($this->fix) |
||
359 | { |
||
360 | SystemFiles::find($file->sys_file_id)->delete(); |
||
361 | $res2[] = [ |
||
362 | 'type' => 'info', |
||
363 | 'value' => ' Corrected', |
||
364 | 'repOnly' => true |
||
365 | ]; |
||
366 | } |
||
367 | } |
||
368 | else |
||
369 | { |
||
370 | // Verify that the file exists |
||
371 | $fileData = Files::find($file->file_id); |
||
372 | if(!Storage::exists($fileData->file_link.$fileData->file_name)) |
||
373 | { |
||
374 | $missingFile++; |
||
375 | $res2[] = [ |
||
376 | 'type' => 'error', |
||
377 | 'value' => ' Missing File ID - '.$fileData->file_id.' - '.$fileData->file_link.$fileData->file_name, |
||
378 | 'repOnly' => true |
||
379 | ]; |
||
380 | |||
381 | if($this->fix) |
||
382 | { |
||
383 | $file->delete(); |
||
384 | $fileData->delete(); |
||
385 | $res2[] = [ |
||
386 | 'type' => 'info', |
||
387 | 'value' => ' Corrected', |
||
388 | 'repOnly' => true |
||
389 | ]; |
||
390 | } |
||
391 | } |
||
392 | |||
393 | $pos = array_search($file->file_id, $this->fileArr); |
||
394 | unset($this->fileArr[$pos]); |
||
395 | } |
||
396 | } |
||
397 | |||
398 | // Error messages if pointer bad or file missing |
||
399 | if($badPointer) |
||
400 | { |
||
401 | $res[] = [ |
||
402 | 'type' => 'error', |
||
403 | 'value' => ' Bad file pointers............'.$badPointer |
||
404 | ]; |
||
405 | if($this->fix) |
||
406 | { |
||
407 | $res[] = [ |
||
408 | 'type' => 'info', |
||
409 | 'value' => ' Corrected' |
||
410 | ]; |
||
411 | } |
||
412 | } |
||
413 | if($missingFile) |
||
414 | { |
||
415 | $res[] = [ |
||
416 | 'type' => 'error', |
||
417 | 'value' => ' Missing Files................'.$missingFile |
||
418 | ]; |
||
419 | if($this->fix) |
||
420 | { |
||
421 | $res[] = [ |
||
422 | 'type' => 'info', |
||
423 | 'value' => ' Corrected' |
||
424 | ]; |
||
425 | } |
||
426 | } |
||
427 | |||
428 | $res = array_merge($res, $res2); |
||
429 | |||
430 | return $res; |
||
431 | } |
||
432 | |||
433 | // Check that all customer files exist |
||
434 | private function customerFiles() |
||
435 | { |
||
436 | $res = []; |
||
437 | $res2 = []; |
||
438 | |||
439 | $badPointer = 0; |
||
440 | $missingFile = 0; |
||
441 | |||
442 | $custFiles = CustomerFiles::all(); |
||
443 | |||
444 | $res[] = [ |
||
445 | 'type' => 'line', |
||
446 | 'value' => 'Customer Files....................'.count($custFiles) |
||
447 | ]; |
||
448 | |||
449 | // Verify all files have a database pointer and a valid file |
||
450 | foreach($custFiles as $file) |
||
451 | { |
||
452 | // Verify database pointer |
||
453 | if(!in_array($file->file_id, $this->fileArr)) |
||
454 | { |
||
455 | $badPointer++; |
||
456 | $res2[] = [ |
||
457 | 'type' => 'error', |
||
458 | 'value' => ' File ID '.$file->file_id.' missing in files table', |
||
459 | 'repOnly' => true |
||
460 | ]; |
||
461 | |||
462 | if($this->fix) |
||
463 | { |
||
464 | CustomerFiles::find($file->cust_file_id)->delete(); |
||
465 | $res2[] = [ |
||
466 | 'type' => 'info', |
||
467 | 'value' => ' Corrected', |
||
468 | 'repOnly' => true |
||
469 | ]; |
||
470 | } |
||
471 | } |
||
472 | else |
||
473 | { |
||
474 | // Verify that the file exists |
||
475 | $fileData = Files::find($file->file_id); |
||
476 | if(!Storage::exists($fileData->file_link.$fileData->file_name)) |
||
477 | { |
||
478 | $missingFile++; |
||
479 | $res2[] = [ |
||
480 | 'type' => 'error', |
||
481 | 'value' => ' Missing File ID - '.$fileData->file_id.' - '.$fileData->file_link.$fileData->file_name, |
||
482 | 'repOnly' => true |
||
483 | ]; |
||
484 | |||
485 | if($this->fix) |
||
486 | { |
||
487 | $file->delete(); |
||
488 | $fileData->delete(); |
||
489 | $res2[] = [ |
||
490 | 'type' => 'info', |
||
491 | 'value' => ' Corrected', |
||
492 | 'repOnly' => true |
||
493 | ]; |
||
494 | } |
||
495 | } |
||
496 | $pos = array_search($file->file_id, $this->fileArr); |
||
497 | unset($this->fileArr[$pos]); |
||
498 | } |
||
499 | } |
||
500 | |||
501 | // Error messages if pointer bad or file missing |
||
502 | if($badPointer) |
||
503 | { |
||
504 | $res[] = [ |
||
505 | 'type' => 'error', |
||
506 | 'value' => ' Bad file pointers............'.$badPointer |
||
507 | ]; |
||
508 | if($this->fix) |
||
509 | { |
||
510 | $res[] = [ |
||
511 | 'type' => 'info', |
||
512 | 'value' => ' Corrected' |
||
513 | ]; |
||
514 | } |
||
515 | } |
||
516 | if($missingFile) |
||
517 | { |
||
518 | $res[] = [ |
||
519 | 'type' => 'error', |
||
520 | 'value' => ' Missing Files................'.$missingFile |
||
521 | ]; |
||
522 | if($this->fix) |
||
523 | { |
||
524 | $res[] = [ |
||
525 | 'type' => 'info', |
||
526 | 'value' => ' Corrected' |
||
527 | ]; |
||
528 | } |
||
529 | } |
||
530 | |||
531 | $res = array_merge($res, $res2); |
||
532 | |||
533 | return $res; |
||
534 | } |
||
535 | |||
536 | // Check that all file link files exist |
||
537 | private function linkFiles() |
||
538 | { |
||
539 | $res = []; |
||
540 | $res2 = []; |
||
541 | |||
542 | $badPointer = 0; |
||
543 | $missingFile = 0; |
||
544 | |||
545 | $linkFiles = FileLinkFiles::all(); |
||
546 | |||
547 | $res[] = [ |
||
548 | 'type' => 'line', |
||
549 | 'value' => 'File Link Files...................'.count($linkFiles) |
||
550 | ]; |
||
551 | |||
552 | // Verify all files have a database pointer and a valid file |
||
553 | foreach($linkFiles as $file) |
||
554 | { |
||
555 | // Verify database pointer |
||
556 | if(!in_array($file->file_id, $this->fileArr)) |
||
557 | { |
||
558 | $badPointer++; |
||
559 | $res2[] = [ |
||
560 | 'type' => 'error', |
||
561 | 'value' => ' File ID '.$file->file_id.' missing in files table', |
||
562 | 'repOnly' => true |
||
563 | ]; |
||
564 | |||
565 | if($this->fix) |
||
566 | { |
||
567 | FileLinkFiles::find($file->cust_file_id)->delete(); |
||
568 | $res2[] = [ |
||
569 | 'type' => 'info', |
||
570 | 'value' => ' Corrected', |
||
571 | 'repOnly' => true |
||
572 | ]; |
||
573 | } |
||
574 | } |
||
575 | else |
||
576 | { |
||
577 | // Verify that the file exists |
||
578 | $fileData = Files::find($file->file_id); |
||
579 | if(!Storage::exists($fileData->file_link.$fileData->file_name)) |
||
580 | { |
||
581 | $missingFile++; |
||
582 | $res2[] = [ |
||
583 | 'type' => 'error', |
||
584 | 'value' => ' Missing File ID - '.$fileData->file_id.' - '.$fileData->file_link.$fileData->file_name, |
||
585 | 'repOnly' => true |
||
586 | ]; |
||
587 | |||
588 | if($this->fix) |
||
589 | { |
||
590 | $file->delete(); |
||
591 | $fileData->delete(); |
||
592 | $res2[] = [ |
||
593 | 'type' => 'info', |
||
594 | 'value' => ' Corrected', |
||
595 | 'repOnly' => true |
||
596 | ]; |
||
597 | } |
||
598 | } |
||
599 | $pos = array_search($file->file_id, $this->fileArr); |
||
600 | unset($this->fileArr[$pos]); |
||
601 | } |
||
602 | } |
||
603 | |||
604 | // Error messages if pointer bad or file missing |
||
605 | if($badPointer) |
||
606 | { |
||
607 | $res[] = [ |
||
608 | 'type' => 'error', |
||
609 | 'value' => ' Bad file pointers............'.$badPointer |
||
610 | ]; |
||
611 | if($this->fix) |
||
612 | { |
||
613 | $res[] = [ |
||
614 | 'type' => 'info', |
||
615 | 'value' => ' Corrected' |
||
616 | ]; |
||
617 | } |
||
618 | } |
||
619 | if($missingFile) |
||
620 | { |
||
621 | $res[] = [ |
||
622 | 'type' => 'error', |
||
623 | 'value' => ' Missing Files................'.$missingFile |
||
624 | ]; |
||
625 | if($this->fix) |
||
626 | { |
||
627 | $res[] = [ |
||
628 | 'type' => 'info', |
||
629 | 'value' => ' Corrected' |
||
630 | ]; |
||
631 | } |
||
632 | } |
||
633 | |||
634 | $res = array_merge($res, $res2); |
||
635 | |||
636 | return $res; |
||
637 | } |
||
638 | |||
639 | // Check that all tech tip files exist |
||
640 | private function tipFiles() |
||
641 | { |
||
642 | $res = []; |
||
643 | $res2 = []; |
||
644 | |||
645 | $badPointer = 0; |
||
646 | $missingFile = 0; |
||
647 | |||
648 | $tipFiles = TechTipFiles::all(); |
||
649 | |||
650 | $res[] = [ |
||
651 | 'type' => 'line', |
||
652 | 'value' => 'Tech Tip Files....................'.count($tipFiles) |
||
653 | ]; |
||
654 | |||
655 | // Verify all files have a database pointer and a valid file |
||
656 | foreach($tipFiles as $file) |
||
657 | { |
||
658 | // Verify database pointer |
||
659 | if(!in_array($file->file_id, $this->fileArr)) |
||
660 | { |
||
661 | $badPointer++; |
||
662 | $res2[] = [ |
||
663 | 'type' => 'error', |
||
664 | 'value' => ' File ID '.$file->file_id.' missing in files table', |
||
665 | 'repOnly' => true |
||
666 | ]; |
||
667 | |||
668 | if($this->fix) |
||
669 | { |
||
670 | TechTipFiles::find($file->cust_file_id)->delete(); |
||
671 | $res2[] = [ |
||
672 | 'type' => 'info', |
||
673 | 'value' => ' Corrected', |
||
674 | 'repOnly' => true |
||
675 | ]; |
||
676 | } |
||
677 | } |
||
678 | else |
||
679 | { |
||
680 | // Verify that the file exists |
||
681 | $fileData = Files::find($file->file_id); |
||
682 | if(!Storage::exists($fileData->file_link.$fileData->file_name)) |
||
683 | { |
||
684 | $missingFile++; |
||
685 | $res2[] = [ |
||
686 | 'type' => 'error', |
||
687 | 'value' => ' Missing File ID - '.$fileData->file_id.' - '.$fileData->file_link.$fileData->file_name, |
||
688 | 'repOnly' => true |
||
689 | ]; |
||
690 | |||
691 | if($this->fix) |
||
692 | { |
||
693 | $file->delete(); |
||
694 | $fileData->delete(); |
||
695 | $res2[] = [ |
||
696 | 'type' => 'info', |
||
697 | 'value' => ' Corrected', |
||
698 | 'repOnly' => true |
||
699 | ]; |
||
700 | } |
||
701 | } |
||
702 | $pos = array_search($file->file_id, $this->fileArr); |
||
703 | unset($this->fileArr[$pos]); |
||
704 | } |
||
705 | } |
||
706 | |||
707 | // Error messages if pointer bad or file missing |
||
708 | if($badPointer) |
||
709 | { |
||
710 | $res[] = [ |
||
711 | 'type' => 'error', |
||
712 | 'value' => ' Bad file pointers............'.$badPointer |
||
713 | ]; |
||
714 | if($this->fix) |
||
715 | { |
||
716 | $res[] = [ |
||
717 | 'type' => 'info', |
||
718 | 'value' => ' Corrected' |
||
719 | ]; |
||
720 | } |
||
721 | } |
||
722 | if($missingFile) |
||
723 | { |
||
724 | $res[] = [ |
||
725 | 'type' => 'error', |
||
726 | 'value' => ' Missing Files................'.$missingFile |
||
727 | ]; |
||
728 | if($this->fix) |
||
729 | { |
||
730 | $res[] = [ |
||
731 | 'type' => 'info', |
||
732 | 'value' => ' Corrected' |
||
733 | ]; |
||
734 | } |
||
735 | } |
||
736 | |||
737 | $res = array_merge($res, $res2); |
||
738 | |||
739 | return $res; |
||
740 | } |
||
741 | |||
742 | // Check all remaining file in database that do not have pointers |
||
743 | private function remainingFiles() |
||
744 | { |
||
745 | $res = []; |
||
746 | |||
747 | $res[] = [ |
||
748 | 'type' => count($this->fileArr) > 0 ? 'error' : 'line', |
||
749 | 'value' => 'Unknown Files.....................'.count($this->fileArr) |
||
750 | ]; |
||
751 | |||
752 | if(count($this->fileArr) > 0) |
||
753 | { |
||
754 | foreach($this->fileArr as $file) |
||
755 | { |
||
756 | $fileData = Files::find($file); |
||
757 | |||
758 | $res[] = [ |
||
759 | 'type' => 'line', |
||
760 | 'value' => ' Unknown File ID - '.$fileData->file_id.' - '.$fileData->file_link.$fileData->file_name, |
||
761 | 'repOnly' => true |
||
762 | ]; |
||
763 | |||
764 | if($this->fix) |
||
765 | { |
||
766 | $res[] = [ |
||
767 | 'type' => 'info', |
||
768 | 'value' => ' Corrected', |
||
769 | 'repOnly' => true |
||
770 | ]; |
||
771 | |||
772 | if(!Storage::exists($fileData->file_link.$fileData->file_name)) |
||
773 | { |
||
774 | Storage::delete($fileData->file_link.$fileData->file_name); |
||
775 | } |
||
776 | |||
777 | $fileData->delete(); |
||
778 | |||
779 | } |
||
780 | } |
||
781 | } |
||
782 | |||
783 | |||
784 | /* |
||
785 | |||
786 | if($this->fix && count($this->fileArr) > 0) |
||
787 | { |
||
788 | $res[] = [ |
||
789 | 'type' => 'info', |
||
790 | 'value' => ' Corrected' |
||
791 | ]; |
||
792 | foreach($this->fileArr as $file) |
||
793 | { |
||
794 | $fileData = Files::find($file); |
||
795 | |||
796 | if(!Storage::exists($fileData->file_link.$fileData->file_name)) |
||
797 | { |
||
798 | Storage::delete($fileData->file_link.$fileData->file_name); |
||
799 | } |
||
800 | |||
801 | $res[] = [ |
||
802 | 'type' => 'info', |
||
803 | 'value' => ' File - '.$fileData->file_link.$fileData->file_name.' deleted', |
||
804 | 'repOnly' => true |
||
805 | ]; |
||
806 | |||
807 | $fileData->delete(); |
||
808 | } |
||
809 | } |
||
810 | */ |
||
811 | |||
812 | return $res; |
||
813 | } |
||
814 | |||
815 | // Determine any rogue files that exist but are not in the database |
||
816 | private function rogueFiles() |
||
868 | } |
||
869 | } |
||
870 |