| @@ -105,8 +105,7 @@ discard block | ||
| 105 | 105 |          { | 
| 106 | 106 | $output->writeln(PHP_EOL . '<error>No configuration loaded.</error> ' | 
| 107 | 107 | . 'Please run <info>init</info> command first'); | 
| 108 | - } | |
| 109 | - else | |
| 108 | + } else | |
| 110 | 109 |          { | 
| 111 | 110 | switch ($this->getBitrixStatus()) | 
| 112 | 111 |              { | 
| @@ -179,8 +178,7 @@ discard block | ||
| 179 | 178 | if ($cliFile === false) | 
| 180 | 179 |              { | 
| 181 | 180 | continue; | 
| 182 | - } | |
| 183 | - elseif (!Loader::includeModule($module['ID'])) | |
| 181 | + } elseif (!Loader::includeModule($module['ID'])) | |
| 184 | 182 |              { | 
| 185 | 183 | continue; | 
| 186 | 184 | } | 
| @@ -224,8 +222,7 @@ discard block | ||
| 224 | 222 | if ($filesystem->isAbsolutePath($this->configuration['web-dir'])) | 
| 225 | 223 |          { | 
| 226 | 224 | $this->setDocumentRoot($this->configuration['web-dir']); | 
| 227 | - } | |
| 228 | - else | |
| 225 | + } else | |
| 229 | 226 |          { | 
| 230 | 227 | $this->setDocumentRoot($this->getRoot() . '/' . $this->configuration['web-dir']); | 
| 231 | 228 | } | 
| @@ -258,8 +255,7 @@ discard block | ||
| 258 | 255 | if ($this->bitrixStatus === static::BITRIX_STATUS_COMPLETE) | 
| 259 | 256 |          { | 
| 260 | 257 | return static::BITRIX_STATUS_COMPLETE; | 
| 261 | - } | |
| 262 | - elseif (!$this->checkBitrix()) | |
| 258 | + } elseif (!$this->checkBitrix()) | |
| 263 | 259 |          { | 
| 264 | 260 | return static::BITRIX_STATUS_UNAVAILABLE; | 
| 265 | 261 | } | 
| @@ -284,8 +280,7 @@ discard block | ||
| 284 | 280 |              { | 
| 285 | 281 | $this->bitrixStatus = static::BITRIX_STATUS_COMPLETE; | 
| 286 | 282 | } | 
| 287 | - } | |
| 288 | - catch (ConnectionException $e) | |
| 283 | + } catch (ConnectionException $e) | |
| 289 | 284 |          { | 
| 290 | 285 | $this->bitrixStatus = static::BITRIX_STATUS_NO_DB_CONNECTION; | 
| 291 | 286 | } | 
| @@ -363,12 +358,10 @@ discard block | ||
| 363 | 358 |              if (preg_match("#[^\\\\/a-zA-Z0-9_]#", $file)) | 
| 364 | 359 |              { | 
| 365 | 360 | return false; | 
| 366 | - } | |
| 367 | - elseif ($arFile[0] === 'bitrix') | |
| 361 | + } elseif ($arFile[0] === 'bitrix') | |
| 368 | 362 |              { | 
| 369 | 363 | return false; | 
| 370 | - } | |
| 371 | - elseif ($arFile[2] !== 'tests') | |
| 364 | + } elseif ($arFile[2] !== 'tests') | |
| 372 | 365 |              { | 
| 373 | 366 | return false; | 
| 374 | 367 | } | 
| @@ -108,7 +108,7 @@ discard block | ||
| 108 | 108 | |
| 109 | 109 | if ($this->getConfiguration() === null) | 
| 110 | 110 |          { | 
| 111 | - $output->writeln(PHP_EOL . '<error>No configuration loaded.</error> ' | |
| 111 | + $output->writeln(PHP_EOL.'<error>No configuration loaded.</error> ' | |
| 112 | 112 | . 'Please run <info>init</info> command first'); | 
| 113 | 113 | } | 
| 114 | 114 | else | 
| @@ -116,18 +116,18 @@ discard block | ||
| 116 | 116 | switch ($this->getBitrixStatus()) | 
| 117 | 117 |              { | 
| 118 | 118 | case static::BITRIX_STATUS_UNAVAILABLE: | 
| 119 | -                    $output->writeln(PHP_EOL . sprintf('<error>No Bitrix kernel found in %s.</error> '  | |
| 119 | +                    $output->writeln(PHP_EOL.sprintf('<error>No Bitrix kernel found in %s.</error> '  | |
| 120 | 120 | . 'Please run <info>env:init</info> command to configure', $this->getDocumentRoot())); | 
| 121 | 121 | break; | 
| 122 | 122 | |
| 123 | 123 | case static::BITRIX_STATUS_NO_DB_CONNECTION: | 
| 124 | - $output->writeln(PHP_EOL . '<error>Bitrix database connection is unavailable.</error>'); | |
| 124 | + $output->writeln(PHP_EOL.'<error>Bitrix database connection is unavailable.</error>'); | |
| 125 | 125 | break; | 
| 126 | 126 | |
| 127 | 127 | case static::BITRIX_STATUS_COMPLETE: | 
| 128 | 128 | if ($this->getCommandName($input) === null) | 
| 129 | 129 |                      { | 
| 130 | -                        $output->writeln(PHP_EOL . sprintf('Using Bitrix <info>kernel v%s</info>.</info>', SM_VERSION), | |
| 130 | +                        $output->writeln(PHP_EOL.sprintf('Using Bitrix <info>kernel v%s</info>.</info>', SM_VERSION), | |
| 131 | 131 | OutputInterface::VERBOSITY_VERY_VERBOSE); | 
| 132 | 132 | } | 
| 133 | 133 | break; | 
| @@ -179,7 +179,7 @@ discard block | ||
| 179 | 179 | |
| 180 | 180 | foreach (ModuleManager::getInstalledModules() as $module) | 
| 181 | 181 |          { | 
| 182 | -            $cliFile = getLocalPath('modules/' . $module['ID'] . '/cli.php'); | |
| 182 | +            $cliFile = getLocalPath('modules/'.$module['ID'].'/cli.php'); | |
| 183 | 183 | |
| 184 | 184 | if ($cliFile === false) | 
| 185 | 185 |              { | 
| @@ -190,7 +190,7 @@ discard block | ||
| 190 | 190 | continue; | 
| 191 | 191 | } | 
| 192 | 192 | |
| 193 | - $config = include_once $this->getDocumentRoot() . $cliFile; | |
| 193 | + $config = include_once $this->getDocumentRoot().$cliFile; | |
| 194 | 194 | |
| 195 | 195 | if (isset($config['commands']) && is_array($config['commands'])) | 
| 196 | 196 |              { | 
| @@ -221,7 +221,7 @@ discard block | ||
| 221 | 221 | |
| 222 | 222 | if (!is_array($this->configuration)) | 
| 223 | 223 |          { | 
| 224 | -            throw new ConfigurationException('Configuration file ' . $path . ' must return an array'); | |
| 224 | +            throw new ConfigurationException('Configuration file '.$path.' must return an array'); | |
| 225 | 225 | } | 
| 226 | 226 | |
| 227 | 227 | //TODO-fox: Проверка на указание в качестве относительного пути / | 
| @@ -236,7 +236,7 @@ discard block | ||
| 236 | 236 | } | 
| 237 | 237 | else | 
| 238 | 238 |          { | 
| 239 | - $this->setDocumentRoot($this->getRoot() . '/' . $this->configuration['web-dir']); | |
| 239 | + $this->setDocumentRoot($this->getRoot().'/'.$this->configuration['web-dir']); | |
| 240 | 240 | } | 
| 241 | 241 | |
| 242 | 242 | if (!is_dir($_SERVER['DOCUMENT_ROOT'])) | 
| @@ -287,7 +287,7 @@ discard block | ||
| 287 | 287 | /** @noinspection PhpUnusedLocalVariableInspection */ | 
| 288 | 288 | $DB, $DBType, $DBHost, $DBLogin, $DBPassword, $DBName, $DBDebug, $DBDebugToFile, $APPLICATION, $USER, $DBSQLServerType; | 
| 289 | 289 | |
| 290 | - require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'; | |
| 290 | + require_once $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php'; | |
| 291 | 291 | |
| 292 | 292 |              if (defined('B_PROLOG_INCLUDED') && B_PROLOG_INCLUDED === true) | 
| 293 | 293 |              { | 
| @@ -310,8 +310,8 @@ discard block | ||
| 310 | 310 | public function checkBitrix() | 
| 311 | 311 |      { | 
| 312 | 312 | if ( | 
| 313 | - !is_file($_SERVER['DOCUMENT_ROOT'] . '/bitrix/.settings.php') | |
| 314 | - && !is_file($_SERVER['DOCUMENT_ROOT'] . '/bitrix/.settings_extra.php') | |
| 313 | + !is_file($_SERVER['DOCUMENT_ROOT'].'/bitrix/.settings.php') | |
| 314 | + && !is_file($_SERVER['DOCUMENT_ROOT'].'/bitrix/.settings_extra.php') | |
| 315 | 315 | ) | 
| 316 | 316 |          { | 
| 317 | 317 | return false; | 
| @@ -357,7 +357,7 @@ discard block | ||
| 357 | 357 | |
| 358 | 358 | $this->initializeBitrix(); | 
| 359 | 359 | |
| 360 | -        spl_autoload_register(function ($className) { | |
| 360 | +        spl_autoload_register(function($className) { | |
| 361 | 361 | $file = ltrim($className, "\\"); | 
| 362 | 362 | $file = strtr($file, Loader::ALPHA_UPPER, Loader::ALPHA_LOWER); | 
| 363 | 363 |              $file = str_replace('\\', '/', $file); | 
| @@ -382,18 +382,18 @@ discard block | ||
| 382 | 382 | return false; | 
| 383 | 383 | } | 
| 384 | 384 | |
| 385 | - $module = array_shift($arFile) . '.' . array_shift($arFile); | |
| 385 | + $module = array_shift($arFile).'.'.array_shift($arFile); | |
| 386 | 386 | |
| 387 | 387 | if (!Loader::includeModule($module)) | 
| 388 | 388 |              { | 
| 389 | 389 | return false; | 
| 390 | 390 | } | 
| 391 | 391 | |
| 392 | -            $path = getLocalPath('/modules/' . $module . '/' . implode('/', $arFile) . '.php'); | |
| 392 | +            $path = getLocalPath('/modules/'.$module.'/'.implode('/', $arFile).'.php'); | |
| 393 | 393 | |
| 394 | 394 | if ($path !== false) | 
| 395 | 395 |              { | 
| 396 | - include_once $this->getDocumentRoot() . $path; | |
| 396 | + include_once $this->getDocumentRoot().$path; | |
| 397 | 397 | } | 
| 398 | 398 | }); | 
| 399 | 399 | } | 
| @@ -41,8 +41,7 @@ | ||
| 41 | 41 | if ($ex = $APPLICATION->GetException()) | 
| 42 | 42 |  		{ | 
| 43 | 43 | throw new static($message ? $message . ': ' . $ex->GetString() : $ex->GetString()); | 
| 44 | - } | |
| 45 | - else | |
| 44 | + } else | |
| 46 | 45 |  		{ | 
| 47 | 46 | throw new static($message ? $message : 'Unknown exception'); | 
| 48 | 47 | } | 
| @@ -14,37 +14,37 @@ | ||
| 14 | 14 | */ | 
| 15 | 15 | class BitrixException extends \RuntimeException | 
| 16 | 16 |  { | 
| 17 | - public static function hasException(\CMain $APPLICATION = null) | |
| 18 | -	{ | |
| 19 | - if (null === $APPLICATION) | |
| 20 | -		{ | |
| 21 | - $APPLICATION = $GLOBALS['APPLICATION']; | |
| 22 | - } | |
| 17 | + public static function hasException(\CMain $APPLICATION = null) | |
| 18 | +    { | |
| 19 | + if (null === $APPLICATION) | |
| 20 | +        { | |
| 21 | + $APPLICATION = $GLOBALS['APPLICATION']; | |
| 22 | + } | |
| 23 | 23 | |
| 24 | - return is_object($APPLICATION->GetException()); | |
| 25 | - } | |
| 24 | + return is_object($APPLICATION->GetException()); | |
| 25 | + } | |
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * Check for legacy bitrix exception, throws new self if any | |
| 29 | - * | |
| 30 | - * @param string $message [optional] Additional error message | |
| 31 | - * @param \CMain $APPLICATION [optional] $APPLICATION instance | |
| 32 | - * @throws static | |
| 33 | - */ | |
| 34 | - public static function generate($message = null, \CMain $APPLICATION = null) | |
| 35 | -	{ | |
| 36 | - if (null === $APPLICATION) | |
| 37 | -		{ | |
| 38 | - $APPLICATION = $GLOBALS['APPLICATION']; | |
| 39 | - } | |
| 27 | + /** | |
| 28 | + * Check for legacy bitrix exception, throws new self if any | |
| 29 | + * | |
| 30 | + * @param string $message [optional] Additional error message | |
| 31 | + * @param \CMain $APPLICATION [optional] $APPLICATION instance | |
| 32 | + * @throws static | |
| 33 | + */ | |
| 34 | + public static function generate($message = null, \CMain $APPLICATION = null) | |
| 35 | +    { | |
| 36 | + if (null === $APPLICATION) | |
| 37 | +        { | |
| 38 | + $APPLICATION = $GLOBALS['APPLICATION']; | |
| 39 | + } | |
| 40 | 40 | |
| 41 | - if ($ex = $APPLICATION->GetException()) | |
| 42 | -		{ | |
| 43 | - throw new static($message ? $message . ': ' . $ex->GetString() : $ex->GetString()); | |
| 44 | - } | |
| 45 | - else | |
| 46 | -		{ | |
| 47 | - throw new static($message ? $message : 'Unknown exception'); | |
| 48 | - } | |
| 49 | - } | |
| 41 | + if ($ex = $APPLICATION->GetException()) | |
| 42 | +        { | |
| 43 | + throw new static($message ? $message . ': ' . $ex->GetString() : $ex->GetString()); | |
| 44 | + } | |
| 45 | + else | |
| 46 | +        { | |
| 47 | + throw new static($message ? $message : 'Unknown exception'); | |
| 48 | + } | |
| 49 | + } | |
| 50 | 50 | } | 
| 51 | 51 | \ No newline at end of file | 
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | |
| 41 | 41 | if ($ex = $APPLICATION->GetException()) | 
| 42 | 42 |  		{ | 
| 43 | - throw new static($message ? $message . ': ' . $ex->GetString() : $ex->GetString()); | |
| 43 | + throw new static($message ? $message.': '.$ex->GetString() : $ex->GetString()); | |
| 44 | 44 | } | 
| 45 | 45 | else | 
| 46 | 46 |  		{ | 
| @@ -86,8 +86,7 @@ discard block | ||
| 86 | 86 | if (!is_array($environments)) | 
| 87 | 87 |          { | 
| 88 | 88 |              throw new \Exception('File with description of environments is missing'); | 
| 89 | - } | |
| 90 | - elseif (count($environments) == 0) | |
| 89 | + } elseif (count($environments) == 0) | |
| 91 | 90 |          { | 
| 92 | 91 |              throw new \Exception('Environments not found in description file'); | 
| 93 | 92 | } | 
| @@ -100,8 +99,7 @@ discard block | ||
| 100 | 99 |              { | 
| 101 | 100 |                  throw new \Exception('Invalid environment code!'); | 
| 102 | 101 | } | 
| 103 | - } | |
| 104 | - else | |
| 102 | + } else | |
| 105 | 103 |          { | 
| 106 | 104 | foreach ($environments as $code => $environment) | 
| 107 | 105 |              { | 
| @@ -171,8 +169,7 @@ discard block | ||
| 171 | 169 | if ($item->isDir()) | 
| 172 | 170 |              { | 
| 173 | 171 | $fs->mkdir($itemPath); | 
| 174 | - } | |
| 175 | - else | |
| 172 | + } else | |
| 176 | 173 |              { | 
| 177 | 174 | $fs->copy($item, $itemPath, true); | 
| 178 | 175 | } | 
| @@ -227,10 +224,10 @@ discard block | ||
| 227 | 224 | if ($app->getConfiguration()) | 
| 228 | 225 |          { | 
| 229 | 226 | $app->addCommands(ModuleCommand::getCommands()); | 
| 230 | - if ($app->getBitrixStatus() != \Notamedia\ConsoleJedi\Application\Application::BITRIX_STATUS_COMPLETE) | |
| 231 | -                throw new BitrixException('Bitrix core is not available'); | |
| 232 | - } | |
| 233 | - else | |
| 227 | +            if ($app->getBitrixStatus() != \Notamedia\ConsoleJedi\Application\Application::BITRIX_STATUS_COMPLETE) { | |
| 228 | +                            throw new BitrixException('Bitrix core is not available'); | |
| 229 | + } | |
| 230 | + } else | |
| 234 | 231 |          { | 
| 235 | 232 |              throw new BitrixException('No configuration loaded'); | 
| 236 | 233 | } | 
| @@ -265,14 +262,12 @@ discard block | ||
| 265 | 262 | |
| 266 | 263 | $bar->clear(); | 
| 267 | 264 | $output->writeln($message . '<info>ok</info>'); | 
| 268 | - } | |
| 269 | - catch (ModuleInstallException $e) | |
| 265 | + } catch (ModuleInstallException $e) | |
| 270 | 266 |              { | 
| 271 | 267 | $bar->clear(); | 
| 272 | 268 | $output->writeln($e->getMessage(), OutputInterface::VERBOSITY_VERBOSE); | 
| 273 | 269 | $output->writeln($message . '<comment>not registered</comment> (install it in admin panel)'); | 
| 274 | - } | |
| 275 | - catch (ModuleException $e) | |
| 270 | + } catch (ModuleException $e) | |
| 276 | 271 |              { | 
| 277 | 272 | $bar->clear(); | 
| 278 | 273 | $output->writeln($e->getMessage(), OutputInterface::VERBOSITY_VERBOSE); | 
| @@ -346,8 +341,7 @@ discard block | ||
| 346 | 341 |                  if ($serverId && !$input->getOption('memcache-cold-start')) | 
| 347 | 342 |                  { | 
| 348 | 343 | $memcache->Resume($serverId); | 
| 349 | - } | |
| 350 | - else | |
| 344 | + } else | |
| 351 | 345 |                  { | 
| 352 | 346 | $exception = $APPLICATION->GetException(); | 
| 353 | 347 | $message = 'Invalid memcache config with index ' . $index; | 
| @@ -391,13 +385,11 @@ discard block | ||
| 391 | 385 | if (isset($value['value']) && isset($value['siteId'])) | 
| 392 | 386 |                      { | 
| 393 | 387 | Option::set($module, $code, $value['value'], $value['siteId']); | 
| 394 | - } | |
| 395 | - else | |
| 388 | + } else | |
| 396 | 389 |                      { | 
| 397 | 390 |                          $output->writeln('<error>Invalid option for module "' . $module . '" with code "' . $code. '"</error>'); | 
| 398 | 391 | } | 
| 399 | - } | |
| 400 | - else | |
| 392 | + } else | |
| 401 | 393 |                  { | 
| 402 | 394 | Option::set($module, $code, $value); | 
| 403 | 395 | |
| @@ -74,14 +74,14 @@ discard block | ||
| 74 | 74 |              throw new \Exception('Config env-dir is missing'); | 
| 75 | 75 | } | 
| 76 | 76 | |
| 77 | - $dir = $this->getApplication()->getRoot() . '/' . $this->getApplication()->getConfiguration()['env-dir']; | |
| 77 | + $dir = $this->getApplication()->getRoot().'/'.$this->getApplication()->getConfiguration()['env-dir']; | |
| 78 | 78 | |
| 79 | 79 | if (!is_dir($dir)) | 
| 80 | 80 |          { | 
| 81 | -            throw new \Exception('Directory ' . $dir . ' is missing'); | |
| 81 | +            throw new \Exception('Directory '.$dir.' is missing'); | |
| 82 | 82 | } | 
| 83 | 83 | |
| 84 | - $environments = include $dir . '/index.php'; | |
| 84 | + $environments = include $dir.'/index.php'; | |
| 85 | 85 | |
| 86 | 86 | if (!is_array($environments)) | 
| 87 | 87 |          { | 
| @@ -118,8 +118,8 @@ discard block | ||
| 118 | 118 |              throw new \Exception('Environment path not found!'); | 
| 119 | 119 | } | 
| 120 | 120 | |
| 121 | - $this->dir = $dir . '/' . $environments[$code]['path']; | |
| 122 | - $this->config = include $this->dir . '/config.php'; | |
| 121 | + $this->dir = $dir.'/'.$environments[$code]['path']; | |
| 122 | + $this->config = include $this->dir.'/config.php'; | |
| 123 | 123 | } | 
| 124 | 124 | |
| 125 | 125 | /** | 
| @@ -134,11 +134,11 @@ discard block | ||
| 134 | 134 | |
| 135 | 135 | foreach ($this->config as $config => $settings) | 
| 136 | 136 |          { | 
| 137 | - $method = 'configure' . ucfirst($config); | |
| 137 | + $method = 'configure'.ucfirst($config); | |
| 138 | 138 | |
| 139 | 139 | if (!in_array($method, $this->bootstrap) && method_exists($this, $method)) | 
| 140 | 140 |              { | 
| 141 | -                $output->writeln('<comment>Setup "' . $config . '"</comment>'); | |
| 141 | +                $output->writeln('<comment>Setup "'.$config.'"</comment>'); | |
| 142 | 142 | $this->$method($input, $output, $settings); | 
| 143 | 143 | } | 
| 144 | 144 | } | 
| @@ -166,7 +166,7 @@ discard block | ||
| 166 | 166 | continue; | 
| 167 | 167 | } | 
| 168 | 168 | |
| 169 | - $itemPath = $this->getApplication()->getRoot() . '/' . $iterator->getSubPathName(); | |
| 169 | + $itemPath = $this->getApplication()->getRoot().'/'.$iterator->getSubPathName(); | |
| 170 | 170 | |
| 171 | 171 | if ($item->isDir()) | 
| 172 | 172 |              { | 
| @@ -177,7 +177,7 @@ discard block | ||
| 177 | 177 | $fs->copy($item, $itemPath, true); | 
| 178 | 178 | } | 
| 179 | 179 | |
| 180 | -            $output->writeln('   ' . $itemPath); | |
| 180 | +            $output->writeln('   '.$itemPath); | |
| 181 | 181 | } | 
| 182 | 182 | } | 
| 183 | 183 | |
| @@ -207,8 +207,8 @@ discard block | ||
| 207 | 207 |              throw new \InvalidArgumentException('Config "licenseKey" must be string type.'); | 
| 208 | 208 | } | 
| 209 | 209 | |
| 210 | - $licenseFileContent = "<" . "? $" . "LICENSE_KEY = \"" . EscapePHPString($licenseKey) . "\"; ?" . ">"; | |
| 211 | - File::putFileContents(Application::getDocumentRoot() . BX_ROOT . '/license_key.php', $licenseFileContent); | |
| 210 | + $licenseFileContent = "<"."? $"."LICENSE_KEY = \"".EscapePHPString($licenseKey)."\"; ?".">"; | |
| 211 | + File::putFileContents(Application::getDocumentRoot().BX_ROOT.'/license_key.php', $licenseFileContent); | |
| 212 | 212 | } | 
| 213 | 213 | |
| 214 | 214 | /** | 
| @@ -251,7 +251,7 @@ discard block | ||
| 251 | 251 | |
| 252 | 252 | foreach ($modules as $moduleName) | 
| 253 | 253 |          { | 
| 254 | - $message = "\r" . ' module:load ' . $moduleName . ': '; | |
| 254 | + $message = "\r".' module:load '.$moduleName.': '; | |
| 255 | 255 | |
| 256 | 256 | try | 
| 257 | 257 |              { | 
| @@ -264,19 +264,19 @@ discard block | ||
| 264 | 264 | (new Module($moduleName))->load()->register(); | 
| 265 | 265 | |
| 266 | 266 | $bar->clear(); | 
| 267 | - $output->writeln($message . '<info>ok</info>'); | |
| 267 | + $output->writeln($message.'<info>ok</info>'); | |
| 268 | 268 | } | 
| 269 | 269 | catch (ModuleInstallException $e) | 
| 270 | 270 |              { | 
| 271 | 271 | $bar->clear(); | 
| 272 | 272 | $output->writeln($e->getMessage(), OutputInterface::VERBOSITY_VERBOSE); | 
| 273 | - $output->writeln($message . '<comment>not registered</comment> (install it in admin panel)'); | |
| 273 | + $output->writeln($message.'<comment>not registered</comment> (install it in admin panel)'); | |
| 274 | 274 | } | 
| 275 | 275 | catch (ModuleException $e) | 
| 276 | 276 |              { | 
| 277 | 277 | $bar->clear(); | 
| 278 | 278 | $output->writeln($e->getMessage(), OutputInterface::VERBOSITY_VERBOSE); | 
| 279 | - $output->writeln($message . '<error>FAILED</error>'); | |
| 279 | + $output->writeln($message.'<error>FAILED</error>'); | |
| 280 | 280 | } | 
| 281 | 281 | $bar->advance(); | 
| 282 | 282 | } | 
| @@ -350,14 +350,14 @@ discard block | ||
| 350 | 350 | else | 
| 351 | 351 |                  { | 
| 352 | 352 | $exception = $APPLICATION->GetException(); | 
| 353 | - $message = 'Invalid memcache config with index ' . $index; | |
| 353 | + $message = 'Invalid memcache config with index '.$index; | |
| 354 | 354 | |
| 355 | 355 | if ($exception->GetString()) | 
| 356 | 356 |                      { | 
| 357 | 357 |                          $message = str_replace('<br>', "\n", $exception->GetString()); | 
| 358 | 358 | } | 
| 359 | 359 | |
| 360 | -                    $output->writeln('<error>' . $message . '</error>'); | |
| 360 | +                    $output->writeln('<error>'.$message.'</error>'); | |
| 361 | 361 | } | 
| 362 | 362 | } | 
| 363 | 363 | } | 
| @@ -394,14 +394,14 @@ discard block | ||
| 394 | 394 | } | 
| 395 | 395 | else | 
| 396 | 396 |                      { | 
| 397 | -                        $output->writeln('<error>Invalid option for module "' . $module . '" with code "' . $code. '"</error>'); | |
| 397 | +                        $output->writeln('<error>Invalid option for module "'.$module.'" with code "'.$code.'"</error>'); | |
| 398 | 398 | } | 
| 399 | 399 | } | 
| 400 | 400 | else | 
| 401 | 401 |                  { | 
| 402 | 402 | Option::set($module, $code, $value); | 
| 403 | 403 | |
| 404 | -                    $output->writeln('   option: "' . $code . '", module: "' . $module . '"'); | |
| 404 | +                    $output->writeln('   option: "'.$code.'", module: "'.$module.'"'); | |
| 405 | 405 | } | 
| 406 | 406 | } | 
| 407 | 407 | } | 
| @@ -73,8 +73,7 @@ discard block | ||
| 73 | 73 | try | 
| 74 | 74 |  		{ | 
| 75 | 75 | $this->getObject(); | 
| 76 | - } | |
| 77 | - catch (Exception\ModuleNotFoundException $e) | |
| 76 | + } catch (Exception\ModuleNotFoundException $e) | |
| 78 | 77 |  		{ | 
| 79 | 78 | return false; | 
| 80 | 79 | } | 
| @@ -342,8 +341,7 @@ discard block | ||
| 342 | 341 |  					\CEventLog::Log("INFO", "MP_MODULE_DOWNLOADED", "main", $key, $value); | 
| 343 | 342 | } | 
| 344 | 343 | } | 
| 345 | - } | |
| 346 | - else | |
| 344 | + } else | |
| 347 | 345 |  		{ | 
| 348 | 346 |  			throw new Exception\ModuleUpdateException('[CL04] UpdateStepModules failed. ' . $errorMessage, $this->getName()); | 
| 349 | 347 | } | 
| @@ -18,395 +18,395 @@ | ||
| 18 | 18 | */ | 
| 19 | 19 | class Module | 
| 20 | 20 |  { | 
| 21 | - /** @var string */ | |
| 22 | - private $name; | |
| 23 | - | |
| 24 | - /** @var \CModule */ | |
| 25 | - private $object; | |
| 26 | - | |
| 27 | - /** @var bool */ | |
| 28 | - private $beta = false; | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * @param string $moduleName | |
| 32 | - */ | |
| 33 | - public function __construct($moduleName) | |
| 34 | -	{ | |
| 35 | - $this->name = $this->normalizeName($moduleName); | |
| 36 | - } | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * @param string $moduleName | |
| 40 | - * @return string | |
| 41 | - */ | |
| 42 | - protected function normalizeName($moduleName) | |
| 43 | -	{ | |
| 44 | -		return preg_replace("/[^a-zA-Z0-9_.]+/i", "", trim($moduleName)); | |
| 45 | - } | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * @return \CModule | |
| 49 | - */ | |
| 50 | - protected function &getObject() | |
| 51 | -	{ | |
| 52 | - if (!isset($this->object)) | |
| 53 | -		{ | |
| 54 | - $this->object = \CModule::CreateModuleObject($this->name); | |
| 55 | - } | |
| 56 | - | |
| 57 | - if (!is_object($this->object) || !($this->object instanceof \CModule)) | |
| 58 | -		{ | |
| 59 | - unset($this->object); | |
| 60 | -			throw new Exception\ModuleNotFoundException('Module not found or incorrect', $this->name); | |
| 61 | - } | |
| 62 | - | |
| 63 | - return $this->object; | |
| 64 | - } | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * Checks for module and module object existence | |
| 68 | - * | |
| 69 | - * @return bool | |
| 70 | - */ | |
| 71 | - public function exist() | |
| 72 | -	{ | |
| 73 | - try | |
| 74 | -		{ | |
| 75 | - $this->getObject(); | |
| 76 | - } | |
| 77 | - catch (Exception\ModuleNotFoundException $e) | |
| 78 | -		{ | |
| 79 | - return false; | |
| 80 | - } | |
| 81 | - | |
| 82 | - return true; | |
| 83 | - } | |
| 84 | - | |
| 85 | - /** | |
| 86 | - * Check if module exists and installed | |
| 87 | - * | |
| 88 | - * @return bool | |
| 89 | - */ | |
| 90 | - public function isRegistered() | |
| 91 | -	{ | |
| 92 | - return ModuleManager::isModuleInstalled($this->name) && $this->exist(); | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * @return bool true for marketplace modules, false for kernel modules | |
| 97 | - */ | |
| 98 | - public function isThirdParty() | |
| 99 | -	{ | |
| 100 | - return strpos($this->name, '.') !== false; | |
| 101 | - } | |
| 102 | - | |
| 103 | - /** | |
| 104 | - * Install module | |
| 105 | - * | |
| 106 | - * @throws Exception\ModuleException | |
| 107 | - * @throws BitrixException | |
| 108 | - */ | |
| 109 | - public function register() | |
| 110 | -	{ | |
| 111 | - if (!$this->isRegistered()) | |
| 112 | -		{ | |
| 113 | - $moduleObject =& $this->getObject(); | |
| 114 | - | |
| 115 | - /** | |
| 116 | - * It's important to check if module class defines InstallDB method (it must register module) | |
| 117 | - * Thus absent InstallDB indicates that the module does not support automatic installation | |
| 118 | - */ | |
| 119 | -			if ((new \ReflectionClass($moduleObject))->getMethod('InstallDB')->class !== get_class($moduleObject)) | |
| 120 | -			{ | |
| 121 | - throw new Exception\ModuleInstallException( | |
| 122 | - 'Missing InstallDB method. This module does not support automatic installation', | |
| 123 | - $this->name | |
| 124 | - ); | |
| 125 | - } | |
| 126 | - | |
| 127 | - if (!$moduleObject->InstallDB() && BitrixException::hasException()) | |
| 128 | -			{ | |
| 129 | - throw new Exception\ModuleInstallException( | |
| 130 | - get_class($moduleObject) . '::InstallDB() returned false', | |
| 131 | - $this->name | |
| 132 | - ); | |
| 133 | - } | |
| 134 | - | |
| 135 | - $moduleObject->InstallEvents(); | |
| 136 | - | |
| 137 | - /** @noinspection PhpVoidFunctionResultUsedInspection */ | |
| 138 | - if (!$moduleObject->InstallFiles() && BitrixException::hasException()) | |
| 139 | -			{ | |
| 140 | - throw new Exception\ModuleInstallException( | |
| 141 | - get_class($moduleObject) . '::InstallFiles() returned false', | |
| 142 | - $this->name | |
| 143 | - ); | |
| 144 | - } | |
| 145 | - | |
| 146 | - if (!$this->isRegistered()) | |
| 147 | -			{ | |
| 148 | - throw new Exception\ModuleInstallException( | |
| 149 | - 'Module was not registered. Probably it does not support automatic installation.', | |
| 150 | - $this->name | |
| 151 | - ); | |
| 152 | - } | |
| 153 | - } | |
| 154 | - | |
| 155 | - return $this; | |
| 156 | - } | |
| 157 | - | |
| 158 | - /** | |
| 159 | - * Download module from marketplace | |
| 160 | - * | |
| 161 | - * @return $this | |
| 162 | - */ | |
| 163 | - public function load() | |
| 164 | -	{ | |
| 165 | - if (!$this->isRegistered()) | |
| 166 | -		{ | |
| 167 | - if (!$this->exist()) | |
| 168 | -			{ | |
| 169 | - require_once($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/classes/general/update_client_partner.php'); | |
| 170 | - | |
| 171 | - if (!\CUpdateClientPartner::LoadModuleNoDemand( | |
| 172 | - $this->getName(), | |
| 173 | - $strError, | |
| 174 | - $this->isBeta() ? 'N' : 'Y', | |
| 175 | - LANGUAGE_ID) | |
| 176 | - ) | |
| 177 | -				{ | |
| 178 | - throw new Exception\ModuleLoadException($strError, $this->getName()); | |
| 179 | - } | |
| 180 | - } | |
| 181 | - } | |
| 182 | - | |
| 183 | - return $this; | |
| 184 | - } | |
| 185 | - | |
| 186 | - /** | |
| 187 | - * Uninstall module | |
| 188 | - * | |
| 189 | - * @throws Exception\ModuleException | |
| 190 | - * @throws BitrixException | |
| 191 | - */ | |
| 192 | - public function unRegister() | |
| 193 | -	{ | |
| 194 | - $moduleObject = $this->getObject(); | |
| 195 | - | |
| 196 | - if ($this->isRegistered()) | |
| 197 | -		{ | |
| 198 | - /** | |
| 199 | - * It's important to check if module class defines UnInstallDB method (it should unregister module) | |
| 200 | - * Thus absent UnInstallDB indicates that the module does not support automatic uninstallation | |
| 201 | - */ | |
| 202 | -			if ((new \ReflectionClass($moduleObject))->getMethod('UnInstallDB')->class !== get_class($moduleObject)) | |
| 203 | -			{ | |
| 204 | - throw new Exception\ModuleUninstallException( | |
| 205 | - 'Missing UnInstallDB method. This module does not support automatic uninstallation', | |
| 206 | - $this->name | |
| 207 | - ); | |
| 208 | - } | |
| 209 | - | |
| 210 | - /** @noinspection PhpVoidFunctionResultUsedInspection */ | |
| 211 | - if (!$moduleObject->UnInstallFiles() && BitrixException::hasException()) | |
| 212 | -			{ | |
| 213 | - throw new Exception\ModuleUninstallException( | |
| 214 | - get_class($moduleObject) . '::UnInstallFiles() returned false', | |
| 215 | - $this->name | |
| 216 | - ); | |
| 217 | - } | |
| 218 | - | |
| 219 | - $moduleObject->UnInstallEvents(); | |
| 220 | - | |
| 221 | - /** @noinspection PhpVoidFunctionResultUsedInspection */ | |
| 222 | - if (!$moduleObject->UnInstallDB() && BitrixException::hasException()) | |
| 223 | -			{ | |
| 224 | - throw new Exception\ModuleUninstallException( | |
| 225 | - get_class($moduleObject) . '::UnInstallFiles() returned false', | |
| 226 | - $this->name | |
| 227 | - ); | |
| 228 | - } | |
| 229 | - | |
| 230 | - if ($this->isRegistered()) | |
| 231 | -			{ | |
| 232 | -				throw new Exception\ModuleUninstallException('Module was not unregistered', $this->name); | |
| 233 | - } | |
| 234 | - } | |
| 235 | - | |
| 236 | - return $this; | |
| 237 | - } | |
| 238 | - | |
| 239 | - /** | |
| 240 | - * Uninstall and remove module directory | |
| 241 | - */ | |
| 242 | - public function remove() | |
| 243 | -	{ | |
| 244 | - if ($this->isRegistered()) | |
| 245 | -		{ | |
| 246 | - $this->unRegister(); | |
| 247 | - } | |
| 248 | - | |
| 249 | -		$path = getLocalPath('modules/' . $this->getName()); | |
| 250 | - | |
| 251 | - if ($path) | |
| 252 | -		{ | |
| 253 | - (new Filesystem())->remove($_SERVER['DOCUMENT_ROOT'] . $path); | |
| 254 | - } | |
| 255 | - | |
| 256 | - unset($this->object); | |
| 257 | - | |
| 258 | - return $this; | |
| 259 | - } | |
| 260 | - | |
| 261 | - /** | |
| 262 | - * Update module | |
| 263 | - * | |
| 264 | - * It must be called repeatedly until the method returns false. | |
| 265 | - * After each call php must be restarted (new process created) to update module class and function definitions. | |
| 266 | - * | |
| 267 | - * @param array $modulesUpdated [optional] | |
| 268 | - * @return bool | |
| 269 | - */ | |
| 270 | - public function update(&$modulesUpdated = null) | |
| 271 | -	{ | |
| 272 | - require_once($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/classes/general/update_client_partner.php'); | |
| 273 | - | |
| 274 | - if (!$this->isThirdParty()) | |
| 275 | -		{ | |
| 276 | -			throw new Exception\ModuleUpdateException('Kernel module updates are currently not supported.', $this->getName()); | |
| 277 | - } | |
| 278 | - | |
| 279 | - // ensures module existence | |
| 280 | - $this->getObject(); | |
| 281 | - | |
| 282 | - $errorMessage = $updateDescription = null; | |
| 283 | - $loadResult = \CUpdateClientPartner::LoadModulesUpdates( | |
| 284 | - $errorMessage, | |
| 285 | - $updateDescription, | |
| 286 | - LANGUAGE_ID, | |
| 287 | - $this->isBeta() ? 'N' : 'Y', | |
| 288 | - [$this->getName()], | |
| 289 | - true | |
| 290 | - ); | |
| 291 | - switch ($loadResult) | |
| 292 | -		{ | |
| 293 | - // archive loaded | |
| 294 | - case "S": | |
| 295 | - return $this->update($modulesUpdated); | |
| 296 | - | |
| 297 | - // error | |
| 298 | - case "E": | |
| 299 | - throw new Exception\ModuleUpdateException($errorMessage, $this->getName()); | |
| 300 | - | |
| 301 | - // finished installing updates | |
| 302 | - case "F": | |
| 303 | - return false; | |
| 304 | - | |
| 305 | - // need to process loaded update | |
| 306 | - case 'U': | |
| 307 | - break; | |
| 308 | - } | |
| 309 | - | |
| 310 | - /** @var string Temp directory with update files */ | |
| 311 | - $updateDir = null; | |
| 312 | - | |
| 313 | - if (!\CUpdateClientPartner::UnGzipArchive($updateDir, $errorMessage, true)) | |
| 314 | -		{ | |
| 315 | -			throw new Exception\ModuleUpdateException('[CL02] UnGzipArchive failed. ' . $errorMessage, $this->getName()); | |
| 316 | - } | |
| 317 | - | |
| 318 | - $this->validateUpdate($updateDir); | |
| 319 | - | |
| 320 | - if (isset($updateDescription["DATA"]["#"]["NOUPDATES"])) | |
| 321 | -		{ | |
| 322 | - \CUpdateClientPartner::ClearUpdateFolder($_SERVER["DOCUMENT_ROOT"] . "/bitrix/updates/" . $updateDir); | |
| 323 | - return false; | |
| 324 | - } | |
| 325 | - | |
| 326 | - $modulesUpdated = $updateDescr = []; | |
| 327 | - if (isset($updateDescription["DATA"]["#"]["ITEM"])) | |
| 328 | -		{ | |
| 329 | - foreach ($updateDescription["DATA"]["#"]["ITEM"] as $moduleInfo) | |
| 330 | -			{ | |
| 331 | - $modulesUpdated[$moduleInfo["@"]["NAME"]] = $moduleInfo["@"]["VALUE"]; | |
| 332 | - $updateDescr[$moduleInfo["@"]["NAME"]] = $moduleInfo["@"]["DESCR"]; | |
| 333 | - } | |
| 334 | - } | |
| 335 | - | |
| 336 | - if (\CUpdateClientPartner::UpdateStepModules($updateDir, $errorMessage)) | |
| 337 | -		{ | |
| 338 | - foreach ($modulesUpdated as $key => $value) | |
| 339 | -			{ | |
| 340 | -				if (Option::set('main', 'event_log_marketplace', "Y") === "Y") | |
| 341 | -				{ | |
| 342 | -					\CEventLog::Log("INFO", "MP_MODULE_DOWNLOADED", "main", $key, $value); | |
| 343 | - } | |
| 344 | - } | |
| 345 | - } | |
| 346 | - else | |
| 347 | -		{ | |
| 348 | -			throw new Exception\ModuleUpdateException('[CL04] UpdateStepModules failed. ' . $errorMessage, $this->getName()); | |
| 349 | - } | |
| 350 | - | |
| 351 | - return true; | |
| 352 | - } | |
| 353 | - | |
| 354 | - /** | |
| 355 | - * Check update files | |
| 356 | - * | |
| 357 | - * @param string $updateDir | |
| 358 | - */ | |
| 359 | - protected function validateUpdate($updateDir) | |
| 360 | -	{ | |
| 361 | - $errorMessage = null; | |
| 362 | - if (!\CUpdateClientPartner::CheckUpdatability($updateDir, $errorMessage)) | |
| 363 | -		{ | |
| 364 | -			throw new Exception\ModuleUpdateException('[CL03] CheckUpdatability failed. ' . $errorMessage, $this->getName()); | |
| 365 | - } | |
| 366 | - | |
| 367 | - if (isset($updateDescription["DATA"]["#"]["ERROR"])) | |
| 368 | -		{ | |
| 369 | - $errorMessage = ""; | |
| 370 | - foreach ($updateDescription["DATA"]["#"]["ERROR"] as $errorDescription) | |
| 371 | -			{ | |
| 372 | - $errorMessage .= "[" . $errorDescription["@"]["TYPE"] . "] " . $errorDescription["#"]; | |
| 373 | - } | |
| 374 | - throw new Exception\ModuleUpdateException($errorMessage, $this->getName()); | |
| 375 | - } | |
| 376 | - } | |
| 377 | - | |
| 378 | - /** | |
| 379 | - * Returns module name | |
| 380 | - * | |
| 381 | - * @return string | |
| 382 | - */ | |
| 383 | - public function getName() | |
| 384 | -	{ | |
| 385 | - return $this->name; | |
| 386 | - } | |
| 387 | - | |
| 388 | - /** | |
| 389 | - * Beta releases allowed? | |
| 390 | - * | |
| 391 | - * @return boolean | |
| 392 | - */ | |
| 393 | - public function isBeta() | |
| 394 | -	{ | |
| 395 | - return $this->beta; | |
| 396 | - } | |
| 397 | - | |
| 398 | - /** | |
| 399 | - * Set beta releases installation | |
| 400 | - * | |
| 401 | - * @param boolean $beta | |
| 402 | - */ | |
| 403 | - public function setBeta($beta = true) | |
| 404 | -	{ | |
| 405 | - $this->beta = $beta; | |
| 406 | - } | |
| 407 | - | |
| 408 | - public function getVersion() | |
| 409 | -	{ | |
| 410 | - return $this->getObject()->MODULE_VERSION; | |
| 411 | - } | |
| 21 | + /** @var string */ | |
| 22 | + private $name; | |
| 23 | + | |
| 24 | + /** @var \CModule */ | |
| 25 | + private $object; | |
| 26 | + | |
| 27 | + /** @var bool */ | |
| 28 | + private $beta = false; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @param string $moduleName | |
| 32 | + */ | |
| 33 | + public function __construct($moduleName) | |
| 34 | +    { | |
| 35 | + $this->name = $this->normalizeName($moduleName); | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * @param string $moduleName | |
| 40 | + * @return string | |
| 41 | + */ | |
| 42 | + protected function normalizeName($moduleName) | |
| 43 | +    { | |
| 44 | +        return preg_replace("/[^a-zA-Z0-9_.]+/i", "", trim($moduleName)); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * @return \CModule | |
| 49 | + */ | |
| 50 | + protected function &getObject() | |
| 51 | +    { | |
| 52 | + if (!isset($this->object)) | |
| 53 | +        { | |
| 54 | + $this->object = \CModule::CreateModuleObject($this->name); | |
| 55 | + } | |
| 56 | + | |
| 57 | + if (!is_object($this->object) || !($this->object instanceof \CModule)) | |
| 58 | +        { | |
| 59 | + unset($this->object); | |
| 60 | +            throw new Exception\ModuleNotFoundException('Module not found or incorrect', $this->name); | |
| 61 | + } | |
| 62 | + | |
| 63 | + return $this->object; | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * Checks for module and module object existence | |
| 68 | + * | |
| 69 | + * @return bool | |
| 70 | + */ | |
| 71 | + public function exist() | |
| 72 | +    { | |
| 73 | + try | |
| 74 | +        { | |
| 75 | + $this->getObject(); | |
| 76 | + } | |
| 77 | + catch (Exception\ModuleNotFoundException $e) | |
| 78 | +        { | |
| 79 | + return false; | |
| 80 | + } | |
| 81 | + | |
| 82 | + return true; | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Check if module exists and installed | |
| 87 | + * | |
| 88 | + * @return bool | |
| 89 | + */ | |
| 90 | + public function isRegistered() | |
| 91 | +    { | |
| 92 | + return ModuleManager::isModuleInstalled($this->name) && $this->exist(); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @return bool true for marketplace modules, false for kernel modules | |
| 97 | + */ | |
| 98 | + public function isThirdParty() | |
| 99 | +    { | |
| 100 | + return strpos($this->name, '.') !== false; | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * Install module | |
| 105 | + * | |
| 106 | + * @throws Exception\ModuleException | |
| 107 | + * @throws BitrixException | |
| 108 | + */ | |
| 109 | + public function register() | |
| 110 | +    { | |
| 111 | + if (!$this->isRegistered()) | |
| 112 | +        { | |
| 113 | + $moduleObject =& $this->getObject(); | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * It's important to check if module class defines InstallDB method (it must register module) | |
| 117 | + * Thus absent InstallDB indicates that the module does not support automatic installation | |
| 118 | + */ | |
| 119 | +            if ((new \ReflectionClass($moduleObject))->getMethod('InstallDB')->class !== get_class($moduleObject)) | |
| 120 | +            { | |
| 121 | + throw new Exception\ModuleInstallException( | |
| 122 | + 'Missing InstallDB method. This module does not support automatic installation', | |
| 123 | + $this->name | |
| 124 | + ); | |
| 125 | + } | |
| 126 | + | |
| 127 | + if (!$moduleObject->InstallDB() && BitrixException::hasException()) | |
| 128 | +            { | |
| 129 | + throw new Exception\ModuleInstallException( | |
| 130 | + get_class($moduleObject) . '::InstallDB() returned false', | |
| 131 | + $this->name | |
| 132 | + ); | |
| 133 | + } | |
| 134 | + | |
| 135 | + $moduleObject->InstallEvents(); | |
| 136 | + | |
| 137 | + /** @noinspection PhpVoidFunctionResultUsedInspection */ | |
| 138 | + if (!$moduleObject->InstallFiles() && BitrixException::hasException()) | |
| 139 | +            { | |
| 140 | + throw new Exception\ModuleInstallException( | |
| 141 | + get_class($moduleObject) . '::InstallFiles() returned false', | |
| 142 | + $this->name | |
| 143 | + ); | |
| 144 | + } | |
| 145 | + | |
| 146 | + if (!$this->isRegistered()) | |
| 147 | +            { | |
| 148 | + throw new Exception\ModuleInstallException( | |
| 149 | + 'Module was not registered. Probably it does not support automatic installation.', | |
| 150 | + $this->name | |
| 151 | + ); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + | |
| 155 | + return $this; | |
| 156 | + } | |
| 157 | + | |
| 158 | + /** | |
| 159 | + * Download module from marketplace | |
| 160 | + * | |
| 161 | + * @return $this | |
| 162 | + */ | |
| 163 | + public function load() | |
| 164 | +    { | |
| 165 | + if (!$this->isRegistered()) | |
| 166 | +        { | |
| 167 | + if (!$this->exist()) | |
| 168 | +            { | |
| 169 | + require_once($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/classes/general/update_client_partner.php'); | |
| 170 | + | |
| 171 | + if (!\CUpdateClientPartner::LoadModuleNoDemand( | |
| 172 | + $this->getName(), | |
| 173 | + $strError, | |
| 174 | + $this->isBeta() ? 'N' : 'Y', | |
| 175 | + LANGUAGE_ID) | |
| 176 | + ) | |
| 177 | +                { | |
| 178 | + throw new Exception\ModuleLoadException($strError, $this->getName()); | |
| 179 | + } | |
| 180 | + } | |
| 181 | + } | |
| 182 | + | |
| 183 | + return $this; | |
| 184 | + } | |
| 185 | + | |
| 186 | + /** | |
| 187 | + * Uninstall module | |
| 188 | + * | |
| 189 | + * @throws Exception\ModuleException | |
| 190 | + * @throws BitrixException | |
| 191 | + */ | |
| 192 | + public function unRegister() | |
| 193 | +    { | |
| 194 | + $moduleObject = $this->getObject(); | |
| 195 | + | |
| 196 | + if ($this->isRegistered()) | |
| 197 | +        { | |
| 198 | + /** | |
| 199 | + * It's important to check if module class defines UnInstallDB method (it should unregister module) | |
| 200 | + * Thus absent UnInstallDB indicates that the module does not support automatic uninstallation | |
| 201 | + */ | |
| 202 | +            if ((new \ReflectionClass($moduleObject))->getMethod('UnInstallDB')->class !== get_class($moduleObject)) | |
| 203 | +            { | |
| 204 | + throw new Exception\ModuleUninstallException( | |
| 205 | + 'Missing UnInstallDB method. This module does not support automatic uninstallation', | |
| 206 | + $this->name | |
| 207 | + ); | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** @noinspection PhpVoidFunctionResultUsedInspection */ | |
| 211 | + if (!$moduleObject->UnInstallFiles() && BitrixException::hasException()) | |
| 212 | +            { | |
| 213 | + throw new Exception\ModuleUninstallException( | |
| 214 | + get_class($moduleObject) . '::UnInstallFiles() returned false', | |
| 215 | + $this->name | |
| 216 | + ); | |
| 217 | + } | |
| 218 | + | |
| 219 | + $moduleObject->UnInstallEvents(); | |
| 220 | + | |
| 221 | + /** @noinspection PhpVoidFunctionResultUsedInspection */ | |
| 222 | + if (!$moduleObject->UnInstallDB() && BitrixException::hasException()) | |
| 223 | +            { | |
| 224 | + throw new Exception\ModuleUninstallException( | |
| 225 | + get_class($moduleObject) . '::UnInstallFiles() returned false', | |
| 226 | + $this->name | |
| 227 | + ); | |
| 228 | + } | |
| 229 | + | |
| 230 | + if ($this->isRegistered()) | |
| 231 | +            { | |
| 232 | +                throw new Exception\ModuleUninstallException('Module was not unregistered', $this->name); | |
| 233 | + } | |
| 234 | + } | |
| 235 | + | |
| 236 | + return $this; | |
| 237 | + } | |
| 238 | + | |
| 239 | + /** | |
| 240 | + * Uninstall and remove module directory | |
| 241 | + */ | |
| 242 | + public function remove() | |
| 243 | +    { | |
| 244 | + if ($this->isRegistered()) | |
| 245 | +        { | |
| 246 | + $this->unRegister(); | |
| 247 | + } | |
| 248 | + | |
| 249 | +        $path = getLocalPath('modules/' . $this->getName()); | |
| 250 | + | |
| 251 | + if ($path) | |
| 252 | +        { | |
| 253 | + (new Filesystem())->remove($_SERVER['DOCUMENT_ROOT'] . $path); | |
| 254 | + } | |
| 255 | + | |
| 256 | + unset($this->object); | |
| 257 | + | |
| 258 | + return $this; | |
| 259 | + } | |
| 260 | + | |
| 261 | + /** | |
| 262 | + * Update module | |
| 263 | + * | |
| 264 | + * It must be called repeatedly until the method returns false. | |
| 265 | + * After each call php must be restarted (new process created) to update module class and function definitions. | |
| 266 | + * | |
| 267 | + * @param array $modulesUpdated [optional] | |
| 268 | + * @return bool | |
| 269 | + */ | |
| 270 | + public function update(&$modulesUpdated = null) | |
| 271 | +    { | |
| 272 | + require_once($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/classes/general/update_client_partner.php'); | |
| 273 | + | |
| 274 | + if (!$this->isThirdParty()) | |
| 275 | +        { | |
| 276 | +            throw new Exception\ModuleUpdateException('Kernel module updates are currently not supported.', $this->getName()); | |
| 277 | + } | |
| 278 | + | |
| 279 | + // ensures module existence | |
| 280 | + $this->getObject(); | |
| 281 | + | |
| 282 | + $errorMessage = $updateDescription = null; | |
| 283 | + $loadResult = \CUpdateClientPartner::LoadModulesUpdates( | |
| 284 | + $errorMessage, | |
| 285 | + $updateDescription, | |
| 286 | + LANGUAGE_ID, | |
| 287 | + $this->isBeta() ? 'N' : 'Y', | |
| 288 | + [$this->getName()], | |
| 289 | + true | |
| 290 | + ); | |
| 291 | + switch ($loadResult) | |
| 292 | +        { | |
| 293 | + // archive loaded | |
| 294 | + case "S": | |
| 295 | + return $this->update($modulesUpdated); | |
| 296 | + | |
| 297 | + // error | |
| 298 | + case "E": | |
| 299 | + throw new Exception\ModuleUpdateException($errorMessage, $this->getName()); | |
| 300 | + | |
| 301 | + // finished installing updates | |
| 302 | + case "F": | |
| 303 | + return false; | |
| 304 | + | |
| 305 | + // need to process loaded update | |
| 306 | + case 'U': | |
| 307 | + break; | |
| 308 | + } | |
| 309 | + | |
| 310 | + /** @var string Temp directory with update files */ | |
| 311 | + $updateDir = null; | |
| 312 | + | |
| 313 | + if (!\CUpdateClientPartner::UnGzipArchive($updateDir, $errorMessage, true)) | |
| 314 | +        { | |
| 315 | +            throw new Exception\ModuleUpdateException('[CL02] UnGzipArchive failed. ' . $errorMessage, $this->getName()); | |
| 316 | + } | |
| 317 | + | |
| 318 | + $this->validateUpdate($updateDir); | |
| 319 | + | |
| 320 | + if (isset($updateDescription["DATA"]["#"]["NOUPDATES"])) | |
| 321 | +        { | |
| 322 | + \CUpdateClientPartner::ClearUpdateFolder($_SERVER["DOCUMENT_ROOT"] . "/bitrix/updates/" . $updateDir); | |
| 323 | + return false; | |
| 324 | + } | |
| 325 | + | |
| 326 | + $modulesUpdated = $updateDescr = []; | |
| 327 | + if (isset($updateDescription["DATA"]["#"]["ITEM"])) | |
| 328 | +        { | |
| 329 | + foreach ($updateDescription["DATA"]["#"]["ITEM"] as $moduleInfo) | |
| 330 | +            { | |
| 331 | + $modulesUpdated[$moduleInfo["@"]["NAME"]] = $moduleInfo["@"]["VALUE"]; | |
| 332 | + $updateDescr[$moduleInfo["@"]["NAME"]] = $moduleInfo["@"]["DESCR"]; | |
| 333 | + } | |
| 334 | + } | |
| 335 | + | |
| 336 | + if (\CUpdateClientPartner::UpdateStepModules($updateDir, $errorMessage)) | |
| 337 | +        { | |
| 338 | + foreach ($modulesUpdated as $key => $value) | |
| 339 | +            { | |
| 340 | +                if (Option::set('main', 'event_log_marketplace', "Y") === "Y") | |
| 341 | +                { | |
| 342 | +                    \CEventLog::Log("INFO", "MP_MODULE_DOWNLOADED", "main", $key, $value); | |
| 343 | + } | |
| 344 | + } | |
| 345 | + } | |
| 346 | + else | |
| 347 | +        { | |
| 348 | +            throw new Exception\ModuleUpdateException('[CL04] UpdateStepModules failed. ' . $errorMessage, $this->getName()); | |
| 349 | + } | |
| 350 | + | |
| 351 | + return true; | |
| 352 | + } | |
| 353 | + | |
| 354 | + /** | |
| 355 | + * Check update files | |
| 356 | + * | |
| 357 | + * @param string $updateDir | |
| 358 | + */ | |
| 359 | + protected function validateUpdate($updateDir) | |
| 360 | +    { | |
| 361 | + $errorMessage = null; | |
| 362 | + if (!\CUpdateClientPartner::CheckUpdatability($updateDir, $errorMessage)) | |
| 363 | +        { | |
| 364 | +            throw new Exception\ModuleUpdateException('[CL03] CheckUpdatability failed. ' . $errorMessage, $this->getName()); | |
| 365 | + } | |
| 366 | + | |
| 367 | + if (isset($updateDescription["DATA"]["#"]["ERROR"])) | |
| 368 | +        { | |
| 369 | + $errorMessage = ""; | |
| 370 | + foreach ($updateDescription["DATA"]["#"]["ERROR"] as $errorDescription) | |
| 371 | +            { | |
| 372 | + $errorMessage .= "[" . $errorDescription["@"]["TYPE"] . "] " . $errorDescription["#"]; | |
| 373 | + } | |
| 374 | + throw new Exception\ModuleUpdateException($errorMessage, $this->getName()); | |
| 375 | + } | |
| 376 | + } | |
| 377 | + | |
| 378 | + /** | |
| 379 | + * Returns module name | |
| 380 | + * | |
| 381 | + * @return string | |
| 382 | + */ | |
| 383 | + public function getName() | |
| 384 | +    { | |
| 385 | + return $this->name; | |
| 386 | + } | |
| 387 | + | |
| 388 | + /** | |
| 389 | + * Beta releases allowed? | |
| 390 | + * | |
| 391 | + * @return boolean | |
| 392 | + */ | |
| 393 | + public function isBeta() | |
| 394 | +    { | |
| 395 | + return $this->beta; | |
| 396 | + } | |
| 397 | + | |
| 398 | + /** | |
| 399 | + * Set beta releases installation | |
| 400 | + * | |
| 401 | + * @param boolean $beta | |
| 402 | + */ | |
| 403 | + public function setBeta($beta = true) | |
| 404 | +    { | |
| 405 | + $this->beta = $beta; | |
| 406 | + } | |
| 407 | + | |
| 408 | + public function getVersion() | |
| 409 | +    { | |
| 410 | + return $this->getObject()->MODULE_VERSION; | |
| 411 | + } | |
| 412 | 412 | } | 
| 413 | 413 | \ No newline at end of file | 
| @@ -110,7 +110,7 @@ discard block | ||
| 110 | 110 |  	{ | 
| 111 | 111 | if (!$this->isRegistered()) | 
| 112 | 112 |  		{ | 
| 113 | - $moduleObject =& $this->getObject(); | |
| 113 | + $moduleObject = & $this->getObject(); | |
| 114 | 114 | |
| 115 | 115 | /** | 
| 116 | 116 | * It's important to check if module class defines InstallDB method (it must register module) | 
| @@ -127,7 +127,7 @@ discard block | ||
| 127 | 127 | if (!$moduleObject->InstallDB() && BitrixException::hasException()) | 
| 128 | 128 |  			{ | 
| 129 | 129 | throw new Exception\ModuleInstallException( | 
| 130 | - get_class($moduleObject) . '::InstallDB() returned false', | |
| 130 | + get_class($moduleObject).'::InstallDB() returned false', | |
| 131 | 131 | $this->name | 
| 132 | 132 | ); | 
| 133 | 133 | } | 
| @@ -138,7 +138,7 @@ discard block | ||
| 138 | 138 | if (!$moduleObject->InstallFiles() && BitrixException::hasException()) | 
| 139 | 139 |  			{ | 
| 140 | 140 | throw new Exception\ModuleInstallException( | 
| 141 | - get_class($moduleObject) . '::InstallFiles() returned false', | |
| 141 | + get_class($moduleObject).'::InstallFiles() returned false', | |
| 142 | 142 | $this->name | 
| 143 | 143 | ); | 
| 144 | 144 | } | 
| @@ -166,7 +166,7 @@ discard block | ||
| 166 | 166 |  		{ | 
| 167 | 167 | if (!$this->exist()) | 
| 168 | 168 |  			{ | 
| 169 | - require_once($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/classes/general/update_client_partner.php'); | |
| 169 | + require_once($_SERVER["DOCUMENT_ROOT"].'/bitrix/modules/main/classes/general/update_client_partner.php'); | |
| 170 | 170 | |
| 171 | 171 | if (!\CUpdateClientPartner::LoadModuleNoDemand( | 
| 172 | 172 | $this->getName(), | 
| @@ -211,7 +211,7 @@ discard block | ||
| 211 | 211 | if (!$moduleObject->UnInstallFiles() && BitrixException::hasException()) | 
| 212 | 212 |  			{ | 
| 213 | 213 | throw new Exception\ModuleUninstallException( | 
| 214 | - get_class($moduleObject) . '::UnInstallFiles() returned false', | |
| 214 | + get_class($moduleObject).'::UnInstallFiles() returned false', | |
| 215 | 215 | $this->name | 
| 216 | 216 | ); | 
| 217 | 217 | } | 
| @@ -222,7 +222,7 @@ discard block | ||
| 222 | 222 | if (!$moduleObject->UnInstallDB() && BitrixException::hasException()) | 
| 223 | 223 |  			{ | 
| 224 | 224 | throw new Exception\ModuleUninstallException( | 
| 225 | - get_class($moduleObject) . '::UnInstallFiles() returned false', | |
| 225 | + get_class($moduleObject).'::UnInstallFiles() returned false', | |
| 226 | 226 | $this->name | 
| 227 | 227 | ); | 
| 228 | 228 | } | 
| @@ -246,11 +246,11 @@ discard block | ||
| 246 | 246 | $this->unRegister(); | 
| 247 | 247 | } | 
| 248 | 248 | |
| 249 | -		$path = getLocalPath('modules/' . $this->getName()); | |
| 249 | +		$path = getLocalPath('modules/'.$this->getName()); | |
| 250 | 250 | |
| 251 | 251 | if ($path) | 
| 252 | 252 |  		{ | 
| 253 | - (new Filesystem())->remove($_SERVER['DOCUMENT_ROOT'] . $path); | |
| 253 | + (new Filesystem())->remove($_SERVER['DOCUMENT_ROOT'].$path); | |
| 254 | 254 | } | 
| 255 | 255 | |
| 256 | 256 | unset($this->object); | 
| @@ -269,7 +269,7 @@ discard block | ||
| 269 | 269 | */ | 
| 270 | 270 | public function update(&$modulesUpdated = null) | 
| 271 | 271 |  	{ | 
| 272 | - require_once($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/main/classes/general/update_client_partner.php'); | |
| 272 | + require_once($_SERVER["DOCUMENT_ROOT"].'/bitrix/modules/main/classes/general/update_client_partner.php'); | |
| 273 | 273 | |
| 274 | 274 | if (!$this->isThirdParty()) | 
| 275 | 275 |  		{ | 
| @@ -312,14 +312,14 @@ discard block | ||
| 312 | 312 | |
| 313 | 313 | if (!\CUpdateClientPartner::UnGzipArchive($updateDir, $errorMessage, true)) | 
| 314 | 314 |  		{ | 
| 315 | -			throw new Exception\ModuleUpdateException('[CL02] UnGzipArchive failed. ' . $errorMessage, $this->getName()); | |
| 315 | +			throw new Exception\ModuleUpdateException('[CL02] UnGzipArchive failed. '.$errorMessage, $this->getName()); | |
| 316 | 316 | } | 
| 317 | 317 | |
| 318 | 318 | $this->validateUpdate($updateDir); | 
| 319 | 319 | |
| 320 | 320 | if (isset($updateDescription["DATA"]["#"]["NOUPDATES"])) | 
| 321 | 321 |  		{ | 
| 322 | - \CUpdateClientPartner::ClearUpdateFolder($_SERVER["DOCUMENT_ROOT"] . "/bitrix/updates/" . $updateDir); | |
| 322 | + \CUpdateClientPartner::ClearUpdateFolder($_SERVER["DOCUMENT_ROOT"]."/bitrix/updates/".$updateDir); | |
| 323 | 323 | return false; | 
| 324 | 324 | } | 
| 325 | 325 | |
| @@ -345,7 +345,7 @@ discard block | ||
| 345 | 345 | } | 
| 346 | 346 | else | 
| 347 | 347 |  		{ | 
| 348 | -			throw new Exception\ModuleUpdateException('[CL04] UpdateStepModules failed. ' . $errorMessage, $this->getName()); | |
| 348 | +			throw new Exception\ModuleUpdateException('[CL04] UpdateStepModules failed. '.$errorMessage, $this->getName()); | |
| 349 | 349 | } | 
| 350 | 350 | |
| 351 | 351 | return true; | 
| @@ -361,7 +361,7 @@ discard block | ||
| 361 | 361 | $errorMessage = null; | 
| 362 | 362 | if (!\CUpdateClientPartner::CheckUpdatability($updateDir, $errorMessage)) | 
| 363 | 363 |  		{ | 
| 364 | -			throw new Exception\ModuleUpdateException('[CL03] CheckUpdatability failed. ' . $errorMessage, $this->getName()); | |
| 364 | +			throw new Exception\ModuleUpdateException('[CL03] CheckUpdatability failed. '.$errorMessage, $this->getName()); | |
| 365 | 365 | } | 
| 366 | 366 | |
| 367 | 367 | if (isset($updateDescription["DATA"]["#"]["ERROR"])) | 
| @@ -369,7 +369,7 @@ discard block | ||
| 369 | 369 | $errorMessage = ""; | 
| 370 | 370 | foreach ($updateDescription["DATA"]["#"]["ERROR"] as $errorDescription) | 
| 371 | 371 |  			{ | 
| 372 | - $errorMessage .= "[" . $errorDescription["@"]["TYPE"] . "] " . $errorDescription["#"]; | |
| 372 | + $errorMessage .= "[".$errorDescription["@"]["TYPE"]."] ".$errorDescription["#"]; | |
| 373 | 373 | } | 
| 374 | 374 | throw new Exception\ModuleUpdateException($errorMessage, $this->getName()); | 
| 375 | 375 | } | 
| @@ -8,15 +8,15 @@ | ||
| 8 | 8 | |
| 9 | 9 | class ModuleException extends \RuntimeException | 
| 10 | 10 |  { | 
| 11 | - /** | |
| 12 | - * ModuleException constructor. | |
| 13 | - * | |
| 14 | - * @param string $message | |
| 15 | - * @param int $moduleName | |
| 16 | - * @param \Exception|null $previous | |
| 17 | - */ | |
| 18 | - public function __construct($message, $moduleName, \Exception $previous = null) | |
| 19 | -	{ | |
| 20 | -		parent::__construct("[$moduleName] " . $message, 0, $previous); | |
| 21 | - } | |
| 11 | + /** | |
| 12 | + * ModuleException constructor. | |
| 13 | + * | |
| 14 | + * @param string $message | |
| 15 | + * @param int $moduleName | |
| 16 | + * @param \Exception|null $previous | |
| 17 | + */ | |
| 18 | + public function __construct($message, $moduleName, \Exception $previous = null) | |
| 19 | +    { | |
| 20 | +        parent::__construct("[$moduleName] " . $message, 0, $previous); | |
| 21 | + } | |
| 22 | 22 | } | 
| 23 | 23 | \ No newline at end of file | 
| @@ -17,6 +17,6 @@ | ||
| 17 | 17 | */ | 
| 18 | 18 | public function __construct($message, $moduleName, \Exception $previous = null) | 
| 19 | 19 |  	{ | 
| 20 | -		parent::__construct("[$moduleName] " . $message, 0, $previous); | |
| 20 | +		parent::__construct("[$moduleName] ".$message, 0, $previous); | |
| 21 | 21 | } | 
| 22 | 22 | } | 
| 23 | 23 | \ No newline at end of file | 
| @@ -17,24 +17,24 @@ | ||
| 17 | 17 | */ | 
| 18 | 18 | class RegisterCommand extends ModuleCommand | 
| 19 | 19 |  { | 
| 20 | - /** | |
| 21 | -	 * {@inheritdoc} | |
| 22 | - */ | |
| 23 | - protected function configure() | |
| 24 | -	{ | |
| 25 | - parent::configure(); | |
| 20 | + /** | |
| 21 | +     * {@inheritdoc} | |
| 22 | + */ | |
| 23 | + protected function configure() | |
| 24 | +    { | |
| 25 | + parent::configure(); | |
| 26 | 26 | |
| 27 | -		$this->setName('module:register') | |
| 28 | -			->setDescription('Install module'); | |
| 29 | - } | |
| 27 | +        $this->setName('module:register') | |
| 28 | +            ->setDescription('Install module'); | |
| 29 | + } | |
| 30 | 30 | |
| 31 | - /** | |
| 32 | -	 * {@inheritdoc} | |
| 33 | - */ | |
| 34 | - protected function execute(InputInterface $input, OutputInterface $output) | |
| 35 | -	{ | |
| 36 | -		$module = new Module($input->getArgument('module')); | |
| 37 | - $module->register(); | |
| 38 | -		$output->writeln(sprintf('registered <info>%s</info>', $module->getName())); | |
| 39 | - } | |
| 31 | + /** | |
| 32 | +     * {@inheritdoc} | |
| 33 | + */ | |
| 34 | + protected function execute(InputInterface $input, OutputInterface $output) | |
| 35 | +    { | |
| 36 | +        $module = new Module($input->getArgument('module')); | |
| 37 | + $module->register(); | |
| 38 | +        $output->writeln(sprintf('registered <info>%s</info>', $module->getName())); | |
| 39 | + } | |
| 40 | 40 | } | 
| 41 | 41 | \ No newline at end of file | 
| @@ -75,8 +75,7 @@ | ||
| 75 | 75 | try | 
| 76 | 76 |  			{ | 
| 77 | 77 | $module->register(); | 
| 78 | - } | |
| 79 | - catch (ModuleInstallException $e) | |
| 78 | + } catch (ModuleInstallException $e) | |
| 80 | 79 |  			{ | 
| 81 | 80 |  				$output->writeln(sprintf('<comment>%s</comment>', $e->getMessage()), OutputInterface::VERBOSITY_VERBOSE); | 
| 82 | 81 |  				$output->writeln(sprintf('Module loaded, but <error>not registered</error>. You need to do it yourself in admin panel.', $module->getName())); | 
| @@ -20,72 +20,72 @@ | ||
| 20 | 20 | */ | 
| 21 | 21 | class LoadCommand extends ModuleCommand | 
| 22 | 22 |  { | 
| 23 | - use CanRestartTrait; | |
| 23 | + use CanRestartTrait; | |
| 24 | 24 | |
| 25 | - /** | |
| 26 | -	 * {@inheritdoc} | |
| 27 | - */ | |
| 28 | - protected function configure() | |
| 29 | -	{ | |
| 30 | - parent::configure(); | |
| 25 | + /** | |
| 26 | +     * {@inheritdoc} | |
| 27 | + */ | |
| 28 | + protected function configure() | |
| 29 | +    { | |
| 30 | + parent::configure(); | |
| 31 | 31 | |
| 32 | -		$this->setName('module:load') | |
| 33 | -			->setDescription('Load and install module from Marketplace') | |
| 34 | -			->addOption('no-update', 'nu', InputOption::VALUE_NONE, 'Don\' update module') | |
| 35 | -			->addOption('no-register', 'ni', InputOption::VALUE_NONE, 'Load only, don\' register module') | |
| 36 | -			->addOption('beta', 'b', InputOption::VALUE_NONE, 'Allow the installation of beta releases'); | |
| 37 | - } | |
| 32 | +        $this->setName('module:load') | |
| 33 | +            ->setDescription('Load and install module from Marketplace') | |
| 34 | +            ->addOption('no-update', 'nu', InputOption::VALUE_NONE, 'Don\' update module') | |
| 35 | +            ->addOption('no-register', 'ni', InputOption::VALUE_NONE, 'Load only, don\' register module') | |
| 36 | +            ->addOption('beta', 'b', InputOption::VALUE_NONE, 'Allow the installation of beta releases'); | |
| 37 | + } | |
| 38 | 38 | |
| 39 | - /** | |
| 40 | -	 * {@inheritdoc} | |
| 41 | - */ | |
| 42 | - protected function execute(InputInterface $input, OutputInterface $output) | |
| 43 | -	{ | |
| 44 | -		$module = new Module($input->getArgument('module')); | |
| 39 | + /** | |
| 40 | +     * {@inheritdoc} | |
| 41 | + */ | |
| 42 | + protected function execute(InputInterface $input, OutputInterface $output) | |
| 43 | +    { | |
| 44 | +        $module = new Module($input->getArgument('module')); | |
| 45 | 45 | |
| 46 | - if (!$module->isThirdParty()) | |
| 47 | -		{ | |
| 48 | -			$output->writeln('<info>Loading kernel modules is unsupported</info>'); | |
| 49 | - } | |
| 46 | + if (!$module->isThirdParty()) | |
| 47 | +        { | |
| 48 | +            $output->writeln('<info>Loading kernel modules is unsupported</info>'); | |
| 49 | + } | |
| 50 | 50 | |
| 51 | -		if ($input->getOption('beta')) | |
| 52 | -		{ | |
| 53 | - $module->setBeta(); | |
| 54 | - } | |
| 51 | +        if ($input->getOption('beta')) | |
| 52 | +        { | |
| 53 | + $module->setBeta(); | |
| 54 | + } | |
| 55 | 55 | |
| 56 | - $module->load(); | |
| 56 | + $module->load(); | |
| 57 | 57 | |
| 58 | -		if (!$input->getOption('no-update')) | |
| 59 | -		{ | |
| 60 | - $modulesUpdated = null; | |
| 61 | - while ($module->update($modulesUpdated)) | |
| 62 | -			{ | |
| 63 | - if (is_array($modulesUpdated)) | |
| 64 | -				{ | |
| 65 | - foreach ($modulesUpdated as $moduleName => $moduleVersion) | |
| 66 | -					{ | |
| 67 | -						$output->writeln(sprintf('updated %s to <info>%s</info>', $moduleName, $moduleVersion)); | |
| 68 | - } | |
| 69 | - } | |
| 70 | - return $this->restartScript($input, $output); | |
| 71 | - } | |
| 72 | - } | |
| 58 | +        if (!$input->getOption('no-update')) | |
| 59 | +        { | |
| 60 | + $modulesUpdated = null; | |
| 61 | + while ($module->update($modulesUpdated)) | |
| 62 | +            { | |
| 63 | + if (is_array($modulesUpdated)) | |
| 64 | +                { | |
| 65 | + foreach ($modulesUpdated as $moduleName => $moduleVersion) | |
| 66 | +                    { | |
| 67 | +                        $output->writeln(sprintf('updated %s to <info>%s</info>', $moduleName, $moduleVersion)); | |
| 68 | + } | |
| 69 | + } | |
| 70 | + return $this->restartScript($input, $output); | |
| 71 | + } | |
| 72 | + } | |
| 73 | 73 | |
| 74 | -		if (!$input->getOption('no-register')) | |
| 75 | -		{ | |
| 76 | - try | |
| 77 | -			{ | |
| 78 | - $module->register(); | |
| 79 | - } | |
| 80 | - catch (ModuleInstallException $e) | |
| 81 | -			{ | |
| 82 | -				$output->writeln(sprintf('<comment>%s</comment>', $e->getMessage()), OutputInterface::VERBOSITY_VERBOSE); | |
| 83 | -				$output->writeln(sprintf('Module loaded, but <error>not registered</error>. You need to do it yourself in admin panel.', $module->getName())); | |
| 84 | - } | |
| 85 | - } | |
| 74 | +        if (!$input->getOption('no-register')) | |
| 75 | +        { | |
| 76 | + try | |
| 77 | +            { | |
| 78 | + $module->register(); | |
| 79 | + } | |
| 80 | + catch (ModuleInstallException $e) | |
| 81 | +            { | |
| 82 | +                $output->writeln(sprintf('<comment>%s</comment>', $e->getMessage()), OutputInterface::VERBOSITY_VERBOSE); | |
| 83 | +                $output->writeln(sprintf('Module loaded, but <error>not registered</error>. You need to do it yourself in admin panel.', $module->getName())); | |
| 84 | + } | |
| 85 | + } | |
| 86 | 86 | |
| 87 | -		$output->writeln(sprintf('installed <info>%s</info>', $module->getName())); | |
| 87 | +        $output->writeln(sprintf('installed <info>%s</info>', $module->getName())); | |
| 88 | 88 | |
| 89 | - return 0; | |
| 90 | - } | |
| 89 | + return 0; | |
| 90 | + } | |
| 91 | 91 | } | 
| 92 | 92 | \ No newline at end of file | 
| @@ -51,8 +51,7 @@ | ||
| 51 | 51 | if (Cache::clearCache(true)) | 
| 52 | 52 |              { | 
| 53 | 53 |                  $output->writeln('<info>All Bitrix cache was deleted</info>'); | 
| 54 | - } | |
| 55 | - else | |
| 54 | + } else | |
| 56 | 55 |              { | 
| 57 | 56 |                  $output->writeln('<error>Error deleting Bitrix cache</error>'); | 
| 58 | 57 | } | 
| @@ -61,13 +61,13 @@ | ||
| 61 | 61 | if ($dir) | 
| 62 | 62 |          { | 
| 63 | 63 | $cache->cleanDir($dir); | 
| 64 | -            $output->writeln('<info>Bitrix cache by "/' . BX_ROOT . '/cache/' . $dir . '" dir was deleted</info>'); | |
| 64 | +            $output->writeln('<info>Bitrix cache by "/'.BX_ROOT.'/cache/'.$dir.'" dir was deleted</info>'); | |
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | if ($tag) | 
| 68 | 68 |          { | 
| 69 | 69 | Application::getInstance()->getTaggedCache()->clearByTag($tag); | 
| 70 | -            $output->writeln('<info>Bitrix cache by tag "' . $tag . '" was deleted</info>'); | |
| 70 | +            $output->writeln('<info>Bitrix cache by tag "'.$tag.'" was deleted</info>'); | |
| 71 | 71 | } | 
| 72 | 72 | } | 
| 73 | 73 | } | 
| 74 | 74 | \ No newline at end of file | 
| @@ -108,8 +108,7 @@ | ||
| 108 | 108 |              { | 
| 109 | 109 | // @todo warning | 
| 110 | 110 | } | 
| 111 | - } | |
| 112 | - else | |
| 111 | + } else | |
| 113 | 112 |          { | 
| 114 | 113 | // @todo warning | 
| 115 | 114 | } |