1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
versionscommand.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Cli\Command\Update;
4
5use Symfony\Component\Console\Command\Command;
6use Symfony\Component\Console\Input\InputInterface;
7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Output\OutputInterface;
9use Symfony\Component\Console\Style\SymfonyStyle;
10use Bitrix\Main\ModuleManager;
11
20class VersionsCommand extends Command
21{
22 protected SymfonyStyle $io;
23
24 protected function configure()
25 {
26 $this
27 ->setName('update:versions')
28 ->setDescription('Updates modules versions.')
29 ->addArgument('versions', InputArgument::REQUIRED, 'JSON file with modules versions.')
30 ;
31 }
32
33 protected function execute(InputInterface $input, OutputInterface $output): int
34 {
35 $this->io = new SymfonyStyle($input, $output);
36
37 if (!$this->updateVersions($input->getArgument('versions')))
38 {
39 return self::FAILURE;
40 }
41
42 return self::SUCCESS;
43 }
44
45 protected function updateVersions(string $importFile): bool
46 {
47 if (($import = file_get_contents($importFile)) === false)
48 {
49 $this->io->error('Import of modules versions failed (can\'t read the file).');
50 return false;
51 }
52
53 $modules = json_decode($import, true);
54 if (!is_array($modules))
55 {
56 $this->io->error('Import of modules versions failed (JSON structure).');
57 return false;
58 }
59
60 foreach ($modules as $module => $version)
61 {
62 if ($info = \CModule::CreateModuleObject($module))
63 {
64 if (version_compare($info->MODULE_VERSION, $version) >= 0)
65 {
66 if (($newVersion = ModuleManager::decreaseVersion($module, 1, $version)) !== null)
67 {
68 $this->io->writeln('Updated ' . $module . ' (' . $info->MODULE_VERSION . ') to version ' . $newVersion);
69 }
70 }
71 }
72 else
73 {
74 $this->io->warning('Module ' . $module . ' not found.');
75 }
76 }
77
78 return true;
79 }
80}
updateVersions(string $importFile)
Определения versionscommand.php:45
execute(InputInterface $input, OutputInterface $output)
Определения versionscommand.php:33
static decreaseVersion(string $moduleId, int $count, ?string $fromVersion=null)
Определения modulemanager.php:192
$output
Определения options.php:436
$modules
Определения bitrix.php:26
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924