• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/notify.php
  • Класс: BitrixImNotify
  • Вызов: Notify::cleanNotifyAgent
static function cleanNotifyAgent(): string
{
	$dayCount = 60;
	$limit = 2000;
	$step = 1000;

	$batches = [];
	$result = BitrixImModelMessageTable::getList([
		'select' => ['ID'],
		'filter' => [
			'=NOTIFY_TYPE' => [IM_NOTIFY_CONFIRM, IM_NOTIFY_FROM, IM_NOTIFY_SYSTEM],
			' ConvertTimeStamp((time() - 86400 * $dayCount), 'FULL')
		],
		'limit' => $limit
	]);

	$batch = [];
	$i = 0;

	while ($row = $result->fetch())
	{
		if ($i++ === $step)
		{
			$i = 0;
			$batches[] = $batch;
			$batch = [];
		}

		$batch[] = (int)$row['ID'];
	}
	if (!empty($batch))
	{
		$batches[] = $batch;
	}

	$counterService = new CounterService();
	foreach ($batches as $batch)
	{
		BitrixImModelMessageTable::deleteBatch([
			'=ID' => $batch
		]);
		BitrixImModelMessageParamTable::deleteBatch([
			'=MESSAGE_ID' => $batch
		]);
		$counterService->deleteByMessageIdsForAll($batch);
	}


	//BitrixImCounter::clearCache();

	return 'BitrixImNotify::cleanNotifyAgent();';
}