Skip to content

Commit b016bf5

Browse files
committed
uploadGeneratetoken: Add support to optionally create new revision
Backported from PR midasplatform#146 This commit updates the "uploadGeneratetoken" API introducing the new parameter "create_additional_revision" allowing to optionally change the default behavior and ensure a new revision is created when: - a bitstream associated with the file already exists on the server - and the checksum parameter is specified - and the item updated has at least one revision Since the http uploader doesn't specify the "checksum" parameter, the problem is only reproducible using the web API. For example, considering the following configuration: folder |--- item1 --- revision1 | |--- bitstream1 (filename1) | |--- item2 --- revision1 | |--- bitstream2 (filename2) By default, trying to associate bitstream1 with item2 will result in this configuration: folder |--- item1 --- revision1 | |--- bitstream1 (filename1) | |--- item2 --- revision1 | |--- bitstream2 (filename2) | |--- bitstream1 (filename1) By setting the option "create_additional_revision" to True, the following configuration will be obtained: folder |--- item1 --- revision1 | |--- bitstream1 (filename1) | |--- item2 -|--- revision1 | | |--- bitstream2 (filename2) | | | |--- revision2 | | |--- bitstream1 (filename1)
1 parent f7cf0ab commit b016bf5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

core/controllers/components/ApisystemComponent.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ function linkCreate($args)
286286
When passing the <b>folderid</b> param, the name of the newly created item,
287287
if not supplied, the item will have the same name as <b>filename</b>.
288288
* @param checksum (Optional) The md5 checksum of the file to be uploaded.
289+
* @param create_additional_revision (Optional) When a <b>checksum</b> is passed and
290+
the server already has the file, by default a reference to the existing
291+
bitstream will be added to the latest revision. By setting
292+
<b>create_additional_revision</b> to true, a new revision will be created.
289293
* @return An upload token that can be used to upload a file.
290294
If <b>folderid</b> is passed instead of <b>itemid</b>, a new item will be created
291295
in that folder, but the id of the newly created item will not be
@@ -372,14 +376,19 @@ function uploadGeneratetoken($args)
372376
// Otherwise an attacker could spoof the checksum and read a private bitstream with a known checksum.
373377
if($itemModel->policyCheck($existingBitstream->getItemrevision()->getItem(), $userDao, MIDAS_POLICY_READ))
374378
{
379+
$create_additional_revision = isset($args['create_additional_revision']) ? $args['create_additional_revision'] : false;
375380
$revision = $itemModel->getLastRevision($item);
376381

377-
if($revision == false)
382+
if($revision == false || $create_additional_revision)
378383
{
379-
// Create new revision if none exists yet
384+
// Create new revision if none exists yet or if user explicitly asked for creating a new revision when
385+
// a bistream with the same checksum was found.
380386
Zend_Loader::loadClass('ItemRevisionDao', BASE_PATH.'/core/models/dao');
381387
$revision = new ItemRevisionDao();
382-
$revision->setChanges('Initial revision');
388+
if($create_additional_revision == false)
389+
{
390+
$revision->setChanges('Initial revision');
391+
}
383392
$revision->setUser_id($userDao->getKey());
384393
$revision->setDate(date("Y-m-d H:i:s"));
385394
$revision->setLicenseId(null);

modules/api/controllers/components/ApiComponent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ function linkCreate($args)
307307
When passing the <b>folderid</b> param, the name of the newly created item,
308308
if not supplied, the item will have the same name as <b>filename</b>.
309309
* @param checksum (Optional) The md5 checksum of the file to be uploaded.
310+
* @param create_additional_revision (Optional) When a <b>checksum</b> is passed and
311+
the server already has the file, by default a reference to the existing
312+
bitstream will be added to the latest revision. By setting
313+
<b>create_additional_revision</b> to true, a new revision will be created.
310314
* @return An upload token that can be used to upload a file.
311315
If <b>folderid</b> is passed instead of <b>itemid</b>, a new item will be created
312316
in that folder, but the id of the newly created item will not be

0 commit comments

Comments
 (0)