@@ -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 | /** |
16 | 16 | * Declare global legacy variables |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | $cliFile = getLocalPath('modules/' . $module['ID'] . '/cli.php'); |
55 | 55 | |
56 | - if(!$cliFile) { |
|
56 | + if (!$cliFile) { |
|
57 | 57 | continue; |
58 | 58 | } |
59 | 59 |
@@ -47,7 +47,7 @@ |
||
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 | 53 | $this->setHelp($annotation->help); |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | |
26 | 26 | $this->isBitrixLoaded = $loader->initializeBitrix(); |
27 | 27 | |
28 | - if($this->isBitrixLoaded) { |
|
29 | - foreach($loader->getModulesCommands() as $command) { |
|
28 | + if ($this->isBitrixLoaded) { |
|
29 | + foreach ($loader->getModulesCommands() as $command) { |
|
30 | 30 | $this->add($command); |
31 | 31 | } |
32 | 32 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | $exitCode = parent::doRun($input, $output); |
40 | 40 | |
41 | - if($this->isBitrixLoaded) { |
|
41 | + if ($this->isBitrixLoaded) { |
|
42 | 42 | if ($this->getCommandName($input) === null) { |
43 | 43 | $output->writeln(PHP_EOL . sprintf('Using Bitrix <info>kernel v%s</info>.</info>', SM_VERSION), |
44 | 44 | OutputInterface::VERBOSITY_VERY_VERBOSE); |
@@ -27,20 +27,20 @@ discard block |
||
27 | 27 | protected function execute(InputInterface $input, OutputInterface $output) |
28 | 28 | { |
29 | 29 | $logger = EnvHelper::getLogger('bx_cron'); |
30 | - if($logger) { |
|
30 | + if ($logger) { |
|
31 | 31 | $this->setLogger($logger); |
32 | 32 | } |
33 | 33 | |
34 | - if(EnvHelper::getSwitch('BX_CRONTAB_RUN', EnvHelper::SWITCH_STATE_OFF)) { |
|
35 | - if($this->logger) { |
|
34 | + if (EnvHelper::getSwitch('BX_CRONTAB_RUN', EnvHelper::SWITCH_STATE_OFF)) { |
|
35 | + if ($this->logger) { |
|
36 | 36 | $this->logger->alert('BxCron switch off'); |
37 | 37 | } |
38 | 38 | return 0; |
39 | 39 | } |
40 | 40 | |
41 | - if(!$this->lock()) { |
|
41 | + if (!$this->lock()) { |
|
42 | 42 | $output->writeln("The command is already running in another process."); |
43 | - if($this->logger) { |
|
43 | + if ($this->logger) { |
|
44 | 44 | $this->logger->warning("The command is already running in another process."); |
45 | 45 | } |
46 | 46 | return 0; |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | */ |
55 | 55 | $this->minAgentPeriod = (count($jobs) + 1) * EnvHelper::getBxCrontabPeriod(); |
56 | 56 | |
57 | - if(!empty($jobs)) { |
|
57 | + if (!empty($jobs)) { |
|
58 | 58 | |
59 | - foreach($jobs as $cmd => $job) { |
|
59 | + foreach ($jobs as $cmd => $job) { |
|
60 | 60 | |
61 | - if($this->isActualJob($job)) { |
|
61 | + if ($this->isActualJob($job)) { |
|
62 | 62 | |
63 | 63 | $job['status'] = self::EXEC_STATUS_WORK; |
64 | 64 | $this->updaateJob($cmd, $job); |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | $timeStart = microtime(true); |
71 | 71 | $returnCode = $command->run($cmdInput, $output); |
72 | 72 | |
73 | - if(!$returnCode) { |
|
73 | + if (!$returnCode) { |
|
74 | 74 | |
75 | 75 | $job['status'] = self::EXEC_STATUS_SUCCESS; |
76 | 76 | |
77 | 77 | $msg = sprintf("%s: SUCCESS [%.2f s]", $cmd, microtime(true) - $timeStart); |
78 | - if($this->logger) { |
|
78 | + if ($this->logger) { |
|
79 | 79 | $this->logger->alert($msg); |
80 | 80 | } |
81 | 81 | $output->writeln(PHP_EOL . $msg); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $job['error_code'] = $returnCode; |
87 | 87 | |
88 | 88 | $msg = sprintf("%s: ERROR [%.2f s]", $cmd, microtime(true) - $timeStart); |
89 | - if($this->logger) { |
|
89 | + if ($this->logger) { |
|
90 | 90 | $this->logger->alert($msg); |
91 | 91 | } |
92 | 92 | $output->writeln(PHP_EOL . $msg); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $job['error'] = $e->getMessage(); |
99 | 99 | |
100 | 100 | |
101 | - if($this->logger) { |
|
101 | + if ($this->logger) { |
|
102 | 102 | $this->logger->error($e, ['command' => $cmd]); |
103 | 103 | } |
104 | 104 | $output->writeln(PHP_EOL . 'ERROR: ' . $e->getMessage()); |
@@ -125,21 +125,21 @@ discard block |
||
125 | 125 | |
126 | 126 | protected function isActualJob(&$job) { |
127 | 127 | |
128 | - if(isset($job['status']) && $job['status'] !== self::EXEC_STATUS_SUCCESS) { |
|
128 | + if (isset($job['status']) && $job['status'] !== self::EXEC_STATUS_SUCCESS) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $period = intval($job['period']); |
133 | 133 | |
134 | - if($period > 0) { |
|
135 | - if($period < $this->minAgentPeriod) { |
|
134 | + if ($period > 0) { |
|
135 | + if ($period < $this->minAgentPeriod) { |
|
136 | 136 | $job['orig_period'] = $period; |
137 | 137 | $period = $job['period'] = $this->minAgentPeriod; |
138 | 138 | } |
139 | - if(time() - $job['last_exec'] >= $period) { |
|
139 | + if (time() - $job['last_exec'] >= $period) { |
|
140 | 140 | return true; |
141 | 141 | } |
142 | - } else if(!empty($job['times'])) { |
|
142 | + } else if (!empty($job['times'])) { |
|
143 | 143 | //TODO: |
144 | 144 | } |
145 | 145 | |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | $commands = $app->all(); |
155 | 155 | |
156 | 156 | $selfCommands = []; |
157 | - foreach($commands as $command) { |
|
157 | + foreach ($commands as $command) { |
|
158 | 158 | /** @var BxCommand $command */ |
159 | - if($command instanceof BxCommand) { |
|
159 | + if ($command instanceof BxCommand) { |
|
160 | 160 | $name = $command->getName(); |
161 | 161 | $selfCommands[$name] = [ |
162 | 162 | 'object' => $command, |
@@ -166,12 +166,12 @@ discard block |
||
166 | 166 | |
167 | 167 | $agents = []; |
168 | 168 | $reader = new AnnotationReader(); |
169 | - foreach($selfCommands as $cmd => $selfCommand) { |
|
169 | + foreach ($selfCommands as $cmd => $selfCommand) { |
|
170 | 170 | $reflectionClass = new \ReflectionClass($selfCommand['object']); |
171 | 171 | $annotations = $reader->getClassAnnotations($reflectionClass); |
172 | 172 | |
173 | - foreach($annotations as $annotation) { |
|
174 | - if($annotation instanceof Agent) { |
|
173 | + foreach ($annotations as $annotation) { |
|
174 | + if ($annotation instanceof Agent) { |
|
175 | 175 | $agents[$cmd] = $annotation->toArray(); |
176 | 176 | } |
177 | 177 | } |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | |
180 | 180 | $crontab = $this->getCronTab(); |
181 | 181 | |
182 | - if(is_array($crontab)) { |
|
183 | - foreach($crontab as $cmd => $job) { |
|
184 | - if(is_array($job) && isset($agents[$cmd])) { |
|
182 | + if (is_array($crontab)) { |
|
183 | + foreach ($crontab as $cmd => $job) { |
|
184 | + if (is_array($job) && isset($agents[$cmd])) { |
|
185 | 185 | $agents[$cmd] = array_merge($job, $agents[$cmd]); |
186 | 186 | } |
187 | 187 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $fh = fopen($filename, 'c'); |
215 | 215 | if (flock($fh, LOCK_EX)) { |
216 | 216 | ftruncate($fh, 0); |
217 | - if(!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) { |
|
217 | + if (!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) { |
|
218 | 218 | throw new \Exception('Unable to write BX_CRONTAB : ' . $filename); |
219 | 219 | } |
220 | 220 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | $filename = EnvHelper::getCrontabFile(); |
233 | 233 | |
234 | 234 | $fh = fopen($filename, 'r'); |
235 | - if(flock($fh, LOCK_SH)) { |
|
235 | + if (flock($fh, LOCK_SH)) { |
|
236 | 236 | $data = @fread($fh, filesize($filename)); |
237 | 237 | $cronTab = json_decode($data, true); |
238 | 238 | } |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | public static function loadEnv() { |
18 | 18 | |
19 | 19 | $envFile = realpath(__DIR__ . '/../../../../.env'); |
20 | - if(!is_file($envFile)) { |
|
20 | + if (!is_file($envFile)) { |
|
21 | 21 | $envFile = realpath(__DIR__ . '/../../../../../.env'); |
22 | 22 | } |
23 | - if(is_file($envFile)) { |
|
23 | + if (is_file($envFile)) { |
|
24 | 24 | try { |
25 | 25 | $env = new \Symfony\Component\Dotenv\Dotenv(); |
26 | 26 | $env->load($envFile); |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | |
38 | 38 | $_SERVER['DOCUMENT_ROOT'] = realpath(__DIR__ . '/../../../../'); |
39 | 39 | |
40 | - if(isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) { |
|
40 | + if (isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) { |
|
41 | 41 | $_SERVER['DOCUMENT_ROOT'] = $_ENV['APP_DOCUMENT_ROOT']; |
42 | 42 | return $_SERVER['DOCUMENT_ROOT']; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $composerFile = realpath(__DIR__ . '/../../../../composer.json'); |
46 | - if(is_file($composerFile)) { |
|
46 | + if (is_file($composerFile)) { |
|
47 | 47 | $composerConfig = json_decode(file_get_contents($composerFile), true); |
48 | - if(isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) { |
|
48 | + if (isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) { |
|
49 | 49 | $_SERVER['DOCUMENT_ROOT'] = $composerConfig['extra']['document-root']; |
50 | 50 | return $_SERVER['DOCUMENT_ROOT']; |
51 | 51 | } |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public static function getLogger($channel) { |
62 | 62 | |
63 | - if(isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) { |
|
63 | + if (isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) { |
|
64 | 64 | $logClass = $_ENV['APP_LOG_CLASS']; |
65 | 65 | $log = new $logClass($channel); |
66 | - if($log instanceof LoggerInterface) { |
|
66 | + if ($log instanceof LoggerInterface) { |
|
67 | 67 | return $log; |
68 | 68 | } |
69 | 69 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public static function getCrontabFile() { |
78 | 78 | |
79 | - if(isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) { |
|
79 | + if (isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) { |
|
80 | 80 | return rtrim($_ENV['BX_CRONTAB_FOLDER'], "/") . '/bx_crontab.json'; |
81 | 81 | } |
82 | 82 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | public static function getCrontabTimeout() { |
87 | 87 | |
88 | - if(isset($_ENV['BX_CRONTAB_FOLDER']) && is_numeric($_ENV['BX_CRONTAB_FOLDER'])) { |
|
88 | + if (isset($_ENV['BX_CRONTAB_FOLDER']) && is_numeric($_ENV['BX_CRONTAB_FOLDER'])) { |
|
89 | 89 | return (int) $_ENV['BX_CRONTAB_FOLDER']; |
90 | 90 | } |
91 | 91 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | public static function getBxCrontabPeriod() { |
96 | 96 | |
97 | - if(isset($_ENV['BX_CRONTAB_PERIOD']) && is_numeric($_ENV['BX_CRONTAB_PERIOD'])) { |
|
97 | + if (isset($_ENV['BX_CRONTAB_PERIOD']) && is_numeric($_ENV['BX_CRONTAB_PERIOD'])) { |
|
98 | 98 | return (int) $_ENV['BX_CRONTAB_PERIOD']; |
99 | 99 | } |
100 | 100 | |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | |
104 | 104 | public static function getSwitch($name, $state) { |
105 | 105 | |
106 | - if(isset($_ENV[$name])) { |
|
106 | + if (isset($_ENV[$name])) { |
|
107 | 107 | |
108 | 108 | $val = strtolower(trim($_ENV[$name])); |
109 | - if($state == self::SWITCH_STATE_ON) { |
|
110 | - if($val === self::SWITCH_STATE_ON || $val === '1' || $val === 'true') { |
|
109 | + if ($state == self::SWITCH_STATE_ON) { |
|
110 | + if ($val === self::SWITCH_STATE_ON || $val === '1' || $val === 'true') { |
|
111 | 111 | return true; |
112 | 112 | } |
113 | - } else if($state == self::SWITCH_STATE_OFF) { |
|
114 | - if($val === self::SWITCH_STATE_OFF || $val === '0' || $val === 'false') { |
|
113 | + } else if ($state == self::SWITCH_STATE_OFF) { |
|
114 | + if ($val === self::SWITCH_STATE_OFF || $val === '0' || $val === 'false') { |
|
115 | 115 | return true; |
116 | 116 | } |
117 | 117 | } |