SetIssuesDatesForPackages   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
c 2
b 0
f 0
dl 0
loc 43
ccs 0
cts 21
cp 0
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 26 1
1
<?php
2
3
4
namespace MyriadDataStore\Console\Commands;
5
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Facades\DB;
8
9
class SetIssuesDatesForPackages extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'myriad-download:set-issues-dates-for-packages';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = '';
24
25
26
    public function handle(): int
27
    {
28
        $tableOrderPackages = config('myriad-data-store.tables.order_packages');
29
        $tableIssues        = config('myriad-data-store.tables.issues');
30
        DB::statement("
31
            UPDATE {$tableOrderPackages}
32
            LEFT JOIN {$tableIssues} ON
33
                        {$tableOrderPackages}.title_id = {$tableIssues}.title_id
34
                         AND {$tableOrderPackages}.start_issue = {$tableIssues}.name
35
            SET {$tableOrderPackages}.start_issue_dn = {$tableIssues}.publication_date
36
            WHERE true;
37
        ");
38
39
        DB::statement("
40
            UPDATE {$tableOrderPackages}
41
            LEFT JOIN {$tableIssues} ON
42
                        {$tableOrderPackages}.title_id = {$tableIssues}.title_id
43
                         AND {$tableOrderPackages}.end_issue = {$tableIssues}.name
44
            LEFT JOIN {$tableIssues} as mi ON
45
                        {$tableOrderPackages}.title_id = mi.title_id
46
                         AND {$tableOrderPackages}.start_issue = mi.name
47
            SET {$tableOrderPackages}.end_issue_dn = IF({$tableIssues}.publication_date IS NULL, mi.publication_date, {$tableIssues}.publication_date)
48
            WHERE true;
49
        ");
50
51
        return 0;
52
    }
53
}
54