• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/classes/general/countersprocessorinstaller.php
  • Класс: CTaskCountersProcessorInstaller
  • Вызов: CTaskCountersProcessorInstaller::recountCounters_ACCOMPLICE_NEW
static function recountCounters_ACCOMPLICE_NEW($userId)
{
	global $DB;

	$DB->startTransaction();

	// Count not viewed tasks by accomplices
	$strSql = "SELECT COUNT(TM.TASK_ID) AS ACC_NEW_CNT, TM.USER_ID AS USER_ID
		FROM b_tasks_member TM
		LEFT JOIN b_tasks T ON T.ID = TM.TASK_ID
		LEFT JOIN b_tasks_viewed TV ON TV.TASK_ID = T.ID AND TV.USER_ID = TM.USER_ID
		WHERE
			T.ID IS NOT NULL 
			AND T.ZOMBIE = 'N' 
			AND TM.TYPE = 'A' 
			AND TV.USER_ID IS NULL 
			AND (T.STATUS = " . CTasks::STATE_NEW . " OR T.STATUS = " . CTasks::STATE_PENDING . ")
	";

	if ($userId !== '*')	// All users or not?
		$strSql .= " AND TM.USER_ID = " . (int) $userId;
			
	$strSql .= "GROUP BY TM.USER_ID";

	$rc = $DB->query($strSql);

	$i = 0;
	while ($ar = $rc->fetch())
	{
		$arValues = CUserCounter::GetValues($ar['USER_ID'], $site_id = '**');

		$total = 0;
		if (isset($arValues[CTaskCountersProcessor::COUNTER_TASKS_TOTAL]))
			$total = (int) $arValues[CTaskCountersProcessor::COUNTER_TASKS_TOTAL];

		$subtotal = 0;
		if (isset($arValues[CTaskCountersProcessor::COUNTER_TASKS_ACCOMPLICE]))
			$subtotal = (int) $arValues[CTaskCountersProcessor::COUNTER_TASKS_ACCOMPLICE];

		CUserCounter::Set(
			(int) $ar['USER_ID'],
			CTaskCountersProcessor::COUNTER_TASKS_ACCOMPLICE_NEW,
			(int) $ar['ACC_NEW_CNT'],
			'**',		// $site_id
			$tag = '',
			false		// $sendPull
		);

		CUserCounter::Set(
			(int) $ar['USER_ID'],
			CTaskCountersProcessor::COUNTER_TASKS_ACCOMPLICE,
			$subtotal + (int) $ar['ACC_NEW_CNT'],
			'**',		// $site_id
			$tag = '',
			false		// $sendPull
		);

		CUserCounter::Set(
			(int) $ar['USER_ID'],
			CTaskCountersProcessor::COUNTER_TASKS_TOTAL,
			$total + (int) $ar['ACC_NEW_CNT'],
			'**',		// $site_id
			$tag = '',
			false		// $sendPull
		);

		// commit on after every 100 users have been processed
		if ( ! (++$i % 100) )
		{
			soundex('commit every 100 users');
			$DB->commit();
			$DB->startTransaction();
		}
	}

	$DB->commit();
}