diff --git a/lib/Controller/FileHandlingController.php b/lib/Controller/FileHandlingController.php index 43d601fd..6ea3c6f3 100644 --- a/lib/Controller/FileHandlingController.php +++ b/lib/Controller/FileHandlingController.php @@ -136,6 +136,10 @@ public function save($path, $filecontents, $mtime) { } if($file->isUpdateable()) { + if (empty($mtime)) { + $this->logger->error('Save request without the modification time of the loaded file: ' . $path, ['app' => 'files_mindmap']); + return new DataResponse(['message' => $this->l->t('The mind map could not be saved. Please reload it and try again.')], Http::STATUS_BAD_REQUEST); + } if ($mtime != $file->getMTime()) { $this->logger->error("User cannot save shared mind map (someone updated it in the meantime): {$mtime} vs. {$file->getMTime()} {$file->getPath()}", ['app' => 'files_mindmap']); return new DataResponse([ 'message' => $this->l->t('The file you are working on was updated in the meantime. You cannot save your progress as saving would overwrite these changes. Please reload the page.')],Http::STATUS_BAD_REQUEST); @@ -159,24 +163,21 @@ public function save($path, $filecontents, $mtime) { } else { // Not writeable! $this->logger->error('User does not have permission to write to file: ' . $path, - ['app' => 'files_texteditor']); + ['app' => 'files_mindmap']); return new DataResponse([ 'message' => $this->l->t('Insufficient permissions')], Http::STATUS_BAD_REQUEST); } - } else if ($path === '') { + } else { $this->logger->error('No file path supplied'); return new DataResponse(['message' => $this->l->t('File path not supplied')], Http::STATUS_BAD_REQUEST); - } else { - $this->logger->error('No file mtime supplied', ['app' => 'files_texteditor']); - return new DataResponse(['message' => $this->l->t('File mtime not supplied')], Http::STATUS_BAD_REQUEST); } } catch (HintException $e) { $message = (string)$e->getHint(); return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); } catch (\Exception $e) { - $message = (string)$this->l->t('An internal server error occurred.'); - $message = $path; + $this->logger->error('Could not save mind map: ' . $path, ['app' => 'files_mindmap', 'exception' => $e]); + $message = (string)$this->l->t('The mind map could not be saved. Please try again later.'); return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); } } diff --git a/lib/Controller/PublicFileHandlingController.php b/lib/Controller/PublicFileHandlingController.php index d575efcb..0b64ce2e 100644 --- a/lib/Controller/PublicFileHandlingController.php +++ b/lib/Controller/PublicFileHandlingController.php @@ -207,6 +207,10 @@ public function save($token, $filecontents, $path, $mtime) { } if(($file instanceof File) && $file->isUpdateable()) { + if (empty($mtime)) { + $this->logger->error('Save request without the modification time of the loaded file: ' . $file->getPath(), ['app' => 'files_mindmap']); + return new DataResponse(['message' => $this->l->t('The mind map could not be saved. Please reload it and try again.')], Http::STATUS_BAD_REQUEST); + } if ($mtime != $file->getMTime()) { $this->logger->error("Anonymous cannot save shared mind map (someone updated it in the meantime): {$mtime} vs. {$file->getMTime()} {$file->getPath()}", ['app' => 'files_mindmap']); return new DataResponse([ 'message' => $this->l->t('The file you are working on was updated in the meantime. You cannot save your progress as saving would overwrite these changes. Please reload the page.')],Http::STATUS_BAD_REQUEST);