diff --git a/core/controllers/components/ApisystemComponent.php b/core/controllers/components/ApisystemComponent.php index 0299c4874..968e1e491 100644 --- a/core/controllers/components/ApisystemComponent.php +++ b/core/controllers/components/ApisystemComponent.php @@ -324,6 +324,10 @@ public function linkCreate($args) * When passing the folderid param, the name of the newly created item, * if not supplied, the item will have the same name as filename. * @param checksum (Optional) The md5 checksum of the file to be uploaded. + * @param create_additional_revision (Optional) When a checksum is passed and + * the server already has the file, by default a reference to the existing + * bitstream will be added to the latest revision. By setting + * create_additional_revision to true, a new revision will be created. * @return An upload token that can be used to upload a file. * If folderid is passed instead of itemid, a new item will be created * in that folder, but the id of the newly created item will not be @@ -404,13 +408,25 @@ public function uploadGeneratetoken($args) MIDAS_POLICY_READ ) ) { + $createAdditionalRevision = isset($args['create_additional_revision']) ? $args['create_additional_revision'] : false; $revision = $itemModel->getLastRevision($item); - if ($revision === false) { - // Create new revision if none exists yet + // Do not create an additional revision if last revision has one bitstream and checksum matches. + if ($createAdditionalRevision && $revision) { + $bitstreams = $revision->getBitstreams(); + if (count($bitstreams) === 1 && $args['checksum'] == $bitstreams[0]->getChecksum()) { + return array('token' => ''); + } + } + + if ($revision === false || $createAdditionalRevision) { + // Create a new revision if none exists yet or if the user explicitly asks to create a new revision when + // a bitstream with the same checksum was found. Zend_Loader::loadClass('ItemRevisionDao', BASE_PATH.'/core/models/dao'); $revision = new ItemRevisionDao(); - $revision->setChanges('Initial revision'); + if ($createAdditionalRevision === false) { + $revision->setChanges('Initial revision'); + } $revision->setUser_id($userDao->getKey()); $revision->setDate(date('Y-m-d H:i:s')); $revision->setLicenseId(null); diff --git a/modules/api/controllers/components/ApiComponent.php b/modules/api/controllers/components/ApiComponent.php index a937bb7a2..559a037d6 100644 --- a/modules/api/controllers/components/ApiComponent.php +++ b/modules/api/controllers/components/ApiComponent.php @@ -317,6 +317,10 @@ public function linkCreate($args) * When passing the folderid param, the name of the newly created item, * if not supplied, the item will have the same name as filename. * @param checksum (Optional) The md5 checksum of the file to be uploaded. + * @param create_additional_revision (Optional) When a checksum is passed and + * the server already has the file, by default a reference to the existing + * bitstream will be added to the latest revision. By setting + * create_additional_revision to true, a new revision will be created. * @return An upload token that can be used to upload a file. * If folderid is passed instead of itemid, a new item will be created * in that folder, but the id of the newly created item will not be