• Модуль: biconnector
  • Путь к файлу: ~/bitrix/modules/biconnector/lib/controller/key.php
  • Класс: BitrixBIConnectorControllerKey
  • Вызов: Key::updateAction
public function updateAction($id, $fields, CRestServer $server)
{
	$result = [
		'error' => 'KEY_NOT_FOUND',
		'error_description' => 'Key not found.',
	];

	$appId = $this->getAppId($server);
	if ($appId > 0)
	{
		$list = KeyTable::getList(
			[
				'filter' => [
					'=ID' => $id,
					'=APP_ID' => $appId,
				],
				'select' => [
					'ID', 'CREATED_BY'
				],
			]
		);
		if ($item = $list->fetch())
		{
			$userId = $this->prepareUserId();
			if ($userId !== (int)$item['CREATED_BY'] && !CRestUtil::isAdmin())
			{
				return [
					'error' => 'ACCESS_DENIED',
					'error_description' => 'Access denied.',
				];
			}

			$save = [];
			if (array_key_exists('CONNECTION', $fields))
			{
				$save['CONNECTION'] = $fields['CONNECTION'];
			}
			if (array_key_exists('ACTIVE', $fields))
			{
				$save['ACTIVE'] = $fields['ACTIVE'] === 'Y';
			}

			$res = KeyTable::update(
				$item['ID'],
				$save
			);
			if (!$res->isSuccess())
			{
				$result = $this->prepareErrorsForRest('UPDATE', $res->getErrorCollection());
			}
			else
			{
				$result = true;
			}
		}
	}

	return $result;
}