1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
updaterservice.php
См. документацию.
1<?php
2
4
8use Symfony\Component\Console\Style\SymfonyStyle;
9
11{
12 protected bool $stableVersionsOnly;
13
14 public function __construct()
15 {
16 $this->stableVersionsOnly = Option::get('main', 'stable_versions_only', 'Y') == 'Y';
17 }
18
19 public function listUpdates(): Result
20 {
21 $error = '';
22 $result = new Result();
23
24 $updateList = \CUpdateClient::GetUpdatesList($error, false, $this->stableVersionsOnly);
25
26 if ($error != '')
27 {
28 return $result->addError(new Error($error));
29 }
30
31 if ($updateList)
32 {
33 if (isset($updateList["ERROR"]))
34 {
35 foreach ($updateList["ERROR"] as $errorMessage)
36 {
37 if ($errorMessage["@"]["TYPE"] != "RESERVED_KEY" && $errorMessage["@"]["TYPE"] != "NEW_UPDATE_SYSTEM")
38 {
39 $error .= "[" . $errorMessage["@"]["TYPE"] . "] " . $errorMessage["#"] . "\n";
40 }
41 elseif ($errorMessage["@"]["TYPE"] == "RESERVED_KEY")
42 {
43 $error .= "You must activate your license key before using the update system.\n";
44 }
45 }
46 if ($error != '')
47 {
48 return $result->addError(new Error(trim($error)));
49 }
50 }
51
52 $result->setData($updateList);
53 }
54
55 return $result;
56 }
57
58 public function repair(string $type): Result
59 {
60 $error = '';
61 $result = new Result();
62
63 if ($type == 'include')
64 {
65 if (!\CUpdateClient::RegisterVersion($error, false, $this->stableVersionsOnly))
66 {
67 return $result->addError(new Error($error));
68 }
69 }
70
71 return $result;
72 }
73
74 public function updateUpdateSystem(): Result
75 {
76 $error = '';
77 $result = new Result();
78
79 if (!\CUpdateClient::UpdateUpdate($error, false, $this->stableVersionsOnly))
80 {
81 return $result->addError(new Error($error));
82 }
83
84 return $result;
85 }
86
87 public function installUpdates(array $modules, SymfonyStyle $io): Result
88 {
89 $result = new Result();
90
91 while (true)
92 {
93 $error = '';
94 $loadResult = \CUpdateClient::LoadModulesUpdates($error, $updateDescription, false, $this->stableVersionsOnly, $modules);
95
96 if ($loadResult == 'S')
97 {
98 if (isset($updateDescription['DATA']['#']['ITEM']))
99 {
100 $this->showStep($updateDescription['DATA']['#']['ITEM'], $io);
101 }
102 }
103 elseif ($loadResult == 'E')
104 {
105 if ($error == '')
106 {
107 $error = '[CL02] Cannot extract files from archive.';
108 }
109 return $result->addError(new Error($error));
110 }
111 elseif ($loadResult == 'F')
112 {
113 return $result;
114 }
115
116 $error = '';
117 $loadResult = \CUpdateClient::LoadModulesUpdates($error, $updateDescription, false, $this->stableVersionsOnly, $modules);
118
119 if ($loadResult == 'E')
120 {
121 return $result->addError(new Error($error));
122 }
123
124 $temporaryUpdatesDir = '';
125 if (!\CUpdateClient::UnGzipArchive($temporaryUpdatesDir, $error))
126 {
127 return $result->addError(new Error($error));
128 }
129
130 if (!\CUpdateClient::CheckUpdatability($temporaryUpdatesDir, $error))
131 {
132 return $result->addError(new Error($error));
133 }
134
135 if (!\CUpdateClient::UpdateStepModules($temporaryUpdatesDir, $error))
136 {
137 $error .= '[CL04] Module update failed.';
138 return $result->addError(new Error($error));
139 }
140
141 \CUpdateClient::logUpdates($updateDescription["DATA"]["#"]["ITEM"]);
142
143 \CUpdateClient::finalizeModuleUpdate($updateDescription["DATA"]["#"]["ITEM"]);
144
145 $io->writeln('Done!');
146
147 Option::set('main', 'update_system_update_time', time());
148 }
149 }
150
151 public function getDependencies(array $updateList, array $unresolved): array
152 {
153 $allModules = [];
154 $dependencies = [];
155 $resolved = [];
156
157 foreach ($updateList as $moduleId => $module)
158 {
159 $allModules[$moduleId] = array_key_last($module['VERSION']);
160 }
161
162 // avoid endless loop
163 $unresolved = array_filter($unresolved, function ($item) use ($allModules) { return isset($allModules[$item]); }, ARRAY_FILTER_USE_KEY);
164
165 do
166 {
167 foreach ($updateList as $moduleId => $module)
168 {
169 if (isset($unresolved[$moduleId]) && !isset($resolved[$moduleId]))
170 {
171 $moduleDep = $this->getModuleDependencies($updateList, $moduleId, $allModules[$moduleId]);
172
173 $resolved[$moduleId] = 1;
174 unset($unresolved[$moduleId]);
175
176 foreach ($moduleDep as $key => $value)
177 {
178 if (isset($allModules[$key]))
179 {
180 if (!isset($resolved[$key]))
181 {
182 $unresolved[$key] = 1;
183 }
184 $dependencies[$key] = $allModules[$key];
185 }
186 }
187 }
188 }
189 }
190 while (!empty($unresolved));
191
192 return $dependencies;
193 }
194
195 public function checkExpertDependencies(array $updateList, array $expertModules): Result
196 {
197 $result = new Result();
198
199 $unresolved = [];
200 foreach ($expertModules as $module => $version)
201 {
202 $dependencies = $this->getModuleDependencies($updateList, $module, $version);
203
204 foreach ($dependencies as $depModule => $depVersion)
205 {
206 if (!isset($expertModules[$depModule]) || \CUpdateClient::CompareVersions($expertModules[$depModule], $depVersion) < 0)
207 {
208 if (isset($updateList[$depModule]["VERSION"][$depVersion]))
209 {
210 $unresolved[$module . ' (' . $version . ')'][] = $depModule . ' (' . $depVersion . ')';
211 }
212 }
213 }
214 }
215
216 if (!empty($unresolved))
217 {
218 $result->addError(new Error("Unresolved dependencies."));
219 $result->setData($unresolved);
220 }
221
222 return $result;
223 }
224
225 protected function getModuleDependencies(array $updateList, string $moduleId, string $moduleVersion): array
226 {
227 $dependencies = [];
228
229 if (isset($updateList[$moduleId]["VERSION"]) && is_array($updateList[$moduleId]["VERSION"]))
230 {
231 foreach ($updateList[$moduleId]["VERSION"] as $versionId => $version)
232 {
233 if (\CUpdateClient::CompareVersions($versionId, $moduleVersion) <= 0)
234 {
235 if (isset($version["VERSION_CONTROL"]) && is_array($version["VERSION_CONTROL"]))
236 {
237 foreach ($version["VERSION_CONTROL"] as $versionModuleId => $versionVersion)
238 {
239 if (isset($dependencies[$versionModuleId]))
240 {
241 if (\CUpdateClient::CompareVersions($versionVersion, $dependencies[$versionModuleId]) > 0)
242 {
243 $dependencies[$versionModuleId] = $versionVersion;
244 }
245 }
246 else
247 {
248 $dependencies[$versionModuleId] = $versionVersion;
249 }
250 }
251 }
252 }
253 else
254 {
255 break;
256 }
257 }
258 }
259
260 return $dependencies;
261 }
262
263 public function transformUpdateList(array $updateList): array
264 {
265 $result = [];
266
267 foreach ($updateList as $module)
268 {
269 $moduleId = $module['@']['ID'];
270 $result[$moduleId] = [];
271
272 if (isset($module["#"]["VERSION"]) && is_array($module["#"]["VERSION"]))
273 {
274 $result[$moduleId]["VERSION"] = [];
275
276 foreach ($module["#"]["VERSION"] as $version)
277 {
278 $versionId = $version["@"]["ID"];
279 $result[$moduleId]["VERSION"][$versionId] = [];
280
281 if (isset($version["#"]["VERSION_CONTROL"]) && is_array($version["#"]["VERSION_CONTROL"]))
282 {
283 $result[$moduleId]["VERSION"][$versionId]["VERSION_CONTROL"] = [];
284
285 foreach ($version["#"]["VERSION_CONTROL"] as $versionControl)
286 {
287 $result[$moduleId]["VERSION"][$versionId]["VERSION_CONTROL"][$versionControl["@"]["MODULE"]] = $versionControl["@"]["VERSION"];
288 }
289 }
290 }
291 }
292 }
293
294 return $result;
295 }
296
297 public function installLanguages(array $languages, SymfonyStyle $io): Result
298 {
299 $result = new Result();
300
301 while (true)
302 {
303 $error = '';
304 $loadResult = \CUpdateClient::LoadLangsUpdates($error, $updateDescription, false, $this->stableVersionsOnly, $languages);
305
306 if ($loadResult == "S")
307 {
308 if (isset($updateDescription['DATA']['#']['ITEM']))
309 {
310 $this->showStep($updateDescription['DATA']['#']['ITEM'], $io);
311 }
312 }
313 elseif ($loadResult == "E")
314 {
315 if ($error == '')
316 {
317 $error = '[CL02] Cannot extract files from archive.';
318 }
319 return $result->addError(new Error($error));
320 }
321 elseif ($loadResult == "F")
322 {
323 return $result;
324 }
325
326 $error = '';
327 $loadResult = \CUpdateClient::LoadLangsUpdates($error, $updateDescription, false, $this->stableVersionsOnly, $languages);
328
329 if ($loadResult == 'E')
330 {
331 return $result->addError(new Error($error));
332 }
333
334 $temporaryUpdatesDir = '';
335 if (!\CUpdateClient::UnGzipArchive($temporaryUpdatesDir, $error))
336 {
337 return $result->addError(new Error($error));
338 }
339
340 if (isset($updateDescription["DATA"]["#"]["NOUPDATES"]))
341 {
342 \CUpdateClient::ClearUpdateFolder($_SERVER["DOCUMENT_ROOT"] . "/bitrix/updates/" . $temporaryUpdatesDir);
343
344 $io->writeln('Done!');
345
346 return $result;
347 }
348 else
349 {
350 if (!\CUpdateClient::UpdateStepLangs($temporaryUpdatesDir, $error))
351 {
352 $error .= "[CL04] Language file update failed.";
353 return $result->addError(new Error($error));
354 }
355
356 $itemsUpdated = [];
357 if (isset($updateDescription["DATA"]["#"]["ITEM"]))
358 {
359 foreach ($updateDescription["DATA"]["#"]["ITEM"] as $item)
360 {
361 $itemsUpdated[$item["@"]["ID"]] = $item["@"]["NAME"];
362 }
363 }
364
365 foreach ($itemsUpdated as $key => $value)
366 {
367 \CUpdateClient::AddMessage2Log("Updated: {$key}" . ($value != '' ? " ({$value})" : ""), "UPD_SUCCESS");
368 }
369
370 \CUpdateClient::finalizeLanguageUpdate($itemsUpdated);
371 }
372
373 $io->writeln('Done!');
374 }
375 }
376
377 protected function showStep(array $items, SymfonyStyle $io): void
378 {
379 $message = '';
380 foreach ($items as $description)
381 {
382 if ($message != '')
383 {
384 $message .= ', ';
385 }
386 $message .= $description['@']['NAME'];
387 if (!empty($description['@']['VALUE']))
388 {
389 $message .= ' ('. $description['@']['VALUE'] . ')';
390 }
391 }
392 if ($message != '')
393 {
394 $io->write('Installing ' . $message . '... ');
395 }
396 }
397}
$type
Определения options.php:106
getDependencies(array $updateList, array $unresolved)
Определения updaterservice.php:151
installUpdates(array $modules, SymfonyStyle $io)
Определения updaterservice.php:87
checkExpertDependencies(array $updateList, array $expertModules)
Определения updaterservice.php:195
getModuleDependencies(array $updateList, string $moduleId, string $moduleVersion)
Определения updaterservice.php:225
showStep(array $items, SymfonyStyle $io)
Определения updaterservice.php:377
installLanguages(array $languages, SymfonyStyle $io)
Определения updaterservice.php:297
Определения error.php:15
</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
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
while($arParentIBlockProperty=$dbParentIBlockProperty->Fetch()) $errorMessage
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$io
Определения csv_new_run.php:98
$modules
Определения bitrix.php:26
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$items
Определения template.php:224
$error
Определения subscription_card_product.php:20