• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/uf/controller.php
  • Класс: BitrixDiskUfController
  • Вызов: Controller::processActionRenameFile
protected function processActionRenameFile()
{
	$this->checkRequiredPostParams(array('newName', 'attachedId'));

	if($this->errorCollection->hasErrors())
	{
		$this->sendJsonErrorResponse();
	}

	[$type, $realValue] = FileUserType::detectType($this->request->getPost('attachedId'));

	if ($type == FileUserType::TYPE_NEW_OBJECT)
	{
		/** @var File $model */
		$model = File::loadById((int)$realValue, array('STORAGE'));
		if(!$model)
		{
			$this->errorCollection->add(array(new Error("Could not find file")));
			$this->sendJsonErrorResponse();
		}
		if(!$model->canRename($model->getStorage()->getCurrentUserSecurityContext()))
		{
			$this->errorCollection->add(array(new Error("Bad permission. Could not read this file")));
			$this->sendJsonErrorResponse();
		}
		$newName = Text::correctFilename(($this->request->getPost('newName')));
		if(!$model->renameInternal($newName, true))
		{
			$this->errorCollection->add($model->getErrors());
			$this->sendJsonErrorResponse();
		}

		$this->sendJsonSuccessResponse(array(
			'id' => $this->request->getPost('attachedId'),
			'name' => $model->getName(),
		));
	}
	else
	{
		$this->sendJsonErrorResponse();
	}
}