@@ -16,9 +16,15 @@ |
||
| 16 | 16 | } |
| 17 | 17 | $timeparts = array_map('intval', explode(':', $time)); |
| 18 | 18 | |
| 19 | - if(isset($timeparts[0])) $this->setHours($timeparts[0]); |
|
| 20 | - if(isset($timeparts[1])) $this->setMinutes($timeparts[1]); |
|
| 21 | - if(isset($timeparts[2])) $this->setSeconds($timeparts[2]); |
|
| 19 | + if(isset($timeparts[0])) { |
|
| 20 | + $this->setHours($timeparts[0]); |
|
| 21 | + } |
|
| 22 | + if(isset($timeparts[1])) { |
|
| 23 | + $this->setMinutes($timeparts[1]); |
|
| 24 | + } |
|
| 25 | + if(isset($timeparts[2])) { |
|
| 26 | + $this->setSeconds($timeparts[2]); |
|
| 27 | + } |
|
| 22 | 28 | } |
| 23 | 29 | |
| 24 | 30 | /** |
@@ -10,15 +10,15 @@ discard block |
||
| 10 | 10 | public function __construct($time = '') { |
| 11 | 11 | |
| 12 | 12 | $time = trim($time); |
| 13 | - if(empty($time)) { |
|
| 13 | + if (empty($time)) { |
|
| 14 | 14 | \App\BxConsole\EnvHelper::timeZoneSet(); |
| 15 | 15 | $time = date("H:i:s"); |
| 16 | 16 | } |
| 17 | 17 | $timeparts = array_map('intval', explode(':', $time)); |
| 18 | 18 | |
| 19 | - if(isset($timeparts[0])) $this->setHours($timeparts[0]); |
|
| 20 | - if(isset($timeparts[1])) $this->setMinutes($timeparts[1]); |
|
| 21 | - if(isset($timeparts[2])) $this->setSeconds($timeparts[2]); |
|
| 19 | + if (isset($timeparts[0])) $this->setHours($timeparts[0]); |
|
| 20 | + if (isset($timeparts[1])) $this->setMinutes($timeparts[1]); |
|
| 21 | + if (isset($timeparts[2])) $this->setSeconds($timeparts[2]); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $timeparts = []; |
| 39 | 39 | $timeparts[] = sprintf("%02d", $this->hours); |
| 40 | 40 | $timeparts[] = sprintf("%02d", $this->minutes); |
| 41 | - if($seconds) { |
|
| 41 | + if ($seconds) { |
|
| 42 | 42 | $timeparts[] = sprintf("%02d", $this->seconds); |
| 43 | 43 | } |
| 44 | 44 | return join(':', $timeparts); |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | public function setHours(int $hours): void |
| 75 | 75 | { |
| 76 | 76 | $hours = (int) $hours; |
| 77 | - if($hours < 0) { |
|
| 77 | + if ($hours < 0) { |
|
| 78 | 78 | $hours = 0; |
| 79 | - } else if($hours > 23) { |
|
| 79 | + } else if ($hours > 23) { |
|
| 80 | 80 | $hours = 23; |
| 81 | 81 | } |
| 82 | 82 | $this->hours = $hours; |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | public function setMinutes(int $minutes): void |
| 89 | 89 | { |
| 90 | 90 | $minutes = (int) $minutes; |
| 91 | - if($minutes < 0) { |
|
| 91 | + if ($minutes < 0) { |
|
| 92 | 92 | $minutes = 0; |
| 93 | - } else if($minutes > 59) { |
|
| 93 | + } else if ($minutes > 59) { |
|
| 94 | 94 | $minutes = 59; |
| 95 | 95 | } |
| 96 | 96 | $this->minutes = $minutes; |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | public function setSeconds(int $seconds): void |
| 103 | 103 | { |
| 104 | 104 | $seconds = (int) $seconds; |
| 105 | - if($seconds < 0) { |
|
| 105 | + if ($seconds < 0) { |
|
| 106 | 106 | $seconds = 0; |
| 107 | - } else if($seconds > 59) { |
|
| 107 | + } else if ($seconds > 59) { |
|
| 108 | 108 | $seconds = 59; |
| 109 | 109 | } |
| 110 | 110 | $this->seconds = $seconds; |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | public static function validateTimeString($str): ?string |
| 114 | 114 | { |
| 115 | 115 | $str = trim($str); |
| 116 | - if(strpos($str, ':') !== false) { |
|
| 116 | + if (strpos($str, ':') !== false) { |
|
| 117 | 117 | $timeParts = explode(':', $str); |
| 118 | - if(count($timeParts) == 2) { |
|
| 118 | + if (count($timeParts) == 2) { |
|
| 119 | 119 | $timeParts[2] = '00'; |
| 120 | 120 | } |
| 121 | 121 | $str = join(':', $timeParts); |
| 122 | - if(preg_match("/^(?:2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9]$/", $str)) { |
|
| 122 | + if (preg_match("/^(?:2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9]$/", $str)) { |
|
| 123 | 123 | return $str; |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -129,33 +129,33 @@ discard block |
||
| 129 | 129 | public static function inInterval($minStrTime, $maxStrTime, $checkStrTime = ''): bool |
| 130 | 130 | { |
| 131 | 131 | $minTime = new self($minStrTime); |
| 132 | - if($maxStrTime == '00:00') { |
|
| 132 | + if ($maxStrTime == '00:00') { |
|
| 133 | 133 | $maxStrTime = '23:59'; |
| 134 | 134 | } |
| 135 | 135 | $maxTime = new self($maxStrTime); |
| 136 | 136 | $checkTime = new self($checkStrTime); |
| 137 | 137 | |
| 138 | - if($minTime->getHours() == $checkTime->getHours()) { |
|
| 139 | - if($minTime->getMinutes() == $checkTime->getMinutes()) { |
|
| 140 | - if($minTime->getSeconds() > $checkTime->getSeconds()) { |
|
| 138 | + if ($minTime->getHours() == $checkTime->getHours()) { |
|
| 139 | + if ($minTime->getMinutes() == $checkTime->getMinutes()) { |
|
| 140 | + if ($minTime->getSeconds() > $checkTime->getSeconds()) { |
|
| 141 | 141 | return false; |
| 142 | 142 | } |
| 143 | - } else if($minTime->getMinutes() > $checkTime->getMinutes()) { |
|
| 143 | + } else if ($minTime->getMinutes() > $checkTime->getMinutes()) { |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | - } else if($minTime->getHours() > $checkTime->getHours()) { |
|
| 146 | + } else if ($minTime->getHours() > $checkTime->getHours()) { |
|
| 147 | 147 | return false; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if($maxTime->getHours() == $checkTime->getHours()) { |
|
| 151 | - if($maxTime->getMinutes() == $checkTime->getMinutes()) { |
|
| 152 | - if($minTime->getSeconds() < $checkTime->getSeconds()) { |
|
| 150 | + if ($maxTime->getHours() == $checkTime->getHours()) { |
|
| 151 | + if ($maxTime->getMinutes() == $checkTime->getMinutes()) { |
|
| 152 | + if ($minTime->getSeconds() < $checkTime->getSeconds()) { |
|
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | - } else if($maxTime->getMinutes() < $checkTime->getMinutes()) { |
|
| 155 | + } else if ($maxTime->getMinutes() < $checkTime->getMinutes()) { |
|
| 156 | 156 | return false; |
| 157 | 157 | } |
| 158 | - } else if($maxTime->getHours() < $checkTime->getHours()) { |
|
| 158 | + } else if ($maxTime->getHours() < $checkTime->getHours()) { |
|
| 159 | 159 | return false; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -101,7 +101,9 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | foreach($jobs as $cmd => $job) { |
| 103 | 103 | $execTime = $job['last_exec']; |
| 104 | - if($execTime > $lastExec) $lastExec = $execTime; |
|
| 104 | + if($execTime > $lastExec) { |
|
| 105 | + $lastExec = $execTime; |
|
| 106 | + } |
|
| 105 | 107 | if(!empty($job['error'])) { |
| 106 | 108 | $hasError = true; |
| 107 | 109 | } |
@@ -132,7 +134,9 @@ discard block |
||
| 132 | 134 | |
| 133 | 135 | $cnt = 1; |
| 134 | 136 | foreach($jobs as $cmd => $job) { |
| 135 | - if($cnt > 1) $table->addRow(new TableSeparator()); |
|
| 137 | + if($cnt > 1) { |
|
| 138 | + $table->addRow(new TableSeparator()); |
|
| 139 | + } |
|
| 136 | 140 | $row = [ |
| 137 | 141 | $cmd, |
| 138 | 142 | $job['period'], |
@@ -40,45 +40,45 @@ discard block |
||
| 40 | 40 | set_time_limit(EnvHelper::getCrontabTimeout()); |
| 41 | 41 | |
| 42 | 42 | $logger = EnvHelper::getLogger('bx_cron'); |
| 43 | - if($logger) { |
|
| 43 | + if ($logger) { |
|
| 44 | 44 | $this->setLogger($logger); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $showStatus = $input->getOption('status'); |
| 48 | 48 | $byTime = $input->getOption('bytime'); |
| 49 | - if($showStatus) { |
|
| 49 | + if ($showStatus) { |
|
| 50 | 50 | $sort = ($byTime ? self::SORT_TIME : self::SORT_NAME); |
| 51 | 51 | $this->showStatus($output, $sort); |
| 52 | 52 | return 0; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if(EnvHelper::getSwitch('BX_CRONTAB_RUN', EnvHelper::SWITCH_STATE_OFF)) { |
|
| 56 | - if($this->logger) { |
|
| 55 | + if (EnvHelper::getSwitch('BX_CRONTAB_RUN', EnvHelper::SWITCH_STATE_OFF)) { |
|
| 56 | + if ($this->logger) { |
|
| 57 | 57 | $this->logger->alert('BxCron switch off'); |
| 58 | 58 | } |
| 59 | 59 | return 0; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if(!$this->lock()) { |
|
| 62 | + if (!$this->lock()) { |
|
| 63 | 63 | $msg = 'The command is already running in another process.'; |
| 64 | 64 | $output->writeln($msg); |
| 65 | - if($this->logger) { |
|
| 65 | + if ($this->logger) { |
|
| 66 | 66 | $this->logger->warning($msg); |
| 67 | 67 | } |
| 68 | 68 | return 0; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if($sleepInterval = EnvHelper::checkSleepInterval()) { |
|
| 71 | + if ($sleepInterval = EnvHelper::checkSleepInterval()) { |
|
| 72 | 72 | $msg = sprintf("Sleep in interval %s", $sleepInterval); |
| 73 | 73 | $output->writeln($msg); |
| 74 | - if($this->logger) { |
|
| 74 | + if ($this->logger) { |
|
| 75 | 75 | $this->logger->warning($msg); |
| 76 | 76 | } |
| 77 | 77 | return 0; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | $clean = $input->getOption('clean'); |
| 81 | - if($clean) { |
|
| 81 | + if ($clean) { |
|
| 82 | 82 | $command = $this->getApplication()->find($clean); |
| 83 | 83 | $this->cleanJob($command->getName()); |
| 84 | 84 | $output->writeln($command->getName() . " will be executed now"); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $cleanAll = $input->getOption('all'); |
| 89 | - if($cleanAll) { |
|
| 89 | + if ($cleanAll) { |
|
| 90 | 90 | $this->cleanJob(); |
| 91 | 91 | $output->writeln("All commands will be executed now"); |
| 92 | 92 | return 0; |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | $lastExec = 0; |
| 112 | 112 | $hasError = false; |
| 113 | 113 | |
| 114 | - foreach($jobs as $cmd => $job) { |
|
| 114 | + foreach ($jobs as $cmd => $job) { |
|
| 115 | 115 | $execTime = $job['last_exec']; |
| 116 | - if($execTime > $lastExec) $lastExec = $execTime; |
|
| 117 | - if(!empty($job['error'])) { |
|
| 116 | + if ($execTime > $lastExec) $lastExec = $execTime; |
|
| 117 | + if (!empty($job['error'])) { |
|
| 118 | 118 | $hasError = true; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | 'Status', |
| 134 | 134 | ]; |
| 135 | 135 | |
| 136 | - if($hasError) { |
|
| 136 | + if ($hasError) { |
|
| 137 | 137 | $header[] = 'Error'; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -143,15 +143,15 @@ discard block |
||
| 143 | 143 | ]); |
| 144 | 144 | |
| 145 | 145 | $cnt = 1; |
| 146 | - foreach($jobs as $cmd => $job) { |
|
| 147 | - if($cnt > 1) $table->addRow(new TableSeparator()); |
|
| 146 | + foreach ($jobs as $cmd => $job) { |
|
| 147 | + if ($cnt > 1) $table->addRow(new TableSeparator()); |
|
| 148 | 148 | $row = [ |
| 149 | 149 | $cmd, |
| 150 | 150 | $job['period'], |
| 151 | 151 | ($job['last_exec'] ? date("d.m.Y H:i:s", $job['last_exec']) : 'NONE'), |
| 152 | 152 | $job['status'], |
| 153 | 153 | ]; |
| 154 | - if($hasError) { |
|
| 154 | + if ($hasError) { |
|
| 155 | 155 | $row[] = $job['error']; |
| 156 | 156 | } |
| 157 | 157 | $table->addRow($row); |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | $crontab = []; |
| 167 | 167 | |
| 168 | - if($command) { |
|
| 168 | + if ($command) { |
|
| 169 | 169 | $crontab = $this->getCronTab(); |
| 170 | - if($crontab === false) { |
|
| 170 | + if ($crontab === false) { |
|
| 171 | 171 | return false; |
| 172 | 172 | } |
| 173 | 173 | unset($crontab[$command]); |
@@ -182,12 +182,12 @@ discard block |
||
| 182 | 182 | $allTimeout = EnvHelper::getCrontabTimeout(); |
| 183 | 183 | $workTime = 0; |
| 184 | 184 | |
| 185 | - if(!empty($jobs)) { |
|
| 185 | + if (!empty($jobs)) { |
|
| 186 | 186 | |
| 187 | - foreach($jobs as $cmd => $job) { |
|
| 187 | + foreach ($jobs as $cmd => $job) { |
|
| 188 | 188 | |
| 189 | 189 | $job['cmd'] = $cmd; |
| 190 | - if($this->isActualJob($job)) { |
|
| 190 | + if ($this->isActualJob($job)) { |
|
| 191 | 191 | |
| 192 | 192 | $job['status'] = self::EXEC_STATUS_WORK; |
| 193 | 193 | $job['start_time'] = time(); |
@@ -202,12 +202,12 @@ discard block |
||
| 202 | 202 | $returnCode = $command->run($cmdInput, $output); |
| 203 | 203 | $execTime = microtime(true) - $timeStart; |
| 204 | 204 | |
| 205 | - if(!$returnCode) { |
|
| 205 | + if (!$returnCode) { |
|
| 206 | 206 | |
| 207 | 207 | $job['status'] = self::EXEC_STATUS_SUCCESS; |
| 208 | 208 | |
| 209 | 209 | $msg = sprintf("%s: SUCCESS [%.2f s]", $cmd, $execTime); |
| 210 | - if($this->logger) { |
|
| 210 | + if ($this->logger) { |
|
| 211 | 211 | $this->logger->alert($msg); |
| 212 | 212 | } |
| 213 | 213 | $output->writeln(PHP_EOL . $msg); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $job['error_code'] = $returnCode; |
| 219 | 219 | |
| 220 | 220 | $msg = sprintf("%s: ERROR [%.2f s]", $cmd, $execTime); |
| 221 | - if($this->logger) { |
|
| 221 | + if ($this->logger) { |
|
| 222 | 222 | $this->logger->alert($msg); |
| 223 | 223 | } |
| 224 | 224 | $output->writeln(PHP_EOL . $msg); |
@@ -230,14 +230,14 @@ discard block |
||
| 230 | 230 | $job['error'] = $e->getMessage(); |
| 231 | 231 | |
| 232 | 232 | |
| 233 | - if($this->logger) { |
|
| 233 | + if ($this->logger) { |
|
| 234 | 234 | $this->logger->error($e, ['command' => $cmd]); |
| 235 | 235 | } |
| 236 | 236 | $output->writeln(PHP_EOL . 'ERROR: ' . $e->getMessage()); |
| 237 | 237 | |
| 238 | 238 | } finally { |
| 239 | 239 | |
| 240 | - if(!$execTime) { |
|
| 240 | + if (!$execTime) { |
|
| 241 | 241 | $execTime = microtime(true) - $timeStart; |
| 242 | 242 | } |
| 243 | 243 | $job['last_exec'] = time(); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $this->updateJob($cmd, $job); |
| 248 | 248 | |
| 249 | 249 | $workTime += $execTime; |
| 250 | - if($workTime * 2 > $allTimeout) { |
|
| 250 | + if ($workTime * 2 > $allTimeout) { |
|
| 251 | 251 | break; |
| 252 | 252 | } |
| 253 | 253 | /* |
@@ -263,31 +263,31 @@ discard block |
||
| 263 | 263 | { |
| 264 | 264 | $actual = false; |
| 265 | 265 | |
| 266 | - if($job['status'] == self::EXEC_STATUS_WORK) { |
|
| 267 | - if($job['start_time'] && $job['start_time'] < (time() - self::RESTART_TIME)) { |
|
| 266 | + if ($job['status'] == self::EXEC_STATUS_WORK) { |
|
| 267 | + if ($job['start_time'] && $job['start_time'] < (time() - self::RESTART_TIME)) { |
|
| 268 | 268 | $actual = true; |
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | $period = intval($job['period']); |
| 273 | 273 | |
| 274 | - if($period > 0) { |
|
| 275 | - if(time() - $job['last_exec'] >= $period) { |
|
| 274 | + if ($period > 0) { |
|
| 275 | + if (time() - $job['last_exec'] >= $period) { |
|
| 276 | 276 | $actual = true; |
| 277 | 277 | } |
| 278 | - } else if(!empty($job['times'])) { |
|
| 278 | + } else if (!empty($job['times'])) { |
|
| 279 | 279 | //TODO: |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if($actual && !empty($job['interval'])) { |
|
| 282 | + if ($actual && !empty($job['interval'])) { |
|
| 283 | 283 | $times = explode('-', $job['interval']); |
| 284 | - if(count($times) == 2) { |
|
| 284 | + if (count($times) == 2) { |
|
| 285 | 285 | $minTime = Time24::validateTimeString($times[0]); |
| 286 | 286 | $maxTime = Time24::validateTimeString($times[1]); |
| 287 | - if($minTime && $maxTime) { |
|
| 288 | - if(!Time24::inInterval($minTime, $maxTime)) { |
|
| 287 | + if ($minTime && $maxTime) { |
|
| 288 | + if (!Time24::inInterval($minTime, $maxTime)) { |
|
| 289 | 289 | $msg = sprintf("%s not in interval %s", $job['cmd'], $job['interval']); |
| 290 | - if($this->logger) { |
|
| 290 | + if ($this->logger) { |
|
| 291 | 291 | $this->logger->alert($msg); |
| 292 | 292 | } |
| 293 | 293 | return false; |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | public function getCronJobs(): array |
| 302 | 302 | { |
| 303 | 303 | $crontab = $this->getCronTab(); |
| 304 | - if($crontab === false) { |
|
| 304 | + if ($crontab === false) { |
|
| 305 | 305 | return []; |
| 306 | 306 | } |
| 307 | 307 | |
@@ -311,9 +311,9 @@ discard block |
||
| 311 | 311 | $commands = $app->all(); |
| 312 | 312 | |
| 313 | 313 | $selfCommands = []; |
| 314 | - foreach($commands as $command) { |
|
| 314 | + foreach ($commands as $command) { |
|
| 315 | 315 | /** @var BxCommand $command */ |
| 316 | - if($command instanceof BxCommand) { |
|
| 316 | + if ($command instanceof BxCommand) { |
|
| 317 | 317 | $name = $command->getName(); |
| 318 | 318 | $selfCommands[$name] = [ |
| 319 | 319 | 'object' => $command, |
@@ -323,19 +323,19 @@ discard block |
||
| 323 | 323 | |
| 324 | 324 | $agents = []; |
| 325 | 325 | $reader = new AnnotationReader(); |
| 326 | - foreach($selfCommands as $cmd => $selfCommand) { |
|
| 326 | + foreach ($selfCommands as $cmd => $selfCommand) { |
|
| 327 | 327 | $reflectionClass = new \ReflectionClass($selfCommand['object']); |
| 328 | 328 | $annotations = $reader->getClassAnnotations($reflectionClass); |
| 329 | 329 | |
| 330 | - foreach($annotations as $annotation) { |
|
| 331 | - if($annotation instanceof Agent) { |
|
| 330 | + foreach ($annotations as $annotation) { |
|
| 331 | + if ($annotation instanceof Agent) { |
|
| 332 | 332 | $agents[$cmd] = $annotation->toArray(); |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - foreach($crontab as $cmd => $job) { |
|
| 338 | - if(is_array($job) && isset($agents[$cmd])) { |
|
| 337 | + foreach ($crontab as $cmd => $job) { |
|
| 338 | + if (is_array($job) && isset($agents[$cmd])) { |
|
| 339 | 339 | $agents[$cmd] = array_merge($job, $agents[$cmd]); |
| 340 | 340 | } |
| 341 | 341 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | $crontab = $this->getCronTab(); |
| 356 | 356 | |
| 357 | - if($crontab === false) { |
|
| 357 | + if ($crontab === false) { |
|
| 358 | 358 | return false; |
| 359 | 359 | } else { |
| 360 | 360 | $crontab = array_merge($crontab, $changedAgents); |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | $fh = fopen($filename, 'c'); |
| 373 | 373 | if (flock($fh, LOCK_EX)) { |
| 374 | 374 | ftruncate($fh, 0); |
| 375 | - if(!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) { |
|
| 375 | + if (!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) { |
|
| 376 | 376 | throw new \Exception('Unable to write BX_CRONTAB : ' . $filename); |
| 377 | 377 | } |
| 378 | 378 | } else { |
@@ -392,16 +392,16 @@ discard block |
||
| 392 | 392 | $filename = EnvHelper::getCrontabFile(); |
| 393 | 393 | |
| 394 | 394 | $fh = fopen($filename, 'r'); |
| 395 | - if(!$fh) { |
|
| 395 | + if (!$fh) { |
|
| 396 | 396 | return false; |
| 397 | 397 | } |
| 398 | - if(flock($fh, LOCK_SH)) { |
|
| 398 | + if (flock($fh, LOCK_SH)) { |
|
| 399 | 399 | $cronTab = []; |
| 400 | 400 | clearstatcache(); |
| 401 | 401 | $filesize = (int) filesize($filename); |
| 402 | - if($filesize > 0 && $data = fread($fh, $filesize)) { |
|
| 402 | + if ($filesize > 0 && $data = fread($fh, $filesize)) { |
|
| 403 | 403 | $decoded = json_decode($data, true); |
| 404 | - if(is_array($decoded)) { |
|
| 404 | + if (is_array($decoded)) { |
|
| 405 | 405 | $cronTab = $decoded; |
| 406 | 406 | } else { |
| 407 | 407 | throw new \Exception("Unable to parse cronTab"); |
@@ -418,14 +418,14 @@ discard block |
||
| 418 | 418 | |
| 419 | 419 | protected function sortCronTab(array &$crontab, $sort = self::SORT_NAME) { |
| 420 | 420 | |
| 421 | - if($sort == self::SORT_TIME) { |
|
| 421 | + if ($sort == self::SORT_TIME) { |
|
| 422 | 422 | $sorting = []; |
| 423 | - foreach($crontab as $cmd => $data) { |
|
| 423 | + foreach ($crontab as $cmd => $data) { |
|
| 424 | 424 | $sorting[$cmd] = $data['last_exec']; |
| 425 | 425 | } |
| 426 | 426 | arsort($sorting, SORT_NUMERIC); |
| 427 | 427 | $sorted = []; |
| 428 | - foreach($sorting as $cmd => $time) { |
|
| 428 | + foreach ($sorting as $cmd => $time) { |
|
| 429 | 429 | $sorted[$cmd] = $crontab[$cmd]; |
| 430 | 430 | } |
| 431 | 431 | $crontab = $sorted; |
@@ -18,10 +18,10 @@ discard block |
||
| 18 | 18 | public static function loadEnv() { |
| 19 | 19 | |
| 20 | 20 | $envFile = realpath(__DIR__ . '/../../../../.env'); |
| 21 | - if(!is_file($envFile)) { |
|
| 21 | + if (!is_file($envFile)) { |
|
| 22 | 22 | $envFile = realpath(__DIR__ . '/../../../../../.env'); |
| 23 | 23 | } |
| 24 | - if(is_file($envFile)) { |
|
| 24 | + if (is_file($envFile)) { |
|
| 25 | 25 | try { |
| 26 | 26 | $env = new \Symfony\Component\Dotenv\Dotenv(); |
| 27 | 27 | $env->load($envFile); |
@@ -36,19 +36,19 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public static function getDocumentRoot() { |
| 38 | 38 | |
| 39 | - if(isset($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['DOCUMENT_ROOT'])) { |
|
| 39 | + if (isset($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['DOCUMENT_ROOT'])) { |
|
| 40 | 40 | return $_SERVER['DOCUMENT_ROOT']; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if(isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) { |
|
| 43 | + if (isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) { |
|
| 44 | 44 | $_SERVER['DOCUMENT_ROOT'] = $_ENV['APP_DOCUMENT_ROOT']; |
| 45 | 45 | return $_SERVER['DOCUMENT_ROOT']; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | $composerFile = realpath(__DIR__ . '/../../../../composer.json'); |
| 49 | - if(is_file($composerFile)) { |
|
| 49 | + if (is_file($composerFile)) { |
|
| 50 | 50 | $composerConfig = json_decode(file_get_contents($composerFile), true); |
| 51 | - if(isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) { |
|
| 51 | + if (isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) { |
|
| 52 | 52 | $_SERVER['DOCUMENT_ROOT'] = $composerConfig['extra']['document-root']; |
| 53 | 53 | return $_SERVER['DOCUMENT_ROOT']; |
| 54 | 54 | } |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public static function getLogger($channel) { |
| 67 | 67 | |
| 68 | - if(isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) { |
|
| 68 | + if (isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) { |
|
| 69 | 69 | $logClass = $_ENV['APP_LOG_CLASS']; |
| 70 | 70 | $log = new $logClass($channel); |
| 71 | - if($log instanceof LoggerInterface) { |
|
| 71 | + if ($log instanceof LoggerInterface) { |
|
| 72 | 72 | return $log; |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public static function getCrontabFile() { |
| 83 | 83 | |
| 84 | - if(isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) { |
|
| 84 | + if (isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) { |
|
| 85 | 85 | return rtrim($_ENV['BX_CRONTAB_FOLDER'], "/") . '/bx_crontab.json'; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | public static function getCrontabTimeout() { |
| 92 | 92 | |
| 93 | - if(isset($_ENV['BX_CRONTAB_TIMEOUT']) && is_numeric($_ENV['BX_CRONTAB_TIMEOUT'])) { |
|
| 93 | + if (isset($_ENV['BX_CRONTAB_TIMEOUT']) && is_numeric($_ENV['BX_CRONTAB_TIMEOUT'])) { |
|
| 94 | 94 | return (int) $_ENV['BX_CRONTAB_TIMEOUT']; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | public static function getBxCrontabPeriod() { |
| 101 | 101 | |
| 102 | - if(isset($_ENV['BX_CRONTAB_PERIOD']) && is_numeric($_ENV['BX_CRONTAB_PERIOD'])) { |
|
| 102 | + if (isset($_ENV['BX_CRONTAB_PERIOD']) && is_numeric($_ENV['BX_CRONTAB_PERIOD'])) { |
|
| 103 | 103 | return (int) $_ENV['BX_CRONTAB_PERIOD']; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | public static function getSwitch($name, $state) { |
| 110 | 110 | |
| 111 | - if(isset($_ENV[$name])) { |
|
| 111 | + if (isset($_ENV[$name])) { |
|
| 112 | 112 | |
| 113 | 113 | $val = strtolower(trim($_ENV[$name])); |
| 114 | - if($state == self::SWITCH_STATE_ON) { |
|
| 115 | - if($val === self::SWITCH_STATE_ON || $val === '1' || $val === 'true') { |
|
| 114 | + if ($state == self::SWITCH_STATE_ON) { |
|
| 115 | + if ($val === self::SWITCH_STATE_ON || $val === '1' || $val === 'true') { |
|
| 116 | 116 | return true; |
| 117 | 117 | } |
| 118 | - } else if($state == self::SWITCH_STATE_OFF) { |
|
| 119 | - if($val === self::SWITCH_STATE_OFF || $val === '0' || $val === 'false') { |
|
| 118 | + } else if ($state == self::SWITCH_STATE_OFF) { |
|
| 119 | + if ($val === self::SWITCH_STATE_OFF || $val === '0' || $val === 'false') { |
|
| 120 | 120 | return true; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | $timeZone = self::BX_CRONTAB_TIMEZONE; |
| 131 | 131 | |
| 132 | - if(isset($_ENV['BX_CRONTAB_TIMEZONE']) && $_ENV['BX_CRONTAB_TIMEZONE']) { |
|
| 132 | + if (isset($_ENV['BX_CRONTAB_TIMEZONE']) && $_ENV['BX_CRONTAB_TIMEZONE']) { |
|
| 133 | 133 | $timeZone = trim($_ENV['BX_CRONTAB_TIMEZONE']); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -138,17 +138,17 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | public static function checkSleepInterval() { |
| 140 | 140 | |
| 141 | - if(isset($_ENV['BX_CRONTAB_SLEEP_TIME']) && $_ENV['BX_CRONTAB_SLEEP_TIME']) { |
|
| 141 | + if (isset($_ENV['BX_CRONTAB_SLEEP_TIME']) && $_ENV['BX_CRONTAB_SLEEP_TIME']) { |
|
| 142 | 142 | $intervals = explode(',', $_ENV['BX_CRONTAB_SLEEP_TIME']); |
| 143 | - foreach($intervals as $interval) { |
|
| 143 | + foreach ($intervals as $interval) { |
|
| 144 | 144 | $times = explode('-', $interval); |
| 145 | - if(count($times) != 2) { |
|
| 145 | + if (count($times) != 2) { |
|
| 146 | 146 | continue; |
| 147 | 147 | } |
| 148 | 148 | $minTime = Time24::validateTimeString($times[0]); |
| 149 | 149 | $maxTime = Time24::validateTimeString($times[1]); |
| 150 | - if($minTime && $maxTime) { |
|
| 151 | - if(Time24::inInterval($minTime, $maxTime)) { |
|
| 150 | + if ($minTime && $maxTime) { |
|
| 151 | + if (Time24::inInterval($minTime, $maxTime)) { |
|
| 152 | 152 | return $interval; |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | /** @var Command $command */ |
| 12 | 12 | $command = new self(); |
| 13 | 13 | |
| 14 | - if(empty($logFile)) { |
|
| 14 | + if (empty($logFile)) { |
|
| 15 | 15 | $logFile = '/dev/null'; |
| 16 | 16 | } else { |
| 17 | 17 | $logFile = $_ENV['APP_CMD_LOG_PATH'] . $logFile; |
@@ -47,10 +47,10 @@ |
||
| 47 | 47 | /** @var Command $annotation */ |
| 48 | 48 | $annotation = $this->getAnnotation(\App\BxConsole\Annotations\Command::class); |
| 49 | 49 | |
| 50 | - if($annotation) { |
|
| 50 | + if ($annotation) { |
|
| 51 | 51 | $this->setName($annotation->name); |
| 52 | 52 | $this->setDescription($annotation->description); |
| 53 | - if($annotation->help) { |
|
| 53 | + if ($annotation->help) { |
|
| 54 | 54 | $this->setHelp($annotation->help); |
| 55 | 55 | } |
| 56 | 56 | } |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | $this->isBitrixLoaded = $loader->initializeBitrix(); |
| 29 | 29 | |
| 30 | - if($this->isBitrixLoaded) { |
|
| 31 | - foreach($loader->getModulesCommands() as $command) { |
|
| 30 | + if ($this->isBitrixLoaded) { |
|
| 31 | + foreach ($loader->getModulesCommands() as $command) { |
|
| 32 | 32 | $this->add($command); |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | $pas4CliNamespace = EnvHelper::getPsr4CliNamespace(); |
| 37 | 37 | /** @scrutinizer ignore-call */ |
| 38 | 38 | $loaders = ClassLoader::getRegisteredLoaders(); |
| 39 | - if(!empty($loaders)) { |
|
| 39 | + if (!empty($loaders)) { |
|
| 40 | 40 | $loader = current($loaders); |
| 41 | - if($loader instanceof ClassLoader) { |
|
| 41 | + if ($loader instanceof ClassLoader) { |
|
| 42 | 42 | $map = $loader->getClassMap(); |
| 43 | - foreach($map as $class => $path) { |
|
| 44 | - if(strpos($class, $pas4CliNamespace) === 0) { |
|
| 43 | + foreach ($map as $class => $path) { |
|
| 44 | + if (strpos($class, $pas4CliNamespace) === 0) { |
|
| 45 | 45 | try { |
| 46 | 46 | $obj = new $class(); |
| 47 | - if($obj instanceof Command) { |
|
| 47 | + if ($obj instanceof Command) { |
|
| 48 | 48 | $this->add($obj); |
| 49 | 49 | } |
| 50 | 50 | } catch (\Exception $e) { } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | $exitCode = parent::doRun($input, $output); |
| 62 | 62 | |
| 63 | - if($this->isBitrixLoaded) { |
|
| 63 | + if ($this->isBitrixLoaded) { |
|
| 64 | 64 | if ($this->getCommandName($input) === null) { |
| 65 | 65 | $output->writeln(PHP_EOL . sprintf('Using Bitrix <info>kernel v%s</info>.</info>', SM_VERSION), |
| 66 | 66 | OutputInterface::VERBOSITY_VERY_VERBOSE); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | public function initializeBitrix() { |
| 12 | 12 | |
| 13 | - if($this->checkBitrix()) { |
|
| 13 | + if ($this->checkBitrix()) { |
|
| 14 | 14 | |
| 15 | 15 | if (defined('B_PROLOG_INCLUDED') && B_PROLOG_INCLUDED === true) { |
| 16 | 16 | return true; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | define('NOT_CHECK_PERMISSIONS', true); |
| 33 | 33 | require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'; |
| 34 | 34 | |
| 35 | - if(class_exists('\Bitrix\Main\Analytics\Counter')) { |
|
| 35 | + if (class_exists('\Bitrix\Main\Analytics\Counter')) { |
|
| 36 | 36 | \Bitrix\Main\Analytics\Counter::disable(); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | $cliFile = getLocalPath('modules/' . $module['ID'] . '/.cli.php'); |
| 68 | 68 | |
| 69 | - if(!$cliFile) { |
|
| 69 | + if (!$cliFile) { |
|
| 70 | 70 | continue; |
| 71 | 71 | } |
| 72 | 72 | |