@@ -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); |
@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | public static function loadEnv() { |
11 | 11 | |
12 | 12 | $envFile = realpath(__DIR__ . '/../../../../.env'); |
13 | - if(!is_file($envFile)) { |
|
13 | + if (!is_file($envFile)) { |
|
14 | 14 | $envFile = realpath(__DIR__ . '/../../../../../.env'); |
15 | 15 | } |
16 | - if(is_file($envFile)) { |
|
16 | + if (is_file($envFile)) { |
|
17 | 17 | try { |
18 | 18 | $env = new \Symfony\Component\Dotenv\Dotenv(); |
19 | 19 | $env->load($envFile); |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | |
31 | 31 | $_SERVER['DOCUMENT_ROOT'] = realpath(__DIR__ . '/../../../../'); |
32 | 32 | |
33 | - if(isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) { |
|
33 | + if (isset($_ENV['APP_DOCUMENT_ROOT']) && is_dir($_ENV['APP_DOCUMENT_ROOT'])) { |
|
34 | 34 | $_SERVER['DOCUMENT_ROOT'] = $_ENV['APP_DOCUMENT_ROOT']; |
35 | 35 | return $_SERVER['DOCUMENT_ROOT']; |
36 | 36 | } |
37 | 37 | |
38 | 38 | $composerFile = realpath(__DIR__ . '/../../../../composer.json'); |
39 | - if(is_file($composerFile)) { |
|
39 | + if (is_file($composerFile)) { |
|
40 | 40 | $composerConfig = json_decode(file_get_contents($composerFile), true); |
41 | - if(isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) { |
|
41 | + if (isset($composerConfig['extra']['document-root']) && is_dir($composerConfig['extra']['document-root'])) { |
|
42 | 42 | $_SERVER['DOCUMENT_ROOT'] = $composerConfig['extra']['document-root']; |
43 | 43 | return $_SERVER['DOCUMENT_ROOT']; |
44 | 44 | } |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public static function getLogger($channel) { |
55 | 55 | |
56 | - if(isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) { |
|
56 | + if (isset($_ENV['APP_LOG_CLASS']) && class_exists($_ENV['APP_LOG_CLASS'])) { |
|
57 | 57 | $logClass = $_ENV['APP_LOG_CLASS']; |
58 | 58 | $log = new $logClass($channel); |
59 | - if($log instanceof LoggerInterface) { |
|
59 | + if ($log instanceof LoggerInterface) { |
|
60 | 60 | return $log; |
61 | 61 | } |
62 | 62 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public static function getCrontabFile() { |
71 | 71 | |
72 | - if(isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) { |
|
72 | + if (isset($_ENV['BX_CRONTAB_FOLDER']) && $_ENV['BX_CRONTAB_FOLDER']) { |
|
73 | 73 | return rtrim($_ENV['BX_CRONTAB_FOLDER'], "/") . '/bx_crontab.json'; |
74 | 74 | } |
75 | 75 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | protected function execute(InputInterface $input, OutputInterface $output) |
37 | 37 | { |
38 | 38 | $logger = EnvHelper::getLogger('bx_cron'); |
39 | - if($logger) { |
|
39 | + if ($logger) { |
|
40 | 40 | $this->setLogger($logger); |
41 | 41 | } |
42 | 42 | |
@@ -50,20 +50,20 @@ discard block |
||
50 | 50 | |
51 | 51 | $workedJobs = []; |
52 | 52 | |
53 | - if(!empty($jobs)) { |
|
53 | + if (!empty($jobs)) { |
|
54 | 54 | |
55 | 55 | $lockStore = new FlockStore(pathinfo(EnvHelper::getCrontabFile(), PATHINFO_DIRNAME)); |
56 | 56 | $lockFactory = new LockFactory($lockStore); |
57 | - if($this->logger) { |
|
57 | + if ($this->logger) { |
|
58 | 58 | $lockFactory->setLogger($this->logger); |
59 | 59 | } |
60 | 60 | |
61 | - foreach($jobs as $cmd => $job) { |
|
61 | + foreach ($jobs as $cmd => $job) { |
|
62 | 62 | |
63 | - if($this->isActualJob($job)) { |
|
63 | + if ($this->isActualJob($job)) { |
|
64 | 64 | |
65 | 65 | $lock = $lockFactory->createLock($this->getLockName($cmd), self::EXEC_TIMEOUT); |
66 | - if($lock->acquire()) { |
|
66 | + if ($lock->acquire()) { |
|
67 | 67 | |
68 | 68 | $workedJobs[$cmd] = $job; |
69 | 69 | |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | $timeStart = microtime(true); |
75 | 75 | $returnCode = $command->run($cmdInput, $output); |
76 | 76 | |
77 | - if(!$returnCode) { |
|
77 | + if (!$returnCode) { |
|
78 | 78 | |
79 | 79 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_SUCCESS; |
80 | 80 | $msg = sprintf("%s: SUCCESS [%.2f s]", $cmd, microtime(true) - $timeStart); |
81 | - if($this->logger) { |
|
81 | + if ($this->logger) { |
|
82 | 82 | $this->logger->alert($msg); |
83 | 83 | } |
84 | 84 | $output->writeln(PHP_EOL . $msg); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_ERROR; |
89 | 89 | $workedJobs[$cmd]['error_code'] = $returnCode; |
90 | 90 | $msg = sprintf("%s: ERROR [%.2f s]", $cmd, microtime(true) - $timeStart); |
91 | - if($this->logger) { |
|
91 | + if ($this->logger) { |
|
92 | 92 | $this->logger->alert($msg); |
93 | 93 | } |
94 | 94 | $output->writeln(PHP_EOL . $msg); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | $workedJobs[$cmd]['status'] = self::EXEC_STATUS_ERROR; |
100 | 100 | $workedJobs[$cmd]['error'] = $e->getMessage(); |
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()); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | break; |
118 | 118 | |
119 | 119 | } else { |
120 | - if($this->logger) { |
|
120 | + if ($this->logger) { |
|
121 | 121 | $this->logger->warning($cmd . " is locked"); |
122 | 122 | } |
123 | 123 | } |
@@ -137,15 +137,15 @@ discard block |
||
137 | 137 | |
138 | 138 | $period = intval($job['period']); |
139 | 139 | |
140 | - if($period > 0) { |
|
141 | - if($period < $this->minAgentPeriod) { |
|
140 | + if ($period > 0) { |
|
141 | + if ($period < $this->minAgentPeriod) { |
|
142 | 142 | $job['orig_period'] = $period; |
143 | 143 | $period = $job['period'] = $this->minAgentPeriod; |
144 | 144 | } |
145 | - if(time() - $job['last_exec'] >= $period) { |
|
145 | + if (time() - $job['last_exec'] >= $period) { |
|
146 | 146 | return true; |
147 | 147 | } |
148 | - } else if(!empty($job['times'])) { |
|
148 | + } else if (!empty($job['times'])) { |
|
149 | 149 | //TODO: |
150 | 150 | } |
151 | 151 | |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | $commands = $app->all(); |
161 | 161 | |
162 | 162 | $selfCommands = []; |
163 | - foreach($commands as $command) { |
|
163 | + foreach ($commands as $command) { |
|
164 | 164 | /** @var BxCommand $command */ |
165 | - if($command instanceof BxCommand) { |
|
165 | + if ($command instanceof BxCommand) { |
|
166 | 166 | $name = $command->getName(); |
167 | 167 | $selfCommands[$name] = [ |
168 | 168 | 'object' => $command, |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | |
173 | 173 | $agents = []; |
174 | 174 | $reader = new AnnotationReader(); |
175 | - foreach($selfCommands as $cmd => $selfCommand) { |
|
175 | + foreach ($selfCommands as $cmd => $selfCommand) { |
|
176 | 176 | $reflectionClass = new \ReflectionClass($selfCommand['object']); |
177 | 177 | $annotations = $reader->getClassAnnotations($reflectionClass); |
178 | 178 | |
179 | - foreach($annotations as $annotation) { |
|
180 | - if($annotation instanceof Agent) { |
|
179 | + foreach ($annotations as $annotation) { |
|
180 | + if ($annotation instanceof Agent) { |
|
181 | 181 | $agents[$cmd] = $annotation->toArray(); |
182 | 182 | } |
183 | 183 | } |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | |
186 | 186 | $crontab = $this->getCronTab(); |
187 | 187 | |
188 | - if(is_array($crontab)) { |
|
189 | - foreach($crontab as $cmd => $job) { |
|
190 | - if(is_array($job) && isset($agents[$cmd])) { |
|
188 | + if (is_array($crontab)) { |
|
189 | + foreach ($crontab as $cmd => $job) { |
|
190 | + if (is_array($job) && isset($agents[$cmd])) { |
|
191 | 191 | $agents[$cmd] = array_merge($job, $agents[$cmd]); |
192 | 192 | } |
193 | 193 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $fh = fopen($filename, 'c'); |
216 | 216 | if (flock($fh, LOCK_EX)) { |
217 | 217 | ftruncate($fh, 0); |
218 | - if(!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) { |
|
218 | + if (!fwrite($fh, json_encode($agents, JSON_PRETTY_PRINT))) { |
|
219 | 219 | throw new \Exception('Unable to write BX_CRONTAB : ' . $filename); |
220 | 220 | } |
221 | 221 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $filename = EnvHelper::getCrontabFile(); |
234 | 234 | |
235 | 235 | $fh = fopen($filename, 'r'); |
236 | - if(flock($fh, LOCK_SH)) { |
|
236 | + if (flock($fh, LOCK_SH)) { |
|
237 | 237 | $data = @fread($fh, filesize($filename)); |
238 | 238 | $cronTab = json_decode($data, true); |
239 | 239 | } |