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

Commit 1ae6c2c

Browse files
author
Charles Marion
committed
ENH: improved upload workflow
1 parent 211d1e3 commit 1ae6c2c

File tree

16 files changed

+427
-95
lines changed

16 files changed

+427
-95
lines changed

core/AppController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,16 @@ public function preDispatch()
111111
"Yes"=>$this->t('Yes'),
112112
"No"=>$this->t('No')
113113
);
114+
115+
114116
$login=array(
115117
"titleUploadLogin"=>$this->t('Please log in'),
116118
"contentUploadLogin"=>$this->t('You need to be logged in to be able to upload files.')
117119
);
118120

119121
$browse=array(
120122
'view'=>$this->t('View'),
123+
'uploadIn'=>$this->t('Upload here'),
121124
'createFolder'=>$this->t('Create a new Folder'),
122125
'preview'=>$this->t('Preview'),
123126
'download'=>$this->t('Download'),

core/controllers/BrowseController.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,18 @@ public function movecopyAction()
100100
if(isset($copySubmit))
101101
{
102102
$this->Folder->addItem($destination,$item);
103+
$this->Item->copyParentPolicies($item,$destination);
103104
}
104105
else
105106
{
106107
$from=$this->_getParam('from');
107-
$from=$this->Folder->load($from);
108+
$from=$this->Folder->load($from);
108109
if($destination==false)
109110
{
110111
throw new Zend_Exception("Unable to load destination");
111112
}
112113
$this->Folder->addItem($destination,$item);
114+
$this->Item->copyParentPolicies($item,$destination);
113115
$this->Folder->removeItem($from, $item);
114116
}
115117
}
@@ -321,10 +323,22 @@ public function uploadedAction()
321323
$this->_redirect('/');
322324
}
323325
$this->view->items=array();
326+
$this->view->header=$this->t('Uploaded Files');
327+
$this->view->Date=$this->Component->Date;
324328
foreach($this->userSession->uploaded as $item)
325329
{
326-
$this->view->items[]=$this->Item->load($item);
330+
$item=$this->Item->load($item);
331+
if($item!=false)
332+
{
333+
$item->policy=MIDAS_POLICY_ADMIN;
334+
$item->size=$this->Component->Utility->formatSize($item->getSizebytes());
335+
$this->view->items[]=$item;
336+
}
327337
}
338+
$this->view->json['item']['message']['delete']=$this->t('Delete');
339+
$this->view->json['item']['message']['deleteMessage']=$this->t('Do you really want to delete this item? It cannot be undo.');
340+
$this->view->json['item']['message']['merge']=$this->t('Merge Files in one Item');
341+
$this->view->json['item']['message']['mergeName']=$this->t('Name of the item');
328342
}
329343
} // end class
330344

core/controllers/DownloadController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function indexAction()
6868
{
6969
continue;
7070
}
71-
$this->Item->plusOneDownload($item);
71+
$this->Item->incrementDownloadCount($item);
7272
if(isset($tmp[1]))
7373
{
7474
$tmp=$this->Item->getRevision($item,$tmp[1]);

core/controllers/ItemController.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class ItemController extends AppController
44
{
5-
public $_models=array('Item');
5+
public $_models=array('Item','ItemRevision','Bitstream');
66
public $_daos=array();
77
public $_components=array('Date','Utility');
88
public $_forms=array();
@@ -111,6 +111,61 @@ function deleteAction()
111111
$this->_redirect('/?checkRecentItem=true');
112112
}//end delete
113113

114+
115+
/** Merge items*/
116+
function mergeAction()
117+
{
118+
$this->_helper->layout->disableLayout();
119+
$this->_helper->viewRenderer->setNoRender();
120+
121+
$itemIds=$this->_getParam("items");
122+
$name=$this->_getParam("name");
123+
if(empty($name))
124+
{
125+
throw new Zend_Exception('Please set a name');
126+
}
127+
$itemIds=explode('-',$itemIds);
128+
129+
$items=array();
130+
foreach ($itemIds as $item)
131+
{
132+
$itemDao=$this->Item->load($item);
133+
if($itemDao!=false&&$this->Item->policyCheck($itemDao,$this->userSession->Dao,MIDAS_POLICY_ADMIN))
134+
{
135+
$items[]=$itemDao;
136+
}
137+
}
138+
139+
if(empty($items))
140+
{
141+
throw new Zend_Exception('Permissions error');
142+
}
143+
144+
145+
$mainItem=$items[0];
146+
$mainItemLastResision=$this->Item->getLastRevision($mainItem);
147+
foreach ($items as $key => $item)
148+
{
149+
if($key!=0)
150+
{
151+
$revision=$this->Item->getLastRevision($item);
152+
$bitstreams=$revision->getBitstreams();
153+
foreach($bitstreams as $b)
154+
{
155+
$b->setItemrevisionId($mainItemLastResision->getKey());
156+
$this->Bitstream->save($b);
157+
}
158+
$this->Item->delete($item);
159+
}
160+
}
161+
162+
$mainItem->setSizebytes($this->ItemRevision->getSize($mainItemLastResision));
163+
$mainItem->setName($name);
164+
$this->Item->save($mainItem);
165+
166+
$this->_redirect('/browse/uploaded');
167+
}//end delete
168+
114169
}//end class
115170

116171
/* pour la récupérer

core/controllers/UploadController.php

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ public function simpleuploadAction()
4040
$this->view->form=$this->getFormAsArray($this->Form->Upload->createUploadLinkForm());
4141
$this->userSession->uploaded=array();
4242
$this->view->selectedLicense=Zend_Registry::get('configGlobal')->defaultlicense;
43+
44+
$this->view->defaultUploadLocation=$this->userSession->Dao->getPrivatefolderId();
45+
$this->view->defaultUploadLocationText=$this->t('My Private Folder');
46+
47+
$parent=$this->_getParam('parent');
48+
if(isset($parent))
49+
{
50+
$parent=$this->Folder->load($parent);
51+
if($this->logged&&$parent!=false)
52+
{
53+
$this->view->defaultUploadLocation=$parent->getKey();
54+
$this->view->defaultUploadLocationText=$parent->getName();
55+
}
56+
}
4357
}//end simple upload
4458

4559

@@ -149,10 +163,11 @@ public function saveuploadedAction()
149163
$upload->receive();
150164
$path=$upload->getFileName();
151165
$file_size=filesize($path);
152-
$privacy=$this->_getParam("privacy");
166+
$parent=$this->_getParam("parent");
167+
$license=$this->_getParam("license");
153168
if (!empty($path)&& file_exists($path) && $upload->getFileSize() > 0)
154169
{
155-
$item=$this->createUploadedItem($this->userSession->Dao,$upload->getFilename(null,false),$upload->getFilename(),$privacy);
170+
$item=$this->createUploadedItem($this->userSession->Dao,$upload->getFilename(null,false),$upload->getFilename(),$parent,$license);
156171
$this->userSession->uploaded[]=$item->getKey();
157172

158173
$info= array();
@@ -163,8 +178,27 @@ public function saveuploadedAction()
163178
}//end saveuploaded
164179

165180
/** save upload item in the DB */
166-
private function createUploadedItem($userDao,$name,$path,$privacy=null)
181+
private function createUploadedItem($userDao,$name,$path,$parent=null,$license=null)
167182
{
183+
if($userDao==null)
184+
{
185+
throw new Zend_Exception('Please log in');
186+
}
187+
188+
if($parent==null)
189+
{
190+
$parent=$userDao->getPrivateFolder();
191+
}
192+
if(is_numeric($parent))
193+
{
194+
$parent=$this->Folder->load($parent);
195+
}
196+
197+
if($parent==false||!$this->Folder->policyCheck($parent, $userDao, MIDAS_POLICY_WRITE))
198+
{
199+
throw new Zend_Exception('Parent permissions errors');
200+
}
201+
168202
$item = new ItemDao;
169203
$item->setName($name);
170204
$item->setDate(date('c'));
@@ -173,25 +207,19 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
173207
$item->setThumbnail('');
174208
$this->Item->save($item);
175209

176-
$feed=$this->Feed->createFeed($this->userSession->Dao,MIDAS_FEED_CREATE_ITEM,$item);
177-
if(isset($privacy)&&$privacy=='public')
178-
{
179-
$this->Folder->addItem($userDao->getPublicFolder(),$item);
180-
$anonymousGroup=$this->Group->load(MIDAS_GROUP_ANONYMOUS_KEY);
181-
$this->Itempolicygroup->createPolicy($anonymousGroup,$item,MIDAS_POLICY_READ);
182-
$this->Feedpolicygroup->createPolicy($anonymousGroup,$feed,MIDAS_POLICY_READ);
183-
}
184-
else
185-
{
186-
$this->Folder->addItem($userDao->getPrivateFolder(),$item);
187-
}
188-
$this->Feedpolicyuser->createPolicy($this->userSession->Dao,$feed,MIDAS_POLICY_ADMIN);
210+
$feed=$this->Feed->createFeed($userDao,MIDAS_FEED_CREATE_ITEM,$item);
211+
212+
$this->Folder->addItem($parent,$item);
213+
$this->Item->copyParentPolicies($item,$parent,$feed);
214+
215+
$this->Feedpolicyuser->createPolicy($userDao,$feed,MIDAS_POLICY_ADMIN);
189216
$this->Itempolicyuser->createPolicy($userDao,$item,MIDAS_POLICY_ADMIN);
190217

191218
$itemRevisionDao = new ItemRevisionDao;
192219
$itemRevisionDao->setChanges('Initial revision');
193220
$itemRevisionDao->setUser_id($userDao->getKey());
194221
$itemRevisionDao->setDate(date('c'));
222+
$itemRevisionDao->setLicense($license);
195223
$this->Item->addRevision($item,$itemRevisionDao);
196224

197225
// Set the keyword for the item
@@ -237,7 +265,7 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
237265
}
238266
$this->ItemRevision->addBitstream($itemRevisionDao,$bitstreamDao);
239267

240-
$this->getLogger()->info(__METHOD__." Upload ok (".$privacy."):".$path);
268+
$this->getLogger()->info(__METHOD__." Upload ok :".$path);
241269
return $item;
242270
}//end createUploadedItem
243271

core/database/upgrade/3.0.2.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
class Upgrade_3_0_2 extends MIDASUpgrade
4+
{
5+
public function preUpgrade()
6+
{
7+
8+
}
9+
10+
public function mysql()
11+
{
12+
$sql = "ALTER TABLE itemrevision ADD COLUMN license integer DEFAULT 0; ";
13+
$this->db->query($sql);
14+
}
15+
16+
public function pgsql()
17+
{
18+
$sql = "ALTER TABLE itemrevision ADD COLUMN license tinyint(4) NOT NULL DEFAULT '0', ; ";
19+
$this->db->query($sql);
20+
}
21+
22+
public function postUpgrade()
23+
{
24+
25+
}
26+
}
27+
?>

core/models/base/ItemModelBase.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,43 @@ abstract function getOwnedByUser($userDao,$limit=20);
3030
abstract function getSharedToUser($userDao,$limit=20);
3131
abstract function getSharedToCommunity($communityDao,$limit=20);
3232

33+
/** copy parent folder policies*/
34+
function copyParentPolicies($itemdao,$folderdao,$feeddao=null)
35+
{
36+
if(!$itemdao instanceof ItemDao||!$folderdao instanceof FolderDao)
37+
{
38+
throw new Zend_Exception("Error param.");
39+
}
40+
$groupPolicies=$folderdao->getFolderpolicygroup();
41+
$userPolicies=$folderdao->getFolderpolicyuser();
42+
43+
$modelLoad = new MIDAS_ModelLoader();
44+
$ItempolicygroupModel = $modelLoad->loadModel('Itempolicygroup');
45+
foreach ($groupPolicies as $key => $policy)
46+
{
47+
$ItempolicygroupModel->createPolicy($policy->getGroup(), $itemdao, $policy->getPolicy());
48+
}
49+
$ItempolicyuserModel = $modelLoad->loadModel('Itempolicyuser');
50+
foreach ($userPolicies as $key => $policy)
51+
{
52+
$ItempolicyuserModel->createPolicy($policy->getUser(), $itemdao, $policy->getPolicy());
53+
}
54+
55+
if($feeddao!=null &&$feeddao instanceof FeedDao)
56+
{
57+
$FeedpolicygroupModel = $modelLoad->loadModel('Feedpolicygroup');
58+
foreach ($groupPolicies as $key => $policy)
59+
{
60+
$FeedpolicygroupModel->createPolicy($policy->getGroup(), $feeddao, $policy->getPolicy());
61+
}
62+
$FeedpolicyuserModel = $modelLoad->loadModel('Feedpolicyuser');
63+
foreach ($userPolicies as $key => $policy)
64+
{
65+
$FeedpolicyuserModel->createPolicy($policy->getUser(), $feeddao, $policy->getPolicy());
66+
}
67+
}
68+
}//end copyParentPolicies
69+
3370
/** plus one view*/
3471
function incrementViewCount($itemdao)
3572
{

core/models/pdo/BitstreamModel.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@
77
*/
88
class BitstreamModel extends BitstreamModelBase
99
{
10-
/** do not use, use method addBitstream in ItemRevision Model*/
11-
public function save($dao)
12-
{
13-
$stack=debug_backtrace(false);
14-
if($stack[1]['class']=="ItemRevisionModel"&&$stack[1]['function']=='addBitstream')
15-
{
16-
return parent::save($dao);
17-
}
18-
throw new Zend_Exception(" Do not use, use method addBitstream in ItemRevision Model.");
19-
}//end Save
10+
2011

2112
/** Get bitstream by checksum */
2213
function getByChecksum($checksum)

core/public/js/browse/browse.movecopy.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
$('#selectElements').click(function(){
88
$('#destinationUpload').html($('#selectedDestination').html());
9-
$('#destinationId').html($('#selectedDestinationHidden').val());
9+
$('#destinationId').val($('#selectedDestinationHidden').val());
1010
$( "div.MainDialog" ).dialog('close');
1111
return false;
1212
});
@@ -26,21 +26,7 @@
2626

2727
$('img.infoLoading').show();
2828
$('div.ajaxInfoElement').html('');
29-
if(ajaxSelectRequest!='')
30-
{
31-
ajaxSelectRequest.abort();
32-
}
33-
createAction(node);
34-
ajaxSelectRequest = $.ajax({
35-
type: "POST",
36-
url: json.global.webroot+'/browse/getelementinfo',
37-
data: {type: node.attr('type'), id: node.attr('element')},
38-
success: function(jsonContent){
39-
createInfo(jsonContent);
40-
$('img.infoLoading').hide();
41-
42-
}
43-
});
29+
4430

4531
function callbackDblClick(node)
4632
{

0 commit comments

Comments
 (0)