-
Notifications
You must be signed in to change notification settings - Fork 9
uploadGeneratetoken: Add support to optionally create new revision #146
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -324,6 +324,10 @@ public function linkCreate($args) | |||
| * When passing the <b>folderid</b> param, the name of the newly created item, | ||||
| * if not supplied, the item will have the same name as <b>filename</b>. | ||||
| * @param checksum (Optional) The md5 checksum of the file to be uploaded. | ||||
| * @param create_additional_revision (Optional) When a <b>checksum</b> 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 | ||||
| * <b>create_additional_revision</b> to true, a new revision will be created. | ||||
| * @return An upload token that can be used to upload a file. | ||||
| * If <b>folderid</b> is passed instead of <b>itemid</b>, 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 | ||||
| ) | ||||
| ) { | ||||
| $create_additional_revision = 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 checkum matches | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
| if ($create_additional_revision && $revision) { | ||||
| $bitstreams = $revision->getBitstreams(); | ||||
| if (count($bitstreams) == 1 && $args['checksum'] == $bitstreams[0]->getChecksum()) { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
| return array('token' => ''); | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not really like returning an invalid token. Throw an exception.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning an empty token is valid and documented, this is what is done in the rest of the code.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok (but I still dislike it). |
||||
| } | ||||
| } | ||||
|
|
||||
| if ($revision === false || $create_additional_revision) { | ||||
| // Create new revision if none exists yet or if the user explicitly asked for creating a new revision when | ||||
| // a bitstream with the same checksum was found. | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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($create_additional_revision === false) { | ||||
| $revision->setChanges('Initial revision'); | ||||
| } | ||||
| $revision->setUser_id($userDao->getKey()); | ||||
| $revision->setDate(date('Y-m-d H:i:s')); | ||||
| $revision->setLicenseId(null); | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camelcase