• Модуль: faceid
  • Путь к файлу: ~/bitrix/modules/faceid/lib/profilephotoindex.php
  • Класс: BitrixFaceidProfilePhotoIndex
  • Вызов: ProfilePhotoIndex::execute
function execute(array &$result)
{
	if (!Option::get('faceid', 'user_index_enabled', 0))
	{
		return false;
	}

	/** @var bool $isFirstRun No indexing during first run */
	$isFirstRun = false;

	// set general flag of index processing
	if (!Option::get('faceid', 'user_index_processing', 0))
	{
		$isFirstRun = true;
		Option::set('faceid', 'user_index_processing', 1);

		$r = UserTable::getList(array(
			'select' => array(new ExpressionField('CNT', 'COUNT(1)')),
			'filter' => array('=ACTIVE' => 'Y', '>PERSONAL_PHOTO' => 0)
		))->fetch();

		if (!empty($r['CNT']))
		{
			Option::set('faceid', 'user_index_total', $r['CNT']);
		}
	}

	// get current values
	$ixCurrent = Option::get('faceid', 'user_index_current', 0);
	$ixTotal = Option::get('faceid', 'user_index_total', 0);

	// check lock
	$locked = Option::get('faceid', 'user_index_lock', 0);

	if (!$locked && !$isFirstRun)
	{
		// lock
		Option::set('faceid', 'user_index_lock', 1);

		// get portion
		$portionSize = 0;

		$r = UserTable::getList(array(
			'select' => array('ID', 'PERSONAL_PHOTO'),
			'filter' => array('=ACTIVE' => 'Y', '>PERSONAL_PHOTO' => 0),
			'order' => array('ID'),
			'offset' => $ixCurrent,
			'limit' => static::$photosPerRequestCount
		));

		while ($user = $r->fetch())
		{
			UsersTable::indexUser($user);
			$portionSize++;
		}

		$ixCurrent += $portionSize;

		// finalize indexing
		$final = $portionSize < static::$photosPerRequestCount;

		if (!$final)
		{
			Option::set('faceid', 'user_index_current', $ixCurrent);
		}
		else
		{
			Option::set('faceid', 'user_indexed', 1);

			Option::delete('faceid', array('name' => 'user_index_processing'));
			Option::delete('faceid', array('name' => 'user_index_current'));
			Option::delete('faceid', array('name' => 'user_index_total'));
		}

		// free lock
		Option::set('faceid', 'user_index_lock', 0);
	}

	$result["steps"] = $ixCurrent;
	$result["count"] = $ixTotal;

	return empty($final) ? true : false;
}