• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/bitrix24disk/legacy/storagecontroller.php
  • Класс: BitrixDiskBitrix24DiskLegacyStorageController
  • Вызов: StorageController::processActionDirectory
protected function processActionDirectory()
{
	$this->checkRequiredPostParams(array('name', 'storageExtra', 'storageId'));
	if($this->errorCollection->hasErrors())
	{
		$this->sendJsonErrorResponse();
	}

	$directoryType = $this->request->getPost('directoryType');
	$folderName = $this->request->getPost('name');
	$inRoot = $this->request->getPost('inRoot') == 'true';
	$isUpdate = $this->request->getPost('update') == 'true';

	$storage = $this->getStorageObject($this->request->getPost('storageExtra'), $this->request->getPost('storageId'));

	if(!$storage->isCorrectName($folderName, $msg))
	{
		$this->sendJsonResponse(array(
			'status' => static::STATUS_DENIED,
			'message' => $msg,
		));
	}

	$parentFolderId = null;
	if(!$inRoot)
	{
		$this->checkRequiredPostParams(array('parentExtra'));
		if($this->errorCollection->hasErrors())
		{
			$this->sendJsonErrorResponse();
		}

		$parentFolderExtra = $storage->parseElementExtra($this->request->getPost('parentExtra'));
		$parentFolderId = $parentFolderExtra['id'];
		//$parentFolderVersion = $_POST['version'];
	}

	if($isUpdate)
	{
		$this->checkRequiredPostParams(array('id', 'version'));
		if($this->errorCollection->hasErrors())
		{
			$this->sendJsonErrorResponse();
		}

		$id = $this->request->getPost('id');

		$folderExtra = $storage->parseElementExtra($this->request->getPost('extra'));
		$targetFolder = $storage->getDirectory($id, $folderExtra);
		if(empty($targetFolder))
		{
			$this->errorCollection->addOne(new Error('Not found directory to update'));
			$this->sendJsonErrorResponse();
		}

		//it is the same directory todo this logic $storage->moveDirectory, but ....we have many query. Or refactor signature
		if($targetFolder['extra']['sectionId'] == $parentFolderId && $folderName == $targetFolder['name'])
		{
			$this->sendJsonSuccessResponse($targetFolder);
		}
		if($folderName != $targetFolder['name'])
		{
			$item = $storage->renameDirectory($folderName, $targetFolder['extra']['id'], $parentFolderId);
		}
		else
		{
			$item = $storage->moveDirectory($folderName, $targetFolder['extra']['id'], $parentFolderId);
		}

		if(!$item)
		{
			$this->errorCollection->addOne(new Error('Error in action move'));
			$this->sendJsonErrorResponse();
		}
		$event = new Event(Driver::INTERNAL_MODULE_ID, self::EVENT_ON_AFTER_DISK_FOLDER_UPDATE, array($item['extra']['id'], $item));
		$event->send();

		$this->sendJsonSuccessResponse($item);
	}
	else
	{
		//todo folder may make in storage root, but parentFolder not exist
		$item = $storage->addDirectory($folderName, $parentFolderId, array(
			'originalTimestamp' => $this->request->getPost('originalTimestamp'),
			'code' => $directoryType,
		));
	}

	if(empty($item))
	{
		$this->errorCollection->addOne(new Error('Error in makeDirectory'));
		$this->sendJsonErrorResponse();
	}
	$event = new Event(Driver::INTERNAL_MODULE_ID, self::EVENT_ON_AFTER_DISK_FOLDER_ADD, array($item['extra']['id'], $item));
	$event->send();

	$this->sendJsonSuccessResponse($item);
}