3namespace Bitrix\Rest\Configuration\Action;
5use Bitrix\Main\ArgumentException;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Rest\Configuration\Notification;
8use Bitrix\Rest\Configuration\Setting;
9use Bitrix\Rest\Configuration\Helper;
10use Bitrix\Rest\Configuration\Controller;
11use Bitrix\Rest\Configuration\Manifest;
12use Bitrix\Rest\Configuration\Structure;
13use Bitrix\Rest\Configuration\DataProvider;
14use Bitrix\Rest\AppTable;
15use Bitrix\Rest\AppLogTable;
16use Bitrix\Main\IO\File;
27 private const STEP_INIT_BACKGROUND =
'init_background';
28 private const STEP_START =
'start';
29 private const STEP_MANIFEST =
'manifest';
30 private const STEP_CLEAN =
'clean';
31 private const STEP_LOAD =
'load';
32 private const STEP_FINISH =
'finish';
34 private const STEPS_ORDER = [
36 self::STEP_INIT_BACKGROUND,
43 private const COUNT_ADD_FILES_BY_STEP = 200;
45 private $manifestCode;
55 $this->manifestCode =
$code;
66 return $this->manifestCode ??
'';
77 public function run(): bool
90 'run' => self::STEP_START,
92 'currentSection' => 0,
98 switch ($actionInfo[
'run'])
100 case self::STEP_START:
101 $actionInfo[
'setting'] = $this->
doStart();
102 $actionInfo[
'section'] = $actionInfo[
'setting'][
'section'];
104 case self::STEP_INIT_BACKGROUND:
105 $actionInfo[
'setting'] = $this->doInitBackground($actionInfo,
$data);
107 case self::STEP_MANIFEST:
109 $actionInfo[
'setting'][
'next'],
114 case self::STEP_CLEAN:
117 (isset(
$data[
'MANIFEST'][
'SKIP_CLEARING']) &&
$data[
'MANIFEST'][
'SKIP_CLEARING'] ===
'Y')
118 || (isset($manifest[
'SKIP_CLEARING']) && $manifest[
'SKIP_CLEARING'] ===
'Y')
121 $actionInfo[
'setting'][
'finish'] =
true;
125 $actionInfo[
'section'][
'next'] = $actionInfo[
'section'][
'next'] ??
null;
126 $actionInfo[
'setting'] = $this->
doClean(
127 $actionInfo[
'section'][$actionInfo[
'currentSection']],
128 $actionInfo[
'section'][
'next'],
129 (
int) $actionInfo[
'step']
133 case self::STEP_LOAD:
134 $actionInfo[
'setting'][
'result'] =
true;
135 $type = $actionInfo[
'section'][$actionInfo[
'currentSection']] ??
false;
136 if (
$type && isset(
$data[self::PROPERTY_STRUCTURE][
$type][$actionInfo[
'step']]))
145 'REST_CONFIGURATION_IMPORT_ERROR_CONTENT',
147 '#STEP#' => $actionInfo[
'step'],
154 $actionInfo[
'section'][$actionInfo[
'currentSection']],
170 'REST_CONFIGURATION_IMPORT_ERROR_SANITIZE_SHORT',
172 '#STEP#' => $actionInfo[
'step']
179 $actionInfo[
'currentSection'],
189 $actionInfo[
'setting'][
'step'] = $actionInfo[
'setting'][
'step'] ??
null;
190 $actionInfo[
'setting'] = $this->
doLoad(
191 $actionInfo[
'setting'][
'step'],
192 $actionInfo[
'section'][$actionInfo[
'currentSection']],
197 $actionInfo[
'setting'][
'next'] = !$actionInfo[
'setting'][
'result'];
200 case self::STEP_FINISH:
201 $actionInfo[
'setting'] = $this->
doFinish();
214 if (!empty($exception))
221 $actionInfo[
'step']++;
223 !array_key_exists(
'next', $actionInfo[
'setting'])
224 || $actionInfo[
'setting'][
'next'] ===
false
227 $actionInfo[
'currentSection']++;
228 $actionInfo[
'step'] = 0;
232 !array_key_exists(
'finish', $actionInfo[
'setting'])
233 && !isset($actionInfo[
'section'][$actionInfo[
'currentSection']])
236 isset($actionInfo[
'setting'][
'finish'])
237 && $actionInfo[
'setting'][
'finish'] ===
true
241 $actionInfo[
'setting'][
'finish'] =
false;
242 $actionInfo[
'currentSection'] = 0;
243 $actionInfo[
'step'] = 0;
244 $key = array_search($actionInfo[
'run'], self::STEPS_ORDER);
249 $actionInfo[
'run'] = self::STEPS_ORDER[
$key] ??
false;
266 if (!empty(
$data[self::PROPERTY_MANIFEST][
'CODE']))
296 'ADDITIONAL_OPTION' => $additionalOption,
302 if ($item[
'NEXT'] !==
false)
304 $result[
'next'] = $item[
'NEXT'];
329 $data = Controller::callEventClear(
336 'CLEAR_FULL' => $clearFull,
337 'PREFIX_NAME' => Loc::getMessage(
'REST_CONFIGURATION_INSTALL_CLEAR_PREFIX_NAME'),
340 'ADDITIONAL_OPTION' => $additionalOption,
346 if (isset(
$data[
'NEXT']))
377 $dataList = Controller::callEventImport(
386 'ADDITIONAL_OPTION' => $additionalOption,
390 foreach ($dataList as
$data)
392 if (is_array(
$data[
'RATIO']))
394 if (empty($ratio[
$code]))
420 private function doInitBackground($actionInfo,
$data):
array
423 $next = $actionInfo[
'step'];
424 $structure =
new Structure($this->setting->getContext());
426 if (
$data[self::PROPERTY_FILES] &&
$data[self::PROPERTY_STRUCTURE][Helper::STRUCTURE_FILES_NAME])
428 $chunkList = array_chunk(
$data[self::PROPERTY_FILES], self::COUNT_ADD_FILES_BY_STEP);
429 if (!empty($chunkList[$next]))
431 $structure->addFileList(
433 $data[self::PROPERTY_STRUCTURE][Helper::STRUCTURE_FILES_NAME]
448 if (!empty($actionInfo[
'next']) && (
int)$actionInfo[
'next'] === 0)
450 $fileName = Helper::STRUCTURE_SMALL_FILES_NAME . Helper::CONFIGURATION_FILE_EXTENSION;
452 foreach (
$data[self::PROPERTY_STRUCTURE] as
$path)
459 $structure->unpackSmallFiles(
$content);
461 catch (\Exception $e)
468 elseif (!empty($actionInfo[
'next']) && (
int)$actionInfo[
'next'] > 0)
496 $section = Controller::getEntityCodeList();
497 $result[
'section'] = array_values($section);
499 if (!is_array(
$app) &&
$app !==
null)
509 if (!empty(
$option[
'UNINSTALL_APP_ON_FINISH']))
525 public function doFinish(
string $mode = Helper::MODE_IMPORT)
530 'createItemList' => [],
535 if (!empty(
$app[
'ID']))
540 $updateResult = AppTable::update(
549 $result[
'result'] = $updateResult->isSuccess();
563 if (!empty($uninstallAppCode))
565 $res = AppTable::getList(
568 "=CODE" => $uninstallAppCode,
573 if ($appInfo =
$res->fetch())
576 $checkResult = AppTable::checkUninstallAvailability($appInfo[
'ID'], $clean);
577 if ($checkResult->isEmpty())
585 AppTable::update($appInfo[
'ID'], $appFields);
595 $eventResult = Controller::callEventFinish(
603 'APP_ID' => (
$app[
'ID'] > 0) ?
$app[
'ID'] : 0,
605 'ADDITIONAL_OPTION' => $additionalOption,
609 foreach ($eventResult as
$data)
611 if (is_array(
$data[
'CREATE_DOM_LIST']))
613 $result[
'createItemList'] = array_merge(
$result[
'createItemList'],
$data[
'CREATE_DOM_LIST']);
616 if (is_array(
$data[
'ADDITIONAL']))
631 !isset(
$data[
'MANIFEST'][
'CODE'])
636 'error' => static::ERROR_MANIFEST_IS_NOT_AVAILABLE,
637 'error_description' =>
'Manifest is not available.',
654 if (
$status === self::STATUS_PROCESS ||
$status === self::STATUS_ERROR)
659 'action' => $actionInfo[
'run'],
660 'step' => $actionInfo[
'step'],
663 !empty($actionInfo[
'section'][$actionInfo[
'currentSection']])
664 && !empty($actionInfo[
'run'])
665 && $actionInfo[
'run'] !== self::STEP_FINISH
668 $result[
'progress'][
'section'] = $actionInfo[
'section'][$actionInfo[
'currentSection']];
674 $result[
'additional'] = $actionInfo[
'setting'][
'additional'] ?? [];
675 $result[
'createItemList'] = $actionInfo[
'setting'][
'createItemList'] ?? [];
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
const ACTION_TYPE_UNINSTALL
static log($appId, $action)
const ACTION_TYPE_INSTALL
static getByClientId($clientId)
static uninstall($appId, $clean=0)
static setSkipRemoteUpdate($v)
getNotificationInstance()
setStatus(string $status)
doClean($code, $step, $next, bool $clearFull=false)
doLoad($step, $code, $content)
const ERROR_MANIFEST_IS_NOT_AVAILABLE
doInitManifest(?string $next, int $step, string $type)
doStart($app=null, string $mode=Helper::MODE_IMPORT, array $option=[])
doFinish(string $mode=Helper::MODE_IMPORT)
static callEventInit($code, $params=[])
static isRestImportAvailable(string $entityCode)
const SETTING_ACTION_INFO
const SETTING_ACTION_ADDITIONAL_OPTION
const SETTING_UNINSTALL_APP_CODE
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"