• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/copy/integration/groupstepper.php
  • Класс: BitrixDiskCopyIntegrationGroupStepper
  • Вызов: GroupStepper::execute
public function execute(array &$option)
{
	if (!Loader::includeModule(self::$moduleId))
	{
		return false;
	}

	try
	{
		$queue = $this->getQueue();
		$this->setQueue($queue);
		$queueOption = $this->getOptionData($this->baseName);
		if (empty($queueOption))
		{
			$this->deleteQueueOption();
			return !$this->isQueueEmpty();
		}

		$groupId = ($queueOption["groupId"] ?: 0);
		$copiedGroupId = ($queueOption["copiedGroupId"] ?: 0);
		$errorOffset = ($queueOption["errorOffset"] ?: 0);

		$storage = Driver::getInstance()->getStorageByGroupId($groupId);
		$targetStorage = Driver::getInstance()->getStorageByGroupId($copiedGroupId);
		if (!$storage || !$targetStorage)
		{
			$this->deleteQueueOption();
			return !$this->isQueueEmpty();
		}

		$rootFolder = $storage->getRootObject();
		$targetRootFolder = $targetStorage->getRootObject();

		$limit = 5;
		$offset = $this->getOffset($targetRootFolder) + $errorOffset;

		$executiveUserId = ($queueOption["executiveUserId"] ?: SystemUser::SYSTEM_USER_ID);
		$mapFolderIds = ($queueOption["mapFolderIds"] ?: []);
		$mapIdsCopiedFiles = ($queueOption["mapIdsCopiedFiles"] ?: []);

		$fileIds = $this->getFileIds($rootFolder);
		$count = count($fileIds);
		$fileIds = array_slice($fileIds, $offset, $limit);

		if (!$fileIds || !$mapFolderIds)
		{
			$this->onAfterCopy($queueOption);
			$this->deleteQueueOption();
			return !$this->isQueueEmpty();
		}

		$copiedFileIds = [];
		foreach ($fileIds as $fileId)
		{
			try
			{
				$file = File::loadById($fileId);
				$folderId = $this->getFolderId($file);
				$targetFolderId = ($mapFolderIds[$folderId] ?: 0);
				$targetFolder = Folder::loadById($targetFolderId);
				$copiedFile = $file->copyTo($targetFolder, $executiveUserId);
				if (!$copiedFile || $file->getErrors())
				{
					$queueOption["errorOffset"] += 1;
				}
				$this->setFileRights($groupId, $copiedGroupId, $file, $copiedFile);
				$copiedFileIds[] = ($copiedFile->getId() ? $fileId : 0);
			}
			catch (Throwable $exception)
			{
				$this->deleteQueueOption();
				return false;
			}
		}

		$queueOption["mapIdsCopiedFiles"] = $mapIdsCopiedFiles + $copiedFileIds;
		$this->saveQueueOption($queueOption);

		$option["count"] = $count;
		$option["steps"] = $offset;

		return true;
	}
	catch (Exception $exception)
	{
		$this->writeToLog($exception);
		$this->deleteQueueOption();
		return false;
	}
}