public function renameFile($file, $targetFileName) { // The name should be different from the current. if ($file->getIdentifier() == $targetFileName) { return $file; } // Check if user is allowed to rename if (!$this->checkUserActionPermission('rename', 'File')) { throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientUserPermissionsException('You are not allowed to rename files."', 1319219349); } // Check if $file is readable if (!$this->checkFileActionPermission('read', $file)) { throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileReadPermissionsException('You are not allowed to read the file "' . $file->getIdentifier() . '\'', 1319219349); } // Check if $file is writable if (!$this->checkFileActionPermission('write', $file)) { throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileWritePermissionsException('You are not allowed to rename the file "' . $file->getIdentifier() . '\'', 1319219349); } // Call driver method to rename the file that also updates the file // object properties try { $newIdentifier = $this->driver->renameFile($file, $targetFileName); $this->updateFile($file, $newIdentifier); /** @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */ $fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository'); $fileRepository->update($file); } catch (\RuntimeException $e) { } return $file; }