Completed
Pull Request — development (#635)
by Ashutosh
09:42
created

Kernel::execute()   B

Complexity

Conditions 8
Paths 15

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 22
rs 8.4444
c 0
b 0
f 0
cc 8
nc 15
nop 2
1
<?php
2
3
namespace App\Console;
4
5
use App\Model\Common\StatusSetting;
6
use App\Model\Mailjob\ActivityLogDay;
7
use Illuminate\Console\Scheduling\Schedule;
8
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
9
10
class Kernel extends ConsoleKernel
11
{
12
    /**
13
     * The Artisan commands provided by your application.
14
     *
15
     * @var array
16
     */
17
    protected $commands = [
18
        //
19
         'App\Console\Commands\Inspire',
20
         \App\Console\Commands\Install::class,
21
        'App\Console\Commands\ExpiryCron',
22
    ];
23
24
    /**
25
     * Define the application's command schedule.
26
     *
27
     * @param \Illuminate\Console\Scheduling\Schedule $schedule
28
     *
29
     * @return void
30
     */
31
    protected function schedule(Schedule $schedule)
32
    {
33
        $this->execute($schedule, 'expiryMail');
34
        $this->execute($schedule, 'deleteLogs');
35
    }
36
37
    public function execute($schedule, $task)
38
    {
39
        $env = base_path('.env');
40
        if (\File::exists($env) && (env('DB_INSTALL') == 1)) {
41
            $expiryMailStatus = StatusSetting::pluck('expiry_mail')->first();
42
            $logDeleteStatus = StatusSetting::pluck('activity_log_delete')->first();
43
            $delLogDays = ActivityLogDay::pluck('days')->first();
44
            if ($delLogDays == null) {
45
                $delLogDays = 99999999;
46
            }
47
            \Config::set('activitylog.delete_records_older_than_days', $delLogDays);
48
            $condition = new \App\Model\Mailjob\Condition();
49
            $command = $condition->getConditionValue($task);
50
            switch ($task) {
51
            case 'expiryMail':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
52
               if ($expiryMailStatus == 1) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
53
                   return $this->getCondition($schedule->command('expiry:notification'), $command);
54
               }
55
56
            case 'deleteLogs':
57
             if ($logDeleteStatus == 1) {
58
                 return $this->getCondition($schedule->command('activitylog:clean'), $command);
59
             }
60
            }
61
        }
62
    }
63
64
    public function getCondition($schedule, $command)
65
    {
66
        $condition = $command['condition'];
67
        $at = $command['at'];
68
        switch ($condition) {
69
            case 'everyMinute':
70
                return $schedule->everyMinute();
71
            case 'everyFiveMinutes':
72
                return $schedule->everyFiveMinutes();
73
            case 'everyTenMinutes':
74
                return $schedule->everyTenMinutes();
75
            case 'everyThirtyMinutes':
76
                return $schedule->everyThirtyMinutes();
77
            case 'hourly':
78
                return $schedule->hourly();
79
            case 'daily':
80
                return $schedule->daily();
81
            case 'dailyAt':
82
                return $this->getConditionWithOption($schedule, $condition, $at);
83
            case 'weekly':
84
                return $schedule->weekly();
85
            case 'monthly':
86
                return $schedule->monthly();
87
            case 'yearly':
88
                return $schedule->yearly();
89
            default:
90
                return $schedule->everyMinute();
91
        }
92
    }
93
94
    public function getConditionWithOption($schedule, $command, $at)
95
    {
96
        switch ($command) {
97
            case 'dailyAt':
98
                return $schedule->dailyAt($at);
99
        }
100
    }
101
102
    /**
103
     * Register the Closure based commands for the application.
104
     *
105
     * @return void
106
     */
107
    protected function commands()
108
    {
109
        require base_path('routes/console.php');
110
    }
111
}
112