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