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

Commit

Permalink
BUG: fixed sql files and now the upload process is in a component
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Marion committed Mar 15, 2011
1 parent 65952c9 commit 3e79a6b
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 106 deletions.
20 changes: 17 additions & 3 deletions application/controllers/UploadController.php
Expand Up @@ -4,7 +4,7 @@ class UploadController extends AppController
{
public $_models=array('User','Item','ItemRevision','Folder','Itempolicyuser',"ItemKeyword",'Itempolicygroup','Group','Feed',"Feedpolicygroup","Feedpolicyuser",'Bitstream','Assetstore');
public $_daos=array('User','Item','ItemRevision','Bitstream','Folder',"ItemKeyword");
public $_components=array('Httpupload');
public $_components=array('Httpupload','Upload');
public $_forms=array('Upload');

/**
Expand Down Expand Up @@ -161,6 +161,10 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
{
$item = new ItemDao;
$item->setName($name);
$item->setDate(date('c'));
$item->setDescription('');
$item->setType(0);
$item->setThumbnail('');
$this->Item->save($item);

// Set the keyword for the item
Expand All @@ -182,17 +186,27 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
}
$this->Feedpolicyuser->createPolicy($this->userSession->Dao,$feed,MIDAS_POLICY_ADMIN);
$this->Itempolicyuser->createPolicy($userDao,$item,MIDAS_POLICY_ADMIN);

$itemRevisionDao = new ItemRevisionDao;
$itemRevisionDao->setChanges('Initial revision');
$itemRevisionDao->setUser_id($userDao->getKey());
$this->Item->addRevision($item,$itemRevisionDao);

$this->Item->addKeyword($item,$keyword);
$this->Item->addKeyword($item,$keyword);

// Add bitstreams to the revision
$bitstreamDao = new BitstreamDao;
$bitstreamDao->setName($name);
$bitstreamDao->setPath($path);
$bitstreamDao->fillPropertiesFromPath();

$defaultAssetStoreId=Zend_Registry::get('configGlobal')->defaultassetstore->id;
$bitstreamDao->setAssetstoreId($defaultAssetStoreId);
$assetstoreDao=$this->Assetstore->load($defaultAssetStoreId);

$bitstreamDao=$this->Bitstream->initBitstream($assetstoreDao, $name, $path);
// Upload the bitstream if necessary (based on the assetstore type)
$this->Component->Upload->uploadBitstream($bitstreamDao,$assetstoreDao);

$this->ItemRevision->addBitstream($itemRevisionDao,$bitstreamDao);

$this->getLogger()->info(__METHOD__." Upload ok (".$privacy."):".$path);
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/forms/InstallForm.php
Expand Up @@ -21,7 +21,7 @@ public function createDBForm($type)
->setRequired(true)
->addValidator('NotEmpty', true);

$password = new Zend_Form_Element_Text('password');
$password = new Zend_Form_Element_Password('password');

$dbname = new Zend_Form_Element_Text('dbname');
$dbname
Expand Down
37 changes: 0 additions & 37 deletions application/models/pdo/BitstreamModel.php
Expand Up @@ -25,43 +25,6 @@ class BitstreamModel extends AppModelPdo
'assetstore' => array('type'=>MIDAS_ONE_TO_MANY, 'model' => 'Assetstore', 'parent_column'=> 'assetstore_id', 'child_column' => 'assetstore_id'),
);

/** init the bitstream (before save it using addBitstream in ItemRevision Model*/
public function initBitstream($assetstoreDao,$name,$path)
{
Zend_Loader::loadClass('BitstreamDao', BASE_PATH.'/application/models/dao');
$bitstreamDao = new BitstreamDao;
$bitstreamDao->setName($name);
$bitstreamDao->setPath($path);

$tmpPath=$assetstoreDao->getPath().'/'.rand(1, 1000);
if(!file_exists($assetstoreDao->getPath()))
{
throw new Zend_Exception("Problem assetstore path: "+$assetstoreDao->getKey());
}
if(!file_exists($tmpPath))
{
mkdir($tmpPath);
}
$tmpPath.='/'.rand(1, 1000);
if(!file_exists($tmpPath))
{
mkdir($tmpPath);
}
$fullPath=$tmpPath."/".rand(1,1000);
while(file_exists($fullPath))
{
$fullPath=$tmpPath."/".rand(1,1000);
}
if(!rename ( $path ,$fullPath))
{
throw new Zend_Exception("Unable to move file ".$path.' to '.$fullPath);
}
$bitstreamDao->setPath($fullPath);
$bitstreamDao->fillPropertiesFromPath();
$bitstreamDao->setAssetstoreId($assetstoreDao->getKey());

return $bitstreamDao;
}

/** do not use, use method addBitstream in ItemRevision Model*/
public function save($dao)
Expand Down
98 changes: 39 additions & 59 deletions application/models/pdo/FeedModel.php
Expand Up @@ -133,88 +133,68 @@ private function _getFeeds($loggedUserDao,$userDao=null,$communityDao=null,$poli
throw new Zend_Exception("Should be a community.");
}

$subqueryUser= $this->select()
->setIntegrityCheck(false)
->from(array('f' => 'feed'))
->join(array('p' => 'feedpolicyuser'),
'f.feed_id=p.feed_id',
array('p.policy'))
->where('p.policy >= ?', $policy)
->where('p.user_id = ? ',$userId)
->limit($limit);

$subqueryGroup = $this->select()
->setIntegrityCheck(false)
->from(array('f' => 'feed'))
->join(array('p' => 'feedpolicygroup'),
'f.feed_id=p.feed_id',
array('p.policy'))
->where('p.policy >= ?', $policy)
->where('( '.$this->_db->quoteInto('p.group_id = ? ',MIDAS_GROUP_ANONYMOUS_KEY).' OR
p.group_id IN (' .new Zend_Db_Expr(
$this->select()
->setIntegrityCheck(false)
->from(array('u2g' => 'user2group'),
array('group_id'))
->where('u2g.user_id = ?' , $userId)
.'))' ))
->limit($limit);

$sql=$this->select()
->setIntegrityCheck(false)
->from(array('f' => 'feed'))
->joinLeft(array('fpu' => 'feedpolicyuser'),'
f.feed_id = fpu.feed_id AND '.$this->_db->quoteInto('fpu.policy >= ?', $policy).'
AND '.$this->_db->quoteInto('fpu.user_id = ? ',$userId).' ',array('userpolicy'=>'fpu.policy'))
->joinLeft(array('fpg' => 'feedpolicygroup'),'
f.feed_id = fpg.feed_id AND '.$this->_db->quoteInto('fpg.policy >= ?', $policy).'
AND ( '.$this->_db->quoteInto('fpg.group_id = ? ',MIDAS_GROUP_ANONYMOUS_KEY).' OR
fpg.group_id IN (' .new Zend_Db_Expr(
$this->select()
->setIntegrityCheck(false)
->from(array('u2g' => 'user2group'),
array('group_id'))
->where('u2g.user_id = ?' , $userId)
) .'))' ,array('grouppolicy'=>'fpg.policy'))
->where(
'(
fpu.feed_id is not null or
fpg.feed_id is not null)'
)
->limit($limit)
;

if($userDao!=null)
{
$subqueryUser->where('f.user_id = ? ',$userDao->getKey());
$subqueryGroup->where('f.user_id = ? ',$userDao->getKey());
$sql->where('f.user_id = ? ',$userDao->getKey());
}

if($communityDao!=null)
{
$subqueryUser->join(array('f2c' => 'feed2community'),
$sql->join(array('f2c' => 'feed2community'),
$this->_db->quoteInto('f2c.community_id = ? ',$communityDao->getKey())
.' AND f.feed_id = f2c.feed_id' ,array());
$subqueryGroup->join(array('f2c' => 'feed2community'),
$this->_db->quoteInto('f2c.community_id = ? ',$communityDao->getKey())
.' AND f.feed_id =f2c.feed_id' ,array());
}

$sql = $this->select()
->union(array($subqueryUser, $subqueryGroup));
$rowset = $this->fetchAll($sql);
$rowsetAnalysed=array();
foreach ($rowset as $keyRow=>$row)
{
foreach($rowsetAnalysed as $keyRa=>$ra)
if($row['userpolicy']==null)$row['userpolicy']=0;
if($row['grouppolicy']==null)$row['grouppolicy']=0;
if(!isset($rowsetAnalysed[$row['feed_id']])||($rowsetAnalysed[$row['feed_id']]->policy<$row['userpolicy']&&$rowsetAnalysed[$row['feed_id']]->policy<$row['grouppolicy']))
{
if($ra->getKey()==$row['feed_id'])
$tmpDao= $this->initDao('Feed', $row);
if($row['userpolicy']>=$row['grouppolicy'])
{
if($ra->policy<$row['policy'])
{
$rowsetAnalysed[$keyRa]->policy=$row['policy'];
}
unset($row);
break;
$tmpDao->policy=$row['userpolicy'];
}
}
if(isset($row))
{
$tmpDao= $this->initDao('Feed', $row);
$tmpDao->policy=$row['policy'];
$rowsetAnalysed[] = $tmpDao;
else
{
$tmpDao->policy=$row['grouppolicy'];
}
$rowsetAnalysed[$row['feed_id']] = $tmpDao;
unset($tmpDao);
}
}
}
$this->Component->Sortdao->field='date';
$this->Component->Sortdao->order='asc';
usort($rowsetAnalysed, array($this->Component->Sortdao,'sortByDate'));
$i=0;
foreach($rowsetAnalysed as $keyRa=>$r)
{
if($i>$limit)
{
unset($rowsetAnalysed[$keyRa]);
}
$i++;
}
return $rowsetAnalysed;
return $rowsetAnalysed;
}
/** Create a feed
* @return FeedDao */
Expand Down
6 changes: 3 additions & 3 deletions application/models/pdo/FolderModel.php
Expand Up @@ -133,7 +133,7 @@ public function getSizeFiltered($folders,$userDao=null,$policy=0)

$sql=$this->select()
->setIntegrityCheck(false)
->from(array('i' => 'item'),array('sum(i.sizebytes)','count(i.item_id)'))
->from(array('i' => 'item'),array('sum'=>'sum(i.sizebytes)','count'=>'count(i.item_id)'))
->join(array('i2f' => 'item2folder'),
'( '.$this->_db->quoteInto('i2f.folder_id IN (?)',$subSqlFolders).'
OR i2f.folder_id='.$folder->getKey().'
Expand Down Expand Up @@ -162,8 +162,8 @@ public function getSizeFiltered($folders,$userDao=null,$policy=0)


$row = $this->fetchRow($sql);
$folders[$key]->count = $row['count(i.item_id)'];
$folders[$key]->size = $row['sum(i.sizebytes)'];
$folders[$key]->count = $row['count'];
$folders[$key]->size = $row['sum'];
if($folders[$key]->size==null)
{
$folders[$key]->size=0;
Expand Down
13 changes: 10 additions & 3 deletions application/models/pdo/ItemModel.php
Expand Up @@ -97,14 +97,21 @@ function getRandomItems($userDao=null,$policy=0,$limit=10,$thumbnailFilter=false
$userId = $userDao->getUserId();
}


if(Zend_Registry::get('configDatabase')->database->adapter=='PDO_MYSQL')
{
$rand='RAND()';
}
else
{
$rand='random()';
}
$sql=$this->select()
->setIntegrityCheck(false)
->from(array('i' => 'item'))
->join(array('tt'=> $this->select()
->from(array('i' => 'item'),array('maxid'=>'MAX(item_id)'))
),
' i.item_id >= FLOOR(tt.maxid*RAND())')
),
' i.item_id >= FLOOR(tt.maxid*'.$rand.')')
->joinLeft(array('ip' => 'itempolicyuser'),'
i.item_id = ip.item_id AND '.$this->_db->quoteInto('ip.policy >= ?', $policy).'
AND '.$this->_db->quoteInto('user_id = ? ',$userId).' ',array('userpolicy'=>'ip.policy'))
Expand Down

0 comments on commit 3e79a6b

Please sign in to comment.