SetIssuesDatesForPackages::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 18
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 26
ccs 0
cts 21
cp 0
crap 2
rs 9.6666
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