• Модуль: rest
  • Путь к файлу: ~/bitrix/modules/rest/lib/configuration/action/import.php
  • Класс: BitrixRestConfigurationActionImport
  • Вызов: Import::doFinish
public function doFinish(string $mode = Helper::MODE_IMPORT)
{
	$result = [
		'result' => true,
		'finish' => true,
		'createItemList' => [],
		'additional' => [],
	];

	$app = $this->getSetting()->get(Setting::SETTING_APP_INFO);
	if (!empty($app['ID']))
	{
		if ($app['INSTALLED'] == AppTable::NOT_INSTALLED)
		{
			AppTable::setSkipRemoteUpdate(true);
			$updateResult = AppTable::update(
				$app['ID'],
				[
					'INSTALLED' => AppTable::INSTALLED
				]
			);
			AppTable::setSkipRemoteUpdate(false);
			AppTable::install($app['ID']);
			AppLogTable::log($app['ID'], AppLogTable::ACTION_TYPE_INSTALL);
			$result['result'] = $updateResult->isSuccess();
		}
		else
		{
			$result['result'] = true;
		}
		Helper::getInstance()->setBasicApp($this->getManifestCode(), $app['CODE']);
	}
	else
	{
		Helper::getInstance()->deleteBasicApp($this->getManifestCode());
	}

	$uninstallAppCode = $this->getSetting()->get(Setting::SETTING_UNINSTALL_APP_CODE);
	if (!empty($uninstallAppCode))
	{
		$res = AppTable::getList(
			[
				'filter' => array(
					"=CODE" => $uninstallAppCode,
					"!=STATUS" => AppTable::STATUS_LOCAL
				),
			]
		);
		if ($appInfo = $res->fetch())
		{
			$clean = true;
			$checkResult = AppTable::checkUninstallAvailability($appInfo['ID'], $clean);
			if ($checkResult->isEmpty())
			{
				$result['result'] = true;
				AppTable::uninstall($appInfo['ID'], $clean);
				$appFields = [
					'ACTIVE' => 'N',
					'INSTALLED' => 'N',
				];
				AppTable::update($appInfo['ID'], $appFields);
				AppLogTable::log($appInfo['ID'], AppLogTable::ACTION_TYPE_UNINSTALL);
			}
		}
	}

	$ratio = $this->getSetting()->get(Setting::SETTING_RATIO);
	$app = $this->getSetting()->get(Setting::SETTING_APP_INFO);
	$userId = $this->getSetting()->get(Setting::SETTING_USER_ID) ?? 0;
	$additionalOption = $this->getSetting()->get(Setting::SETTING_ACTION_ADDITIONAL_OPTION);
	$eventResult = Controller::callEventFinish(
		[
			'TYPE' => 'IMPORT',
			'CONTEXT' => $this->getContextEntity(),
			'CONTEXT_USER' => $this->getContext(),
			'RATIO' => $ratio,
			'MANIFEST_CODE' => $this->getManifestCode(),
			'IMPORT_MANIFEST' => Manifest::get($this->getManifestCode()) ?? [],
			'APP_ID' => ($app['ID'] > 0) ? $app['ID'] : 0,
			'USER_ID' => $userId,
			'ADDITIONAL_OPTION' => $additionalOption,
		]
	);

	foreach ($eventResult as $data)
	{
		if (is_array($data['CREATE_DOM_LIST']))
		{
			$result['createItemList'] = array_merge($result['createItemList'], $data['CREATE_DOM_LIST']);
		}

		if (is_array($data['ADDITIONAL']))
		{
			$result['additional'] = array_merge($result['additional'], $data['ADDITIONAL']);
		}
	}
	$result['finish'] = $result['result'];

	return $result;
}