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

Commit d4762c8

Browse files
author
Michael Grauer
committed
BUG: refs #0342. Added support to download zips of empty items.
1 parent d1f8ef7 commit d4762c8

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

core/controllers/DownloadController.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public function indexAction()
108108

109109
if(empty($folders) && empty($revisions))
110110
{
111-
throw new Zend_Exception('There is nothing to download');
111+
// download an empty zip with the name of item (if it exists), then exit
112+
$this->_downloadEmptyItem($item);
112113
}
113114
if(empty($folders) && count($revisions) == 1)
114115
{
@@ -122,7 +123,8 @@ public function indexAction()
122123

123124
if(count($bitstreams) == 0)
124125
{
125-
throw new Zend_Exception('Empty item');
126+
// download an empty zip with the name of item (if it exists), then exit
127+
$this->_downloadEmptyItem($item);
126128
}
127129
elseif(count($bitstreams) == 1)
128130
{
@@ -202,6 +204,37 @@ public function indexAction()
202204
}
203205
}//end index
204206

207+
/**
208+
* will download a zip file with the same name as the item name,
209+
* if the item exists, then will exit.
210+
* @param type $item
211+
*/
212+
private function _downloadEmptyItem($item)
213+
{
214+
while(ob_get_level() > 0)
215+
{
216+
ob_end_clean();
217+
}
218+
ob_start();
219+
Zend_Loader::loadClass('ZipStream', BASE_PATH.'/library/ZipStream/');
220+
$this->_helper->viewRenderer->setNoRender();
221+
if(isset($item))
222+
{
223+
$name = $item->getName();
224+
}
225+
else
226+
{
227+
$name = "No_item_selected";
228+
}
229+
$name = substr($name, 0, 50);
230+
$zip = new ZipStream($name.'.zip');
231+
$zip->finish();
232+
exit();
233+
}
234+
235+
236+
237+
205238
/** create zip recursive*/
206239
private function _createZipRecursive($zip, $path, $folders, $revisions)
207240
{

0 commit comments

Comments
 (0)