Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Add parameters for specifying length and checksum of files to which l…
Browse files Browse the repository at this point in the history
…ink points
  • Loading branch information
Jamie Snape committed Jun 3, 2014
1 parent fe41983 commit f8be410
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 11 additions & 1 deletion core/controllers/components/ApisystemComponent.php
Expand Up @@ -212,6 +212,10 @@ function userApikeyDefault($args)
* @param itemname (Optional)
The name of the newly created item, if not supplied, the item will
have the same name as <b>url</b>.
* @param length (Optional)
The length in bytes of the file to which the link points.
* @param checksum (Optional)
The md5 checksum of the file to which the link points.
* @return The item information of the item created.
*/
function linkCreate($args)
Expand Down Expand Up @@ -244,8 +248,14 @@ function linkCreate($args)
throw new Exception('Invalid URL', MIDAS_INVALID_PARAMETER);
}
$itemname = isset($args['itemname']) ? $args['itemname'] : $args['url'];
if(isset($args['length']) && !filter_var($args['length'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 0))))
{
throw new Exception('Invalid length', MIDAS_INVALID_PARAMETER);
}
$length = isset($args['length']) ? $args['length'] : 0;
$checksum = isset($args['checksum']) ? $args['checksum'] : ' ';
$uploadComponent = MidasLoader::loadComponent('Upload');
$item = $uploadComponent->createLinkItem($userDao, $itemname, $args['url'], $folder);
$item = $uploadComponent->createLinkItem($userDao, $itemname, $args['url'], $folder, $length, $checksum);
if(!$item)
{
throw new Exception('Link creation failed', MIDAS_INTERNAL_ERROR);
Expand Down
7 changes: 4 additions & 3 deletions core/controllers/components/UploadComponent.php
Expand Up @@ -116,7 +116,7 @@ function uploadBitstream($bitstreamdao, $assetstoredao, $copy = false)
} // end uploadBitstream()

/** save upload item in the DB */
public function createLinkItem($userDao, $name, $url, $parent = null)
public function createLinkItem($userDao, $name, $url, $parent = null, $sizebytes = 0, $checksum = ' ')
{
$itemModel = MidasLoader::loadModel('Item');
$feedModel = MidasLoader::loadModel('Feed');
Expand Down Expand Up @@ -147,6 +147,7 @@ public function createLinkItem($userDao, $name, $url, $parent = null)
$item = new ItemDao;
$item->setName($name);
$item->setDescription('');
$item->setSizebytes($sizebytes);
$item->setType(0);
$item->setPrivacyStatus(MIDAS_PRIVACY_PRIVATE); // Must set this flag private initially
$itemModel->save($item, false);
Expand All @@ -173,8 +174,8 @@ public function createLinkItem($userDao, $name, $url, $parent = null)
$bitstreamDao->setName($url);
$bitstreamDao->setPath($url);
$bitstreamDao->setMimetype('url');
$bitstreamDao->setSizebytes(0);
$bitstreamDao->setChecksum(' ');
$bitstreamDao->setSizebytes($sizebytes);
$bitstreamDao->setChecksum($checksum);

$assetstoreDao = $assetstoreModel->getDefault();
$bitstreamDao->setAssetstoreId($assetstoreDao->getKey());
Expand Down

0 comments on commit f8be410

Please sign in to comment.