• Модуль: rest
  • Путь к файлу: ~/bitrix/modules/rest/lib/configuration/appconfiguration.php
  • Класс: BitrixRestConfigurationAppConfiguration
  • Вызов: AppConfiguration::importApp
static function importApp($item)
{
	$result = false;
	if (!empty($item['CONTENT']['DATA']['code']))
	{
		$code = preg_replace('/[^a-zA-Z0-9._-]/', '', $item['CONTENT']['DATA']['code']);
		if ($code !== $item['CONTENT']['DATA']['code'])
		{
			return [
				'ERROR_EXCEPTION' => [
					'message' => Loc::getMessage(
						'REST_CONFIGURATION_ERROR_UNKNOWN_APP'
					),
				],
			];
		}

		Application::setContextUserId((int)$item['USER_ID']);
		$result = Application::install($code);
		if ($result['success'])
		{
			$res = AppTable::getList(
				[
					'filter' => [
						'=CODE' => $code,
						'=ACTIVE' => AppTable::ACTIVE,
						'=INSTALLED' => AppTable::NOT_INSTALLED,
						'!=URL_INSTALL' => false,
					],
					'limit' => 1
				]
			);
			if ($app = $res->fetch())
			{
				$res = EventTable::getList(
					[
						'filter' => [
							"APP_ID" => $app['ID'],
							"EVENT_NAME" => "ONAPPINSTALL",
							"EVENT_HANDLER" => $app["URL_INSTALL"],
						],
						'limit' => 1
					]
				);
				if (!$event = $res->fetch())
				{
					$res = EventTable::add(
						[
							"APP_ID" => $app['ID'],
							"EVENT_NAME" => "ONAPPINSTALL",
							"EVENT_HANDLER" => $app["URL_INSTALL"],
						]
					);
					if ($res->isSuccess())
					{
						Sender::bind('rest', 'OnRestAppInstall');
					}

					AppTable::setSkipRemoteUpdate(true);
					AppTable::update(
						$app['ID'],
						[
							'INSTALLED' => AppTable::INSTALLED
						]
					);
					AppTable::setSkipRemoteUpdate(false);

					AppLogTable::log($app['ID'], AppLogTable::ACTION_TYPE_INSTALL);

					AppTable::install($app['ID']);
				}
			}
		}
		elseif (is_array($result) && $result['errorDescription'])
		{
			$result['ERROR_EXCEPTION']['message'] = Loc::getMessage(
				'REST_CONFIGURATION_ERROR_INSTALL_APP_CONTENT_DATA',
				[
					'#ERROR_CODE#' => $result['error'],
					'#ERROR_MESSAGE#' => $result['errorDescription'],
				]
			);
		}
		else
		{
			$result['ERROR_EXCEPTION']['message'] = Loc::getMessage(
				'REST_CONFIGURATION_ERROR_INSTALL_APP_CONTENT'
			);
		}
	}
	else
	{
		return [
			'ERROR_EXCEPTION' => [
				'message' => Loc::getMessage(
					'REST_CONFIGURATION_ERROR_UNKNOWN_APP'
				),
			],
		];
	}

	return $result;
}