• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/update/linkfilemigration.php
  • Класс: BitrixImUpdateLinkFileMigration
  • Вызов: LinkFileMigration::makeMigrationIteration
private function makeMigrationIteration(array &$option): bool
{
	$isFinished = Option::get(self::$moduleId, self::OPTION_NAME, '');

	if ($isFinished === '')
	{
		Option::set(self::$moduleId, self::OPTION_NAME, 'N');
	}

	if ($isFinished === 'Y')
	{
		return self::FINISH_EXECUTION;
	}

	$lastId = $option['lastId'] ?? 0;
	$params = $this->getParams($lastId);

	if ($params->count() === 0)
	{
		Option::set(self::$moduleId, self::OPTION_NAME, 'Y');
		if (BitrixMainLoader::includeModule('pull'))
		{
			Event::add(
				Event::SHARED_CHANNEL,
				[
					'module_id' => 'im',
					'command' => 'linkFileMigrationFinished',
					'extra' => Common::getPullExtra(),
				],
				CPullChannel::TYPE_SHARED
			);
		}

		return self::FINISH_EXECUTION;
	}

	$ids = $params->getParamValueList();
	$lastId = max($params->getIdList());
	$this->changeMigrationFlag(true);
	$fileCollection = new FileCollection();
	$fileEntities = BitrixImV2EntityFileFileCollection::initByDiskFilesIds($ids);
	foreach ($params as $param)
	{
		$fileEntity = $fileEntities->getById((int)$param->getParamValue());
		if ($fileEntity === null)
		{
			continue;
		}
		$message = $param->getMessage();
		if ($message === null)
		{
			continue;
		}
		$file = new FileItem();
		$file
			->setChatId($message->getChatId())
			->setAuthorId($message->getAuthorId())
			->setMessageId($param->getMessageId())
			->setEntity($fileEntity)
			->setDateCreate($message->getDateCreate())
		;
		$fileCollection->add($file);
	}
	$fileCollection->save(true);
	$this->changeMigrationFlag(false);
	$option['lastId'] = $lastId;
	$steps = LinkFileTable::getCount();
	$count = MessageParamTable::getCount(Query::filter()->where('PARAM_NAME', 'FILE_ID'));
	$option['steps'] = $steps;
	$option['count'] = $count;

	return self::CONTINUE_EXECUTION;
}