@@ -977,18 +977,40 @@ function userApikeyDefault($args)
977
977
return array ('apikey ' => $ defaultApiKey );
978
978
}
979
979
980
+ /**
981
+ * Download a bitstream either by its id or by a checksum. Either an id or checksum parameter is required.
982
+ * @param token (Optional) Authentication token
983
+ * @param id (Optional) The id of the bitstream
984
+ * @param checksum (Optional) The checksum of the bitstream
985
+ * @param name (Optional) Alternate filename to download as
986
+ */
980
987
function bitstreamDownload ($ args )
981
988
{
982
- $ this ->_validateParams ($ args , array ('id ' ));
989
+ if (!array_key_exists ('id ' , $ args ) && !array_key_exists ('checksum ' , $ args ))
990
+ {
991
+ throw new Exception ('Either an id or checksum parameter is required ' , MIDAS_INVALID_PARAMETER );
992
+ }
983
993
$ userDao = $ this ->_getUser ($ args );
984
994
$ modelLoader = new MIDAS_ModelLoader ();
985
995
$ bitstreamModel = $ modelLoader ->loadModel ('Bitstream ' );
986
- $ bitstream = $ bitstreamModel ->load ($ args ['id ' ]);
996
+ if (array_key_exists ('id ' , $ args ))
997
+ {
998
+ $ bitstream = $ bitstreamModel ->load ($ args ['id ' ]);
999
+ }
1000
+ else
1001
+ {
1002
+ $ bitstream = $ bitstreamModel ->getByChecksum ($ args ['checksum ' ]);
1003
+ }
987
1004
988
1005
if (!$ bitstream )
989
1006
{
990
1007
throw new Exception ('Invalid bitstream id ' , MIDAS_INVALID_PARAMETER );
991
1008
}
1009
+
1010
+ if (array_key_exists ('name ' , $ args ))
1011
+ {
1012
+ $ bitstream ->setName ($ args ['name ' ]);
1013
+ }
992
1014
$ revisionModel = $ modelLoader ->loadModel ('ItemRevision ' );
993
1015
$ revision = $ revisionModel ->load ($ bitstream ->getItemrevisionId ());
994
1016
0 commit comments