- Модуль: rest
- Путь к файлу: ~/bitrix/modules/rest/lib/configuration/action/import.php
- Класс: BitrixRestConfigurationActionImport
- Вызов: Import::run
public function run(): bool
{
$result = false;
$data = $this->getStructureData();
if ($this->check($data))
{
$this->setStatus(self::STATUS_PROCESS);
$actionInfo = $this->getSetting()->get(Setting::SETTING_ACTION_INFO);
if (!$actionInfo)
{
$actionInfo = [
'setting' => [],
'run' => self::STEP_START,
'section' => [],
'currentSection' => 0,
'step' => 0,
];
}
$this->setManifestCode($data['MANIFEST']['CODE']);
switch ($actionInfo['run'])
{
case self::STEP_START:
$actionInfo['setting'] = $this->doStart();
$actionInfo['section'] = $actionInfo['setting']['section'];
break;
case self::STEP_INIT_BACKGROUND:
$actionInfo['setting'] = $this->doInitBackground($actionInfo, $data);
break;
case self::STEP_MANIFEST:
$actionInfo['setting'] = $this->doInitManifest(
$actionInfo['setting']['next'],
$actionInfo['step'],
Helper::MODE_IMPORT
);
break;
case self::STEP_CLEAN:
$manifest = Manifest::get($this->getManifestCode());
if (
(isset($data['MANIFEST']['SKIP_CLEARING']) && $data['MANIFEST']['SKIP_CLEARING'] === 'Y')
|| (isset($manifest['SKIP_CLEARING']) && $manifest['SKIP_CLEARING'] === 'Y')
)
{
$actionInfo['setting']['finish'] = true;
}
else
{
$actionInfo['section']['next'] = $actionInfo['section']['next'] ?? null;
$actionInfo['setting'] = $this->doClean(
$actionInfo['section'][$actionInfo['currentSection']],
$actionInfo['section']['next'],
(int) $actionInfo['step']
);
}
break;
case self::STEP_LOAD:
$actionInfo['setting']['result'] = true;
$type = $actionInfo['section'][$actionInfo['currentSection']] ?? false;
if ($type && isset($data[self::PROPERTY_STRUCTURE][$type][$actionInfo['step']]))
{
$path = $data[self::PROPERTY_STRUCTURE][$type][$actionInfo['step']];
$http = DataProviderController::getInstance()->get(DataProviderController::CODE_IO);
$content = $http->getContent($path, $actionInfo['step']);
if (!empty($content['ERROR_CODE']))
{
$this->getNotificationInstance()->add(
Loc::getMessage(
'REST_CONFIGURATION_IMPORT_ERROR_CONTENT',
[
'#STEP#' => $actionInfo['step'],
]
),
implode(
'_',
[
$content['ERROR_CODE'],
$actionInfo['section'][$actionInfo['currentSection']],
$actionInfo['step'],
]
),
Notification::TYPE_EXCEPTION
);
}
if ($content['COUNT'] === 0)
{
$content['COUNT'] = count($data[self::PROPERTY_STRUCTURE][$type]);
}
if ($content['SANITIZE'])
{
$this->getNotificationInstance()->add(
Loc::getMessage(
'REST_CONFIGURATION_IMPORT_ERROR_SANITIZE_SHORT',
[
'#STEP#' => $actionInfo['step']
]
),
implode(
'_',
[
'SANITIZE',
$actionInfo['currentSection'],
$actionInfo['step'],
]
),
Notification::TYPE_NOTICE
);
}
if (!is_null($content['DATA']))
{
$actionInfo['setting']['step'] = $actionInfo['setting']['step'] ?? null;
$actionInfo['setting'] = $this->doLoad(
$actionInfo['setting']['step'],
$actionInfo['section'][$actionInfo['currentSection']],
$content
);
}
}
$actionInfo['setting']['next'] = !$actionInfo['setting']['result'];
break;
case self::STEP_FINISH:
$actionInfo['setting'] = $this->doFinish();
break;
default:
$this->setStatus(self::STATUS_FINISH);
$this->unregister();
break;
}
$exception = $this->getNotificationInstance()->list(
[
'type' => Notification::TYPE_EXCEPTION,
]
);
if (!empty($exception))
{
$this->setStatus(self::STATUS_ERROR);
$this->unregister();
}
else
{
$actionInfo['step']++;
if (
!array_key_exists('next', $actionInfo['setting'])
|| $actionInfo['setting']['next'] === false
)
{
$actionInfo['currentSection']++;
$actionInfo['step'] = 0;
}
if (
(
!array_key_exists('finish', $actionInfo['setting'])
&& !isset($actionInfo['section'][$actionInfo['currentSection']])
)
|| (
isset($actionInfo['setting']['finish'])
&& $actionInfo['setting']['finish'] === true
)
)
{
$actionInfo['setting']['finish'] = false;
$actionInfo['currentSection'] = 0;
$actionInfo['step'] = 0;
$key = array_search($actionInfo['run'], self::STEPS_ORDER);
if ($key !== false)
{
$key++;
}
$actionInfo['run'] = self::STEPS_ORDER[$key] ?? false;
}
}
$result = $this->getSetting()->set(Setting::SETTING_ACTION_INFO, $actionInfo);
}
else
{
$this->setStatus(self::STATUS_ERROR);
}
return $result;
}