@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * @return void |
48 | 48 | */ |
49 | - public function create(){ |
|
49 | + public function create() { |
|
50 | 50 | |
51 | 51 | $schedulePath = app()->path()->schedule(); |
52 | 52 | |
53 | - if(!file_exists($schedulePath)){ |
|
53 | + if (!file_exists($schedulePath)) { |
|
54 | 54 | $this->directory['schedule'] = $schedulePath; |
55 | 55 | $this->file->makeDirectory($this); |
56 | 56 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $this->argument['scheduleClass'] = ucfirst($this->argument['schedule']).''; |
60 | 60 | $this->argument['projectName'] = strtolower($this->projectName()); |
61 | 61 | |
62 | - $this->touch['schedule/schedule']= $schedulePath.'/'.$this->argument['schedule'].'.php'; |
|
62 | + $this->touch['schedule/schedule'] = $schedulePath.'/'.$this->argument['schedule'].'.php'; |
|
63 | 63 | |
64 | 64 | |
65 | 65 | $this->file->touch($this); |
@@ -76,39 +76,39 @@ discard block |
||
76 | 76 | { |
77 | 77 | $this->scheduleJsonFile(); |
78 | 78 | $this->clear(); |
79 | - foreach (JsonHandler::get() as $schedule=>$items){ |
|
80 | - if($schedule!==$this->argument['schedule']){ |
|
81 | - app()->command('schedule register','schedule:'.$schedule); |
|
79 | + foreach (JsonHandler::get() as $schedule=>$items) { |
|
80 | + if ($schedule!==$this->argument['schedule']) { |
|
81 | + app()->command('schedule register', 'schedule:'.$schedule); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | 86 | public function list() |
87 | 87 | { |
88 | - exec('crontab -l',$list); |
|
88 | + exec('crontab -l', $list); |
|
89 | 89 | |
90 | - $this->table->setHeaders(['no','minute','hour','day','month','week','schedule','description']); |
|
90 | + $this->table->setHeaders(['no', 'minute', 'hour', 'day', 'month', 'week', 'schedule', 'description']); |
|
91 | 91 | |
92 | 92 | |
93 | - foreach ($list as $key=>$item){ |
|
93 | + foreach ($list as $key=>$item) { |
|
94 | 94 | |
95 | - if(preg_match('@.*php api schedule run '.strtolower($this->projectName()).'.*@is',$item,$result)){ |
|
96 | - if(isset($result[0])){ |
|
95 | + if (preg_match('@.*php api schedule run '.strtolower($this->projectName()).'.*@is', $item, $result)) { |
|
96 | + if (isset($result[0])) { |
|
97 | 97 | |
98 | 98 | $cron = []; |
99 | 99 | |
100 | - if(preg_match('@(.*)\scd@',$result[0],$cron)){ |
|
101 | - $cron = (isset($cron[1])) ? explode(' ',$cron[1]) : ''; |
|
100 | + if (preg_match('@(.*)\scd@', $result[0], $cron)) { |
|
101 | + $cron = (isset($cron[1])) ? explode(' ', $cron[1]) : ''; |
|
102 | 102 | |
103 | 103 | } |
104 | 104 | |
105 | 105 | $scheduleName = ''; |
106 | 106 | |
107 | - if(preg_match('@schedule\:(.*?)\s@',$result[0],$scheduler)){ |
|
107 | + if (preg_match('@schedule\:(.*?)\s@', $result[0], $scheduler)) { |
|
108 | 108 | $scheduleName = (isset($scheduler[1])) ? $scheduler[1] : ''; |
109 | 109 | |
110 | 110 | $schedulerInstance = $this->scheduleInstance(ucfirst($scheduleName)); |
111 | - $description = ClosureDispatcher::bind($schedulerInstance)->call(function(){ |
|
111 | + $description = ClosureDispatcher::bind($schedulerInstance)->call(function() { |
|
112 | 112 | return $this->description; |
113 | 113 | }); |
114 | 114 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $schedules = Utils::glob(app()->path()->schedule()); |
140 | 140 | |
141 | 141 | |
142 | - if(isset($schedules[$this->argument['schedule']])){ |
|
142 | + if (isset($schedules[$this->argument['schedule']])) { |
|
143 | 143 | |
144 | 144 | $scheduleNamespace = Utils::getNamespace($schedules[$this->argument['schedule']]); |
145 | 145 | $scheduleInstance = app()->resolve($scheduleNamespace); |
@@ -147,20 +147,20 @@ discard block |
||
147 | 147 | $scheduleManager = new ScheduleManager(); |
148 | 148 | $scheduleInstance->when($scheduleManager); |
149 | 149 | |
150 | - $cronScheduler = implode(' ',$scheduleManager->getCronScheduler()); |
|
150 | + $cronScheduler = implode(' ', $scheduleManager->getCronScheduler()); |
|
151 | 151 | |
152 | 152 | $command = $cronScheduler.' cd '.root.' && php api schedule run munch schedule:'.lcfirst($this->argument['schedule']).' >> /dev/null 2>&1'; |
153 | 153 | |
154 | - if($this->cronjob_exists($command)===false){ |
|
154 | + if ($this->cronjob_exists($command)===false) { |
|
155 | 155 | |
156 | 156 | $output = shell_exec('crontab -l'); |
157 | 157 | file_put_contents('/tmp/crontab.txt', $output.''.$command.''.PHP_EOL); |
158 | 158 | exec('crontab /tmp/crontab.txt'); |
159 | 159 | |
160 | 160 | $this->scheduleJsonFile(); |
161 | - JsonHandler::set($this->argument['schedule'].'.namespace',$scheduleNamespace); |
|
162 | - JsonHandler::set($this->argument['schedule'].'.date',date('Y-m-d H:i:s')); |
|
163 | - JsonHandler::set($this->argument['schedule'].'.command',$cronScheduler); |
|
161 | + JsonHandler::set($this->argument['schedule'].'.namespace', $scheduleNamespace); |
|
162 | + JsonHandler::set($this->argument['schedule'].'.date', date('Y-m-d H:i:s')); |
|
163 | + JsonHandler::set($this->argument['schedule'].'.command', $cronScheduler); |
|
164 | 164 | |
165 | 165 | echo $this->info('Cron has been added'); |
166 | 166 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | { |
175 | 175 | $schedules = Utils::glob(app()->path()->schedule()); |
176 | 176 | |
177 | - if(isset($schedules[$this->argument['schedule']])){ |
|
177 | + if (isset($schedules[$this->argument['schedule']])) { |
|
178 | 178 | $scheduleNamespace = Utils::getNamespace($schedules[$this->argument['schedule']]); |
179 | 179 | $scheduleInstance = app()->resolve($scheduleNamespace); |
180 | 180 | |
@@ -186,25 +186,25 @@ discard block |
||
186 | 186 | { |
187 | 187 | $this->clear(); |
188 | 188 | $this->scheduleJsonFile(); |
189 | - foreach (JsonHandler::get() as $schedule=>$items){ |
|
190 | - app()->command('schedule register','schedule:'.lcfirst($schedule)); |
|
189 | + foreach (JsonHandler::get() as $schedule=>$items) { |
|
190 | + app()->command('schedule register', 'schedule:'.lcfirst($schedule)); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - private function cronjob_exists($command){ |
|
194 | + private function cronjob_exists($command) { |
|
195 | 195 | |
196 | - $cronjob_exists=false; |
|
196 | + $cronjob_exists = false; |
|
197 | 197 | |
198 | 198 | exec('crontab -l', $crontab); |
199 | 199 | |
200 | 200 | |
201 | - if(isset($crontab)&&is_array($crontab)){ |
|
201 | + if (isset($crontab) && is_array($crontab)) { |
|
202 | 202 | |
203 | 203 | $crontab = array_flip($crontab); |
204 | 204 | |
205 | - if(isset($crontab[$command])){ |
|
205 | + if (isset($crontab[$command])) { |
|
206 | 206 | |
207 | - $cronjob_exists=true; |
|
207 | + $cronjob_exists = true; |
|
208 | 208 | |
209 | 209 | } |
210 | 210 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | { |
221 | 221 | $schedules = Utils::glob(app()->path()->schedule()); |
222 | 222 | |
223 | - if(isset($schedules[$schedule])){ |
|
223 | + if (isset($schedules[$schedule])) { |
|
224 | 224 | $scheduleNamespace = Utils::getNamespace($schedules[$schedule]); |
225 | 225 | return $scheduleInstance = app()->resolve($scheduleNamespace); |
226 | 226 | } |