Skip to content

Commit

Permalink
[Document Repository] fix Unable to edit an uploaded file (#7056)
Browse files Browse the repository at this point in the history
Fixing the file id method and handle put method to edit a file.

Fixes #7002
  • Loading branch information
kongtiaowang authored Jun 10, 2021
1 parent 64a8ed6 commit 12041ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/document_repository/jsx/editFormIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ window.addEventListener('load', () => {
<div className="row">
<div className="col-md-9 col-lg-7">
<DocEditForm
dataURL={`${loris.BaseURL}/document_repository/Files/${id}`}
dataURL={`${loris.BaseURL}/document_repository/Files/meta/${id}`}
action={`${loris.BaseURL}/document_repository/Files`}
/>
</div>
Expand Down
25 changes: 17 additions & 8 deletions modules/document_repository/php/files.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,25 @@ class Files extends \NDB_Page
case "POST":
return $this->uploadDocFile($request);
case "PUT":
$tmp = $request->getBody();
$arr = (array)json_decode($tmp);
return $this->editDocFile($arr);
return $this->editDocFile($request);
case "DELETE":
$id = basename($request->getUri()->getPath());
$this->deleteFile($id);
return (new \LORIS\Http\Response\JSON\OK(
['message' => 'File deleted.']
));
case "GET":
$filename = urldecode(basename($request->getUri()->getPath()));
$filename = urldecode(basename($request->getUri()->getPath()));
$route = explode('/', $request->getUri()->getPath());
if ($route[2] == 'meta') {
return (new \LORIS\Http\Response())
->withHeader("Content-Type", "text/plain")
->withBody(
new \LORIS\Http\StringStream(
json_encode($this->getUploadDocFields($filename))
)
);
}
$downloader = new \LORIS\FilesDownloadHandler(
new \SPLFileInfo(
$downloadpath . $request->getAttribute('user')->getUsername()
Expand All @@ -90,11 +98,11 @@ class Files extends \NDB_Page
/**
* Handles the document editing process
*
* @param array $req the request
* @param ServerRequestInterface $req The incoming PSR7 request
*
* @return ResponseInterface
*/
function editDocFile(array $req): ResponseInterface
function editDocFile(ServerRequestInterface $req): ResponseInterface
{
$factory = \NDB_Factory::singleton();
$user = $factory->user();
Expand All @@ -104,14 +112,15 @@ class Files extends \NDB_Page
self::FORBIDDEN
);
}
$req = json_decode((string)$req->getBody(), true);
$updateValues = [
'instrument' => $req['instrument'] ?? null,
'comments' => $req['comments'] ?? null,
'version' => $req['version'] ?? null,
'visitLabel' => $req['visitLabel'] ?? null,
'pscid' => $req['pscid'] ?? null,
];
$fileName = $req['fileName'];
$fileName = $req['fileName'] ?? null;
$Notifier = new \NDB_Notifier(
"document_repository",
"edit"
Expand All @@ -120,7 +129,7 @@ class Files extends \NDB_Page
$db->update(
'document_repository',
$updateValues,
['record_id' => $req['id']]
['record_id' => $req['id'] ?? null]
);
$factory = \NDB_Factory::singleton();
$baseURL = $factory->settings()->getBaseURL();
Expand Down

0 comments on commit 12041ad

Please # to comment.