• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/volume/event.php
  • Класс: Bitrix\Crm\Volume\Event
  • Вызов: Event::clearFiles
public function clearFiles()
{
	if (!$this->canClearFile())
	{
		return -1;
	}

	if (count($this->getFilter()) > 0)
	{
		$query = $this->prepareQuery();
	}
	else
	{
		$query = $this->prepareNonRelationQuery();
	}

	$dropped = -1;

	if ($this->prepareFilter($query))
	{
		$query
			->addSelect('EVENT_ID')
			->setLimit(self::MAX_FILE_PER_INTERACTION)
			->setOrder(array('EVENT_ID' => 'ASC'))
			->whereNotNull('FILES')
			->where('FILES', '<>', '')
		;
		/*
		if ($this->getProcessOffset() > 0)
		{
			$query->where('EVENT_ID', '>=', $this->getProcessOffset());
		}
		*/

		$result = $query->exec();

		$dropped = 0;
		while ($event = $result->fetch())
		{
			$this->setProcessOffset($event['EVENT_ID']);

			$droppedCount = self::dropEventFiles($event['EVENT_ID'], $this->getOwner());
			if ($droppedCount >= 0)
			{
				$this->incrementDroppedFileCount($droppedCount);
				$dropped ++;
			}
			else
			{
				$this->incrementFailCount();
			}

			if ($this->hasTimeLimitReached())
			{
				break;
			}
		}
	}
	else
	{
		$this->collectError(new Main\Error('Filter error', self::ERROR_DELETION_FAILED));
	}

	return $dropped;
}