public function renameFile(Request $request)
{
$namespace = $request->request->get('namespace');
$parent = $request->request->get('parent');
$oldName = $request->request->get('oldname');
$newName = $request->request->get('newname');
if (!$this->isMatchingExtension($oldName, $newName)) {
return $this->json(Trans::__('general.phrase.only-root-change-file-extensions'), Response::HTTP_FORBIDDEN);
}
try {
$this->filesystem()->rename("{$namespace}://{$parent}/{$oldName}", "{$parent}/{$newName}");
return $this->json($newName, Response::HTTP_OK);
} catch (ExceptionInterface $e) {
$msg = Trans::__('Unable to rename file: %FILE%', ['%FILE%' => $oldName]);
$this->logException($msg, $e);
if ($e instanceof FileExistsException) {
$status = Response::HTTP_CONFLICT;
} elseif ($e instanceof FileNotFoundException) {
$status = Response::HTTP_NOT_FOUND;
} else {
$status = Response::HTTP_INTERNAL_SERVER_ERROR;
}
return $this->json($msg, $status);
}
}