Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions core/controllers/components/ApisystemComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -404,13 +408,25 @@ public function uploadGeneratetoken($args)
MIDAS_POLICY_READ
)
) {
$create_additional_revision = isset($args['create_additional_revision']) ? $args['create_additional_revision'] : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelcase

$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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not, checksum, matches.

if ($create_additional_revision && $revision) {
$bitstreams = $revision->getBitstreams();
if (count($bitstreams) == 1 && $args['checksum'] == $bitstreams[0]->getChecksum()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

===

return array('token' => '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not really like returning an invalid token. Throw an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
See

* If <b>checksum</b> is passed and the token returned is blank, the

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down
4 changes: 4 additions & 0 deletions modules/api/controllers/components/ApiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,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
Expand Down