PingAgent::doRun

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. PingAgent
  4. doRun
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/agent/activity/pingagent.php
  • Класс: Bitrix\Crm\Agent\Activity\PingAgent
  • Вызов: PingAgent::doRun
static function doRun(): bool
{
	$highBound = (new DateTime())->add('+' . self::DEADLINE_HIGH_BOUND_LENGTH . ' seconds');
	$result = ActivityPingQueueTable::getList([
		'select' => ['*'],
		'filter' => [
			'<=PING_DATETIME' => $highBound,
		],
		'order' => ['PING_DATETIME' => 'ASC']
	])->fetchAll();

	if (empty($result))
	{
		return true; // nothing to do
	}

	foreach ($result as $item)
	{
		$activity = ActivityTable::query()
			->where('ID', $item['ACTIVITY_ID'])
			->setSelect([
				'ID',
				'COMPLETED',
				'SUBJECT',
				'AUTHOR_ID',
				'RESPONSIBLE_ID',
				'DEADLINE',
			])
			->fetch()
		;

		$bindings = CCrmActivity::GetBindings($item['ACTIVITY_ID']);
		if (
			!is_array($activity)
			|| !(is_array($bindings) && !empty($bindings))
			|| static::isActivityPassed($activity)
		)
		{
			ActivityPingQueueTable::delete($item['ID']);

			continue;
		}

		$authorId = $activity['RESPONSIBLE_ID'] ?? null;
		$deadline = $activity['DEADLINE'] ?? null;
		if ($deadline && CCrmDateTimeHelper::IsMaxDatabaseDate($deadline))
		{
			$deadline = null;
		}

		foreach ($bindings as $binding)
		{
			static::addPing((int)$item['ACTIVITY_ID'], $item['PING_DATETIME'], $deadline, $binding, $authorId);
			static::sendNotification((int)$binding['OWNER_TYPE_ID'], (int)$binding['OWNER_ID'], $activity);

			ActivityPingQueueTable::delete($item['ID']);
		}
	}

	return true;
}

Добавить комментарий