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

Commit 466aa94

Browse files
author
Charles Marion
committed
BUG: fixed Upload/Dowload
fixed Dao loading
1 parent ecbb3fd commit 466aa94

File tree

9 files changed

+39
-20
lines changed

9 files changed

+39
-20
lines changed

core/controllers/DownloadController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function indexAction()
103103
{
104104
$bitstream=$bitstreams[0];
105105
$this->view->mimetype = $bitstream->getMimetype();
106-
$this->view->path = $bitstream->getPath();
106+
$this->view->path = $bitstream->getAssetstore()->getPath().'/'.$bitstream->getPath();
107107
$this->view->name =$bitstream->getName();
108108
if(!file_exists($this->view->path))
109109
{
@@ -120,7 +120,7 @@ public function indexAction()
120120
$zip = new ZipStream($name.'.zip');
121121
foreach ($bitstreams as $bitstream)
122122
{
123-
$zip->add_file_from_path($bitstream->getName(), $bitstream->getPath());
123+
$zip->add_file_from_path($bitstream->getName(), $bitstream->getAssetstore()->getPath().'/'.$bitstream->getPath());
124124
}
125125
$zip->finish();
126126
}
@@ -152,7 +152,7 @@ private function createZipRecursive($zip,$path,$folders,$revisions)
152152
$bitstreams=$revision->getBitstreams();
153153
foreach ($bitstreams as $bitstream)
154154
{
155-
$zip->add_file_from_path($path.'/'.$bitstream->getName(), $bitstream->getPath());
155+
$zip->add_file_from_path($path.'/'.$bitstream->getName(), $bitstream->getAssetstore()->getPath().'/'.$bitstream->getPath());
156156
}
157157
}
158158
foreach($folders as $folder)
@@ -178,7 +178,7 @@ private function createZipRecursive($zip,$path,$folders,$revisions)
178178
$bitstreams=$subRevisions->getBitstreams();
179179
foreach ($bitstreams as $bitstream)
180180
{
181-
$zip->add_file_from_path($path.'/'.$bitstream->getName(), $bitstream->getPath());
181+
$zip->add_file_from_path($path.'/'.$bitstream->getName(), $bitstream->getAssetstore()->getPath().'/'. $bitstream->getPath());
182182
}
183183
}
184184
}

core/controllers/UploadController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,13 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
207207

208208
// Upload the bitstream if necessary (based on the assetstore type)
209209
$this->Component->Upload->uploadBitstream($bitstreamDao,$assetstoreDao);
210-
210+
$checksum=$bitstreamDao->getChecksum();
211+
$tmpBitstreamDao=$this->Bitstream->getByChecksum($checksum);
212+
if($tmpBitstreamDao!=false)
213+
{
214+
$bitstreamDao->setPath($tmpBitstreamDao->getPath());
215+
$bitstreamDao->setAssetstoreId($tmpBitstreamDao->getAssetstoreId());
216+
}
211217
$this->ItemRevision->addBitstream($itemRevisionDao,$bitstreamDao);
212218

213219
$this->getLogger()->info(__METHOD__." Upload ok (".$privacy."):".$path);

core/models/base/BitstreamModelBase.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
class BitstreamModelBase extends AppModel
2+
abstract class BitstreamModelBase extends AppModel
33
{
44
public function __construct()
55
{
@@ -19,10 +19,13 @@ public function __construct()
1919
'assetstore_id' => array('type'=>MIDAS_DATA),
2020
'date' => array('type'=>MIDAS_DATA),
2121
//'itemrevision' => array('type'=>MIDAS_ONE_TO_MANY, 'model' => 'ItemRevision', 'parent_column'=> 'itemrevision_id', 'child_column' => 'itemrevision_id'),
22-
'assetstore' => array('type'=>MIDAS_ONE_TO_MANY, 'model' => 'Assetstore', 'parent_column'=> 'assetstore_id', 'child_column' => 'assetstore_id'),
22+
'assetstore' => array('type'=>MIDAS_MANY_TO_ONE, 'model' => 'Assetstore', 'parent_column'=> 'assetstore_id', 'child_column' => 'assetstore_id'),
2323
);
2424
$this->initialize(); // required
2525
} // end __construct()
26+
27+
/** Abstract functions */
28+
abstract function getByChecksum($checksum);
2629

2730
} // end class BitstreamModelBase
2831
?>

core/models/base/FolderModelBase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function __construct()
2727
} // end __construct()
2828

2929
/** Abstract functions */
30-
abstract function getByFolder_id($folderid);
3130
abstract function getChildrenFoldersFiltered($folder,$userDao=null,$policy=0);
3231
abstract function getItemsFiltered($folder,$userDao=null,$policy=0);
3332
abstract function getSizeFiltered($folders,$userDao=null,$policy=0);

core/models/pdo/BitstreamModel.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public function save($dao)
1818
throw new Zend_Exception(" Do not use, use method addBitstream in ItemRevision Model.");
1919
}//end Save
2020

21-
21+
/** Get bitstream by checksum */
22+
function getByChecksum($checksum)
23+
{
24+
$row = $this->database->fetchRow($this->database->select()->where('checksum = ?', $checksum));
25+
$dao= $this->initDao(ucfirst($this->_name),$row);
26+
return $dao;
27+
} // end getByChecksum()
2228
} // end class
2329
?>

core/models/pdo/FolderModel.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77
*/
88
class FolderModel extends FolderModelBase
99
{
10-
11-
/** Get a folder by id */
12-
function getByFolder_id($folderid)
13-
{
14-
$row = $this->database->fetchRow($this->database->select()->where('folder_id = ?', $folderid));
15-
$dao=$this->initDao(ucfirst($this->_name),$row);
16-
return $dao;
17-
} // end getByFolder_id()
1810

1911
/** check if the policy is valid*/
2012
function policyCheck($folderDao,$userDao=null,$policy=0)

core/models/pdo/ItemKeywordModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function insertKeyword($keyword)
104104
// Check if the keyword already exists
105105
$row = $this->database->fetchRow($this->database->select()->from($this->_name)
106106
->where('value=?',$keyword->getValue()));
107+
107108
if($row)
108109
{
109110
$row->relevance += 1; // increase the relevance
@@ -113,7 +114,7 @@ function insertKeyword($keyword)
113114
else
114115
{
115116
$keyword->setRelevance(1);
116-
$return = $this->save($keyword);
117+
$return = parent::save($keyword);
117118
}
118119
unset($row);
119120
return $return;

core/models/pdo/ItemRevisionModel.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ function addBitstream($itemRevisionDao,$bitstreamDao)
4343
$bitstreamDao->setItemrevisionId($itemRevisionDao->getItemrevisionId());
4444

4545
// Save the bistream
46-
$bitstreamDao->setDate(date('c'));
47-
$BitstreamModel->save($bitstreamDao);
46+
if(!isset($bitstreamDao->saved)||!$bitstreamDao->saved)
47+
{
48+
$bitstreamDao->setDate(date('c'));
49+
$BitstreamModel->save($bitstreamDao);
50+
}
4851

4952
$item=$itemRevisionDao->getItem($bitstreamDao);
5053
$item->setSizebytes($this->getSize($itemRevisionDao));

library/MIDAS/models/MIDASDatabasePdo.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public function getValue($var, $key, $dao)
8686
require_once BASE_PATH.'/library/MIDAS/models/ModelLoader.php';
8787
$this->ModelLoader = new MIDAS_ModelLoader();
8888
$model = $this->ModelLoader->loadModel($this->_mainData[$var]['model']);
89+
$key = $model->getKey();
90+
if($this->_mainData[$var]['child_column']==$key)
91+
{
92+
return $model->load($dao->get($this->_mainData[$var]['parent_column']));
93+
}
8994
if(!method_exists($model, 'getBy'.ucfirst($this->_mainData[$var]['child_column'])))
9095
{
9196
throw new Zend_Exception(get_class($model).'::getBy'.ucfirst($this->_mainData[$var]['child_column'])." is not implemented");
@@ -336,6 +341,10 @@ public function getAllByKey($keys)
336341
unset($keys[$k]);
337342
}
338343
}
344+
if(empty($keys))
345+
{
346+
return array();
347+
}
339348
return $this->fetchAll($this->select()->where($this->_key . ' IN (?)', $keys));
340349
}
341350

0 commit comments

Comments
 (0)