• Модуль: imbot
  • Путь к файлу: ~/bitrix/modules/imbot/lib/bot/network.php
  • Класс: BitrixImBotBotNetwork
  • Вызов: Network::updateConnector
static function updateConnector($lineId, $fields)
{
	$update = [];
	$update['LINE_ID'] = (int)$lineId;
	if ($update['LINE_ID'] <= 0)
	{
		return false;
	}

	if (isset($fields['NAME']))
	{
		$fields['NAME'] = trim($fields['NAME']);
		if (mb_strlen($fields['NAME']) >= 3)
		{
			$update['FIELDS']['LINE_NAME'] = $fields['NAME'];
		}
		else
		{
			self::$lastError = new ImBotError(__METHOD__, 'NAME_LENGTH', 'Field NAME should be 3 or more characters');
			return false;
		}
	}

	if (isset($fields['DESC']))
	{
		$update['FIELDS']['LINE_DESC'] = trim($fields['DESC']);
	}

	if (isset($fields['FIRST_MESSAGE']))
	{
		$update['FIELDS']['FIRST_MESSAGE'] = trim($fields['FIRST_MESSAGE']);
	}

	if (isset($fields['AVATAR']))
	{
		$update['FIELDS']['AVATAR'] = '';

		$fields['AVATAR'] = (int)$fields['AVATAR'];
		if ($fields['AVATAR'])
		{
			$fileTmp = CFile::resizeImageGet(
				$fields['AVATAR'],
				['width' => 300, 'height' => 300],
				BX_RESIZE_IMAGE_EXACT,
				false,
				false,
				true
			);
			if ($fileTmp['src'])
			{
				$update['FIELDS']['AVATAR'] = mb_substr($fileTmp['src'], 0, 4) == 'http'
					? $fileTmp['src']
					: ImBotHttp::getServerAddress().$fileTmp['src'];
			}
		}
	}

	if (isset($fields['ACTIVE']))
	{
		$update['FIELDS']['ACTIVE'] = $fields['ACTIVE'] == 'N'? 'N': 'Y';
	}

	if (isset($fields['HIDDEN']))
	{
		$update['FIELDS']['HIDDEN'] = $fields['HIDDEN'] == 'Y'? 'Y': 'N';
	}

	$http = self::instanceHttpClient();
	$result = $http->query(
		self::COMMAND_CONNECTOR_UPDATE,
		$update,
		true
	);
	if (isset($result['error']))
	{
		self::$lastError = new ImBotError(__METHOD__, $result['error']['code'], $result['error']['msg']);
		return false;
	}

	return $result['result'];
}