Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
UpdateFlyplates | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
handle | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace App\Console\Commands; |
4 | |
5 | use Illuminate\Console\Command; |
6 | use Illuminate\Support\Facades\Log; |
7 | use App\Http\Models\Shortcut; |
8 | use App\Http\Models\Template; |
9 | |
10 | class UpdateFlyplates extends Command |
11 | { |
12 | /** |
13 | * The name and signature of the console command. |
14 | * |
15 | * @var string |
16 | */ |
17 | protected $signature = 'app:update-flyplates'; |
18 | |
19 | /** |
20 | * The console command description. |
21 | * |
22 | * @var string |
23 | */ |
24 | protected $description = 'Update the templates table based on shortcuts'; |
25 | |
26 | /** |
27 | * Execute the console command. |
28 | */ |
29 | public function handle() |
30 | { |
31 | |
32 | $templateUpdates = [ |
33 | '-tf' => [ |
34 | 'html' => '<div>That\'s Fly!</div>', |
35 | 'template_id' => '62978fc6fa71110d3e474904' |
36 | ], |
37 | '-brb' => [ |
38 | 'html' => '<div>Be Right Back</div>', |
39 | 'template_id' => '629fde9dfdf08a50de594416' |
40 | ], |
41 | ]; |
42 | |
43 | foreach ($templateUpdates as $shortcut => $data) { |
44 | |
45 | $template = Template::where('shortcut', $shortcut)->first(); |
46 | |
47 | if ($template) { |
48 | |
49 | $template->html = $data['html']; |
50 | $template->save(); |
51 | |
52 | Log::info("Updated template for shortcut: $shortcut"); |
53 | } else { |
54 | Log::info("No template found for shortcut: $shortcut"); |
55 | } |
56 | |
57 | // Step 2: Update the `Shortcut` model |
58 | $shortcuts = Shortcut::where('shortcut', $shortcut) |
59 | ->where('version', 1) |
60 | ->get(); |
61 | |
62 | if ($shortcuts->isNotEmpty()) { |
63 | foreach ($shortcuts as $shortcut) { |
64 | $shortcut->html = $data['html']; |
65 | $shortcut->save(); |
66 | } |
67 | Log::info("Updated shortcuts(".$shortcuts->count().") for template_id: {$data['template_id']}"); |
68 | } else { |
69 | Log::info("No shortcut found for template_id: {$data['template_id']} with version = 1"); |
70 | } |
71 | |
72 | } |
73 | |
74 | Log::info('Templates and shortcuts update completed.'); |
75 | } |
76 | } |