• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/controller/onlyoffice.php
  • Класс: BitrixDiskControllerOnlyOffice
  • Вызов: OnlyOffice::renameDocumentAction
public function renameDocumentAction(ModelsDocumentSession $documentSession, string $newName): ?array
{
	if (!$documentSession->isEdit())
	{
		$this->addError(new Error('Could not rename document by view session.'));

		return null;
	}

	if (!$documentSession->canUserRename($this->getCurrentUser()))
	{
		$this->addError(new Error('Could not rename due to lack of rights.'));

		return null;
	}

	$file = $documentSession->getFile();
	if (!$file)
	{
		$this->addError(new Error('Could not find file.'));

		return null;
	}

	$newName .= ".{$file->getExtension()}";
	$newName = DiskUiText::correctFilename($newName);
	if (!$file->rename($newName, true))
	{
		$this->addErrors($this->getErrors());

		return null;
	}

	$result = DocumentOnlyOfficeOnlyOfficeHandler::renameDocument($documentSession->getExternalHash(), $newName);
	if (!$result->isSuccess())
	{
		$this->addErrors($result->getErrors());
	}

	return [
		'file' => [
			'name' => $file->getName(),
		]
	];
}