• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/bot.php
  • Класс: BitrixImBot
  • Вызов: Bot::unRegister
static function unRegister(array $bot)
{
	$botId = intval($bot['BOT_ID']);
	$moduleId = isset($bot['MODULE_ID'])? $bot['MODULE_ID']: '';
	$appId = isset($bot['APP_ID'])? $bot['APP_ID']: '';

	if (intval($botId) <= 0)
	{
		return false;
	}

	$bots = self::getListCache();
	if (!isset($bots[$botId]))
	{
		return false;
	}

	if ($moduleId <> '' && $bots[$botId]['MODULE_ID'] != $moduleId)
	{
		return false;
	}

	if ($appId <> '' && $bots[$botId]['APP_ID'] != $appId)
	{
		return false;
	}

	BitrixImModelBotTable::delete($botId);

	$orm = BitrixImModelBotChatTable::getList(Array(
		'filter' => Array('=BOT_ID' => $botId)
	));
	if ($row = $orm->fetch())
	{
		BitrixImModelBotChatTable::delete($row['ID']);
	}

	$cache = BitrixMainDataCache::createInstance();
	$cache->cleanDir(self::CACHE_PATH);

	$user = new CUser;
	$user->Delete($botId);

	if (BitrixMainLoader::includeModule($bots[$botId]['MODULE_ID']) && $bots[$botId]["METHOD_BOT_DELETE"] && class_exists($bots[$botId]["CLASS"]) && method_exists($bots[$botId]["CLASS"], $bots[$botId]["METHOD_BOT_DELETE"]))
	{
		call_user_func_array(array($bots[$botId]["CLASS"], $bots[$botId]["METHOD_BOT_DELETE"]), Array($botId));
	}

	foreach(BitrixMainEventManager::getInstance()->findEventHandlers("im", "onImBotDelete") as $event)
	{
		ExecuteModuleEventEx($event, Array($bots[$botId], $botId));
	}

	$orm = BitrixImModelCommandTable::getList(Array(
		'filter' => Array('=BOT_ID' => $botId)
	));
	while ($row = $orm->fetch())
	{
		BitrixImCommand::unRegister(Array('COMMAND_ID' => $row['ID'], 'FORCE' => 'Y'));
	}

	$orm = BitrixImModelAppTable::getList(Array(
		'filter' => Array('=BOT_ID' => $botId)
	));
	while ($row = $orm->fetch())
	{
		BitrixImApp::unRegister(Array('ID' => $row['ID'], 'FORCE' => 'Y'));
	}

	self::sendPullNotify($botId, 'botDelete');

	BitrixMainApplication::getInstance()->getTaggedCache()->clearByTag("IM_CONTACT_LIST");

	return true;
}