@@ -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 |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | |
10 | 10 | public static function loadEnv() { |
11 | 11 | |
12 | - if(class_exists('\Symfony\Component\Dotenv\Dotenv')) { |
|
12 | + if (class_exists('\Symfony\Component\Dotenv\Dotenv')) { |
|
13 | 13 | $envFile = realpath(__DIR__ . '/../../../../.env'); |
14 | - if(!is_file($envFile)) { |
|
14 | + if (!is_file($envFile)) { |
|
15 | 15 | $envFile = realpath(__DIR__ . '/../../../../../.env'); |
16 | 16 | } |
17 | - if(is_file($envFile)) { |
|
17 | + if (is_file($envFile)) { |
|
18 | 18 | try { |
19 | 19 | $env = new \Symfony\Component\Dotenv\Dotenv(); |
20 | 20 | $env->load($envFile); |
@@ -32,15 +32,15 @@ discard block |
||
32 | 32 | |
33 | 33 | $_SERVER['DOCUMENT_ROOT'] = realpath(__DIR__ . '/../../../../'); |
34 | 34 | |
35 | - if(isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) { |
|
35 | + if (isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) { |
|
36 | 36 | $_SERVER['DOCUMENT_ROOT'] = $_ENV['APP_DOCUMENT_ROOT']; |
37 | 37 | return $_SERVER['DOCUMENT_ROOT']; |
38 | 38 | } |
39 | 39 | |
40 | 40 | $composerFile = realpath(__DIR__ . '/../../../../composer.json'); |
41 | - if(is_file($composerFile)) { |
|
41 | + if (is_file($composerFile)) { |
|
42 | 42 | $composerConfig = json_decode(file_get_contents($composerFile), true); |
43 | - if(isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) { |
|
43 | + if (isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) { |
|
44 | 44 | $_SERVER['DOCUMENT_ROOT'] = $composerConfig['extra']['document-root']; |
45 | 45 | return $_SERVER['DOCUMENT_ROOT']; |
46 | 46 | } |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public static function getLogger($channel) { |
57 | 57 | |
58 | - if(isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) { |
|
58 | + if (isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) { |
|
59 | 59 | $logClass = $_ENV['APP_LOG_CLASS']; |
60 | 60 | $log = new $logClass($channel); |
61 | - if($log instanceof LoggerInterface) { |
|
61 | + if ($log instanceof LoggerInterface) { |
|
62 | 62 | return $log; |
63 | 63 | } |
64 | 64 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public static function getCrontabFile() { |
73 | 73 | |
74 | - if(isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) { |
|
74 | + if (isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) { |
|
75 | 75 | return rtrim($_ENV['BX_CRONTAB_FOLDER'], "/") . '/bx_crontab.json'; |
76 | 76 | } |
77 | 77 |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | |
48 | 48 | $workedJobs = []; |
49 | 49 | |
50 | - if(!empty($jobs)) { |
|
50 | + if (!empty($jobs)) { |
|
51 | 51 | |
52 | 52 | $lockStore = new FlockStore(pathinfo(EnvHelper::getCrontabFile(), PATHINFO_DIRNAME)); |
53 | 53 | $lockFactory = new LockFactory($lockStore); |
54 | - if($this->logger) { |
|
54 | + if ($this->logger) { |
|
55 | 55 | $lockFactory->setLogger($this->logger); |
56 | 56 | } |
57 | 57 | |
58 | - foreach($jobs as $cmd => $job) { |
|
58 | + foreach ($jobs as $cmd => $job) { |
|
59 | 59 | |
60 | - if($this->isActualJob($job)) { |
|
60 | + if ($this->isActualJob($job)) { |
|
61 | 61 | |
62 | 62 | $lock = $lockFactory->createLock($this->getLockName($cmd), self::EXEC_TIMEOUT); |
63 | - if($lock->acquire()) { |
|
63 | + if ($lock->acquire()) { |
|
64 | 64 | |
65 | 65 | $workedJobs[$cmd] = $job; |
66 | 66 | |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | $timeStart = microtime(true); |
72 | 72 | $returnCode = $command->run($cmdInput, $output); |
73 | 73 | |
74 | - if(!$returnCode) { |
|
74 | + if (!$returnCode) { |
|
75 | 75 | |
76 | 76 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_SUCCESS; |
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); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_ERROR; |
86 | 86 | $workedJobs[$cmd]['error_code'] = $returnCode; |
87 | 87 | $msg = sprintf("%s: ERROR [%.2f s]", $cmd, microtime(true) - $timeStart); |
88 | - if($this->logger) { |
|
88 | + if ($this->logger) { |
|
89 | 89 | $this->logger->alert($msg); |
90 | 90 | } |
91 | 91 | $output->writeln(PHP_EOL . $msg); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_ERROR; |
97 | 97 | $workedJobs[$cmd]['error'] = $e->getMessage(); |
98 | - if($this->logger) { |
|
98 | + if ($this->logger) { |
|
99 | 99 | $this->logger->error($e, ['command' => $cmd]); |
100 | 100 | } |
101 | 101 | $output->writeln(PHP_EOL . 'ERROR: ' . $e->getMessage()); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | break; |
115 | 115 | |
116 | 116 | } else { |
117 | - if($this->logger) { |
|
117 | + if ($this->logger) { |
|
118 | 118 | $this->logger->warning($cmd . " is locked"); |
119 | 119 | } |
120 | 120 | } |
@@ -134,15 +134,15 @@ discard block |
||
134 | 134 | |
135 | 135 | $period = intval($job['period']); |
136 | 136 | |
137 | - if($period > 0) { |
|
138 | - if($period < $this->minAgentPeriod) { |
|
137 | + if ($period > 0) { |
|
138 | + if ($period < $this->minAgentPeriod) { |
|
139 | 139 | $job['orig_period'] = $period; |
140 | 140 | $period = $job['period'] = $this->minAgentPeriod; |
141 | 141 | } |
142 | - if(time() - $job['last_exec'] >= $period) { |
|
142 | + if (time() - $job['last_exec'] >= $period) { |
|
143 | 143 | return true; |
144 | 144 | } |
145 | - } else if(!empty($job['times'])) { |
|
145 | + } else if (!empty($job['times'])) { |
|
146 | 146 | //TODO: |
147 | 147 | } |
148 | 148 | |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | $commands = $app->all(); |
158 | 158 | |
159 | 159 | $selfCommands = []; |
160 | - foreach($commands as $command) { |
|
160 | + foreach ($commands as $command) { |
|
161 | 161 | /** @var BxCommand $command */ |
162 | - if($command instanceof BxCommand) { |
|
162 | + if ($command instanceof BxCommand) { |
|
163 | 163 | $name = $command->getName(); |
164 | 164 | $selfCommands[$name] = [ |
165 | 165 | 'object' => $command, |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | |
170 | 170 | $agents = []; |
171 | 171 | $reader = new AnnotationReader(); |
172 | - foreach($selfCommands as $cmd => $selfCommand) { |
|
172 | + foreach ($selfCommands as $cmd => $selfCommand) { |
|
173 | 173 | $reflectionClass = new \ReflectionClass($selfCommand['object']); |
174 | 174 | $annotations = $reader->getClassAnnotations($reflectionClass); |
175 | 175 | |
176 | - foreach($annotations as $annotation) { |
|
177 | - if($annotation instanceof Agent) { |
|
176 | + foreach ($annotations as $annotation) { |
|
177 | + if ($annotation instanceof Agent) { |
|
178 | 178 | $agents[$cmd] = $annotation->toArray(); |
179 | 179 | } |
180 | 180 | } |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | |
183 | 183 | $crontab = $this->getCronTab(); |
184 | 184 | |
185 | - if(is_array($crontab)) { |
|
186 | - foreach($crontab as $cmd => $job) { |
|
187 | - if(is_array($job) && isset($agents[$cmd])) { |
|
185 | + if (is_array($crontab)) { |
|
186 | + foreach ($crontab as $cmd => $job) { |
|
187 | + if (is_array($job) && isset($agents[$cmd])) { |
|
188 | 188 | $agents[$cmd] = array_merge($job, $agents[$cmd]); |
189 | 189 | } |
190 | 190 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $fh = fopen($filename, 'c'); |
213 | 213 | if (flock($fh, LOCK_EX)) { |
214 | 214 | ftruncate($fh, 0); |
215 | - if(!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) { |
|
215 | + if (!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) { |
|
216 | 216 | throw new \Exception('Unable to write BX_CRONTAB : ' . $filename); |
217 | 217 | } |
218 | 218 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $filename = EnvHelper::getCrontabFile(); |
231 | 231 | |
232 | 232 | $fh = fopen($filename, 'r'); |
233 | - if(flock($fh, LOCK_SH)) { |
|
233 | + if (flock($fh, LOCK_SH)) { |
|
234 | 234 | $data = @fread($fh, filesize($filename)); |
235 | 235 | $cronTab = json_decode($data, true); |
236 | 236 | } |
@@ -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); |