1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
modulescommand.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Cli\Command\Update;
4
5use Symfony\Component\Console\Input\InputInterface;
6use Symfony\Component\Console\Input\InputOption;
7
19{
20 protected function configure()
21 {
22 $this
23 ->setName('update:modules')
24 ->setDescription('Updates modules.')
25 ->addOption('modules', 'm', InputOption::VALUE_REQUIRED, 'Comma separated list of modules to update.')
26 ->addOption('import', 'i', InputOption::VALUE_REQUIRED, 'JSON file with modules versions (exported in the expert mode).')
27 ;
28 }
29
30 protected function executeCommand(array $updateList, InputInterface $input): bool
31 {
32 if (isset($updateList['MODULES'][0]['#']['MODULE']))
33 {
34 $updateList = $this->updater->transformUpdateList($updateList['MODULES'][0]['#']['MODULE']);
35
36 $this->showUpdates($updateList);
37
38 $importFile = $input->getOption('import');
39 if (!empty($importFile))
40 {
41 // expert mode
42 if (!$this->installExpertUpdates($updateList, $importFile))
43 {
44 return false;
45 }
46 }
47 else
48 {
49 if (!$this->installUpdates($updateList, $input->getOption('modules')))
50 {
51 return false;
52 }
53 }
54 }
55 else
56 {
57 $this->io->info('No updates found.');
58 }
59
60 return true;
61 }
62
63 protected function installUpdates(array $updateList, ?string $inputModules): bool
64 {
65 $selectedModules = [];
66 if (!empty($inputModules))
67 {
68 $selectedModules = explode(',', $inputModules);
69 }
70
71 $modules = [];
72 foreach ($updateList as $moduleId => $module)
73 {
74 if (empty($selectedModules) || in_array($moduleId, $selectedModules))
75 {
76 $modules[$moduleId] = array_key_last($module['VERSION']);
77 }
78 }
79
80 if (!empty($modules))
81 {
82 if (!empty($selectedModules))
83 {
84 // need to check dependencies
85 $dependentModules = $this->updater->getDependencies($updateList, $modules);
86 $modules = array_merge($modules, $dependentModules);
87 ksort($modules);
88
89 $this->io->title('Updates to install');
90 foreach ($modules as $moduleId => $version)
91 {
92 $this->io->writeln($moduleId . ' (' . $version . ')');
93 }
94 }
95
96 if ($this->io->confirm('Install updates?'))
97 {
98 $result = $this->updater->installUpdates(array_keys($modules), $this->io);
99 if ($result->isSuccess())
100 {
101 $this->io->success('Updates installed successfully.');
102 }
103 else
104 {
105 $this->io->error((string)$result->getError());
106 return false;
107 }
108 }
109 }
110 else
111 {
112 $this->io->info('No modules selected.');
113 }
114
115 return true;
116 }
117
118 protected function showUpdates(array $updateList): void
119 {
120 $this->io->title('Available updates');
121
122 $updates = [];
123 foreach ($updateList as $moduleId => $module)
124 {
125 $updates[] = $moduleId . ' (' . array_key_last($module['VERSION']) . ')';
126 }
127 sort($updates);
128
129 $this->io->write($updates, true);
130 }
131
132 protected function installExpertUpdates(array $updateList, string $importFile): bool
133 {
134 if (($import = file_get_contents($importFile)) === false)
135 {
136 $this->io->error('Import of expert updates failed (can\'t read the file).');
137 return false;
138 }
139
140 $expertModules = json_decode($import, true);
141 if (!\CUpdateExpertMode::isCorrectModulesStructure($expertModules))
142 {
143 $this->io->error('Import of expert updates failed (JSON structure).');
144 return false;
145 }
146
147 $this->io->title('Imported expert updates');
148 foreach ($expertModules as $module => $version)
149 {
150 $this->io->writeln($module . ' (' . $version . ')');
151 }
152
153 $result = $this->updater->checkExpertDependencies($updateList, $expertModules);
154
155 if (!$result->isSuccess())
156 {
157 $this->io->error((string)$result->getError());
158
159 foreach ($result->getData() as $module => $dependencies)
160 {
161 $this->io->writeln($module . ' requires ' . implode(', ', $dependencies));
162 }
163 $this->io->newLine();
164
165 return false;
166 }
167
168 if ($this->io->confirm('Install updates?'))
169 {
170 $result = $this->updater->installUpdates($expertModules, $this->io);
171 if ($result->isSuccess())
172 {
173 $this->io->success('Updates installed successfully.');
174 }
175 else
176 {
177 $this->io->error((string)$result->getError());
178 return false;
179 }
180 }
181
182 return true;
183 }
184}
installExpertUpdates(array $updateList, string $importFile)
Определения modulescommand.php:132
showUpdates(array $updateList)
Определения modulescommand.php:118
installUpdates(array $updateList, ?string $inputModules)
Определения modulescommand.php:63
executeCommand(array $updateList, InputInterface $input)
Определения modulescommand.php:30
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$moduleId
$modules
Определения bitrix.php:26