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

Commit 68e28a3

Browse files
author
Charles Marion
committed
ENH: added revision upload (bug 9586)
1 parent 22c7e15 commit 68e28a3

File tree

11 files changed

+658
-7
lines changed

11 files changed

+658
-7
lines changed

core/controllers/ItemController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class ItemController extends AppController
44
{
55
public $_models=array('Item','ItemRevision','Bitstream');
66
public $_daos=array();
7-
public $_components=array('Date','Utility');
7+
public $_components=array('Date','Utility','Sortdao');
88
public $_forms=array();
99

1010
/** Init Controller */
@@ -24,6 +24,7 @@ function viewAction()
2424
{
2525
$this->view->header=$this->t("Item");
2626
$this->view->Date=$this->Component->Date;
27+
$this->view->Utility=$this->Component->Utility;
2728
$itemId=$this->_getParam("itemId");
2829
if(!isset($itemId)||!is_numeric($itemId))
2930
{
@@ -77,10 +78,15 @@ function viewAction()
7778
$this->Item->incrementViewCount($itemDao);
7879
$itemDao->lastrevision=$itemRevision;
7980
$itemDao->revisions=$itemDao->getRevisions();
81+
82+
$this->Component->Sortdao->field='revision';
83+
$this->Component->Sortdao->order='desc';
84+
usort($itemDao->revisions, array($this->Component->Sortdao,'sortByNumber'));
85+
8086
$itemDao->creation=$this->Component->Date->formatDate(strtotime($itemRevision->getDate()));
8187
$this->view->itemDao=$itemDao;
8288

83-
$this->view->itemSize=$this->Component->Utility->formatSize($itemDao->getSizebytes());;
89+
$this->view->itemSize=$this->Component->Utility->formatSize($itemDao->getSizebytes());
8490

8591
$this->view->json['item']=$itemDao->_toArray();
8692
$this->view->json['item']['message']['delete']=$this->t('Delete');

core/controllers/UploadController.php

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ public function simpleuploadAction()
5656
}
5757
}//end simple upload
5858

59+
/** upload new revision*/
60+
public function revisionAction()
61+
{
62+
if(!$this->logged)
63+
{
64+
throw new Zend_Exception("You have to be logged in to do that");
65+
}
66+
if(!$this->getRequest()->isXmlHttpRequest())
67+
{
68+
throw new Zend_Exception("Error, should be an ajax action.");
69+
}
70+
$this->_helper->layout->disableLayout();
71+
$itemId = $this->_getParam('itemId');
72+
$item = $this->Item->load($itemId);
73+
74+
if($item==false)
75+
{
76+
throw new Zend_Exception("Unable to load item.");
77+
}
78+
if(!$this->Item->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_WRITE))
79+
{
80+
throw new Zend_Exception("Error policies.");
81+
}
82+
$this->view->item=$item;
83+
$itemRevision=$this->Item->getLastRevision($item);;
84+
$this->view->lastrevision=$itemRevision;
85+
}//end revisionAction
86+
5987

6088
/** save a link*/
6189
public function savelinkAction()
@@ -167,8 +195,17 @@ public function saveuploadedAction()
167195
$license=$this->_getParam("license");
168196
if (!empty($path)&& file_exists($path) && $upload->getFileSize() > 0)
169197
{
170-
$item=$this->createUploadedItem($this->userSession->Dao,$upload->getFilename(null,false),$upload->getFilename(),$parent,$license);
171-
$this->userSession->uploaded[]=$item->getKey();
198+
$tmp=explode('-', $parent);
199+
if(count($tmp)==2) //means we upload a new revision
200+
{
201+
$changes=$this->_getParam("changes");
202+
$this->createNewRevision($this->userSession->Dao,$upload->getFilename(null,false),$upload->getFilename(),$tmp,$license,$changes);
203+
}
204+
else
205+
{
206+
$item=$this->createUploadedItem($this->userSession->Dao,$upload->getFilename(null,false),$upload->getFilename(),$parent,$license);
207+
$this->userSession->uploaded[]=$item->getKey();
208+
}
172209

173210
$info= array();
174211
$info['name']= basename($upload->getFileName());
@@ -177,6 +214,98 @@ public function saveuploadedAction()
177214
}
178215
}//end saveuploaded
179216

217+
/** save upload item in the DB */
218+
private function createNewRevision($userDao,$name,$path,$item_revision,$license=null,$changes)
219+
{
220+
if($userDao==null)
221+
{
222+
throw new Zend_Exception('Please log in');
223+
}
224+
225+
$item = $this->Item->load($item_revision[0]);
226+
227+
if($item==false)
228+
{
229+
throw new Zend_Exception('Unable to find item');
230+
}
231+
232+
$revisions = $item->getRevisions();
233+
$itemRevisionDao=null;
234+
foreach($revisions as $revision)
235+
{
236+
if($item_revision[1]==$revision->getRevision())
237+
{
238+
$itemRevisionDao=$revision;
239+
break;
240+
}
241+
}
242+
243+
if(!$this->Item->policyCheck($item, $userDao, MIDAS_POLICY_WRITE))
244+
{
245+
throw new Zend_Exception('Parent permissions errors');
246+
}
247+
248+
249+
if($itemRevisionDao==null)
250+
{
251+
$itemRevisionDao = new ItemRevisionDao;
252+
$itemRevisionDao->setChanges($changes);
253+
$itemRevisionDao->setUser_id($userDao->getKey());
254+
$itemRevisionDao->setDate(date('c'));
255+
$itemRevisionDao->setLicense($license);
256+
$this->Item->addRevision($item,$itemRevisionDao);
257+
258+
$feed=$this->Feed->createFeed($userDao,MIDAS_FEED_CREATE_REVISION,$itemRevisionDao);
259+
260+
$groupPolicies=$item->getItempolicygroup();
261+
$userPolicies=$item->getItempolicyuser();
262+
263+
//copy policies
264+
if($feed!=null &&$feed instanceof FeedDao)
265+
{
266+
foreach ($groupPolicies as $key => $policy)
267+
{
268+
$this->Feedpolicygroup->createPolicy($policy->getGroup(), $feed, $policy->getPolicy());
269+
}
270+
foreach ($userPolicies as $key => $policy)
271+
{
272+
$this->Feedpolicyuser->createPolicy($policy->getUser(), $feed, $policy->getPolicy());
273+
}
274+
}
275+
}
276+
else
277+
{
278+
$itemRevisionDao->setChanges($changes);
279+
$itemRevisionDao->setLicense($license);
280+
$this->ItemRevision->save($itemRevisionDao);
281+
}
282+
283+
284+
// Add bitstreams to the revision
285+
$bitstreamDao = new BitstreamDao;
286+
$bitstreamDao->setName($name);
287+
$bitstreamDao->setPath($path);
288+
$bitstreamDao->fillPropertiesFromPath();
289+
290+
$defaultAssetStoreId=Zend_Registry::get('configGlobal')->defaultassetstore->id;
291+
$bitstreamDao->setAssetstoreId($defaultAssetStoreId);
292+
$assetstoreDao=$this->Assetstore->load($defaultAssetStoreId);
293+
294+
// Upload the bitstream if necessary (based on the assetstore type)
295+
$this->Component->Upload->uploadBitstream($bitstreamDao,$assetstoreDao);
296+
$checksum=$bitstreamDao->getChecksum();
297+
$tmpBitstreamDao=$this->Bitstream->getByChecksum($checksum);
298+
if($tmpBitstreamDao!=false)
299+
{
300+
$bitstreamDao->setPath($tmpBitstreamDao->getPath());
301+
$bitstreamDao->setAssetstoreId($tmpBitstreamDao->getAssetstoreId());
302+
}
303+
$this->ItemRevision->addBitstream($itemRevisionDao,$bitstreamDao);
304+
305+
$this->getLogger()->info(__METHOD__." Upload ok :".$path);
306+
return $item;
307+
}//end createUploadedItem
308+
180309
/** save upload item in the DB */
181310
private function createUploadedItem($userDao,$name,$path,$parent=null,$license=null)
182311
{

core/models/base/ItemModelBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct()
2929
abstract function getOwnedByUser($userDao,$limit=20);
3030
abstract function getSharedToUser($userDao,$limit=20);
3131
abstract function getSharedToCommunity($communityDao,$limit=20);
32+
abstract function policyCheck($itemdao,$userDao=null,$policy=0);
3233

3334
/** copy parent folder policies*/
3435
function copyParentPolicies($itemdao,$folderdao,$feeddao=null)
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
div.ui-tabs {
2+
position: relative!important;
3+
left: 11px!important;
4+
}
5+
6+
.cluetip-jtip #cluetip-inner {
7+
width:94%!important;
8+
}
9+
10+
11+
#swfuploadContent{
12+
13+
}
14+
#jqueryFileUploadContent{
15+
16+
}
17+
18+
/* -- Form Styles ------------------------------- */
19+
#swfuploadContent form {
20+
margin: 0;
21+
padding: 0;
22+
}
23+
24+
25+
26+
#swfuploadContent div.fieldset {
27+
border: 1px solid #afe14c;
28+
}
29+
#swfuploadContent div.fieldset span.legend {
30+
position: relative;
31+
background-color: #FFF;
32+
padding: 3px;
33+
top: -30px;
34+
font: 700 14px Arial, Helvetica, sans-serif;
35+
color: #73b304;
36+
}
37+
38+
#swfuploadContent div.flash {
39+
width: 375px;
40+
margin: 10px 0px;
41+
border-color: #D9E4FF;
42+
overflow: auto;
43+
height: 90px;
44+
45+
-moz-border-radius-topleft : 5px;
46+
-webkit-border-top-left-radius : 5px;
47+
-moz-border-radius-topright : 5px;
48+
-webkit-border-top-right-radius : 5px;
49+
-moz-border-radius-bottomleft : 5px;
50+
-webkit-border-bottom-left-radius : 5px;
51+
-moz-border-radius-bottomright : 5px;
52+
-webkit-border-bottom-right-radius : 5px;
53+
54+
}
55+
56+
#swfuploadContent div.reviewUploaded{
57+
display:none;
58+
}
59+
60+
#swfuploadContentdiv#divStatus{
61+
float:right;
62+
}
63+
64+
#swfuploadContent button,
65+
#swfuploadContent input,
66+
#swfuploadContent select,
67+
#swfuploadContent textarea {
68+
border-width: 1px;
69+
margin-bottom: 10px;
70+
padding: 2px 3px;
71+
}
72+
73+
74+
75+
#swfuploadContent input[disabled]{ border: 1px solid #ccc } /* FF 2 Fix */
76+
77+
78+
#swfuploadContent label {
79+
width: 150px;
80+
text-align: right;
81+
display:block;
82+
margin-right: 5px;
83+
}
84+
85+
#btnSubmit { margin: 0 0 0 155px ; }
86+
87+
/* -- Table Styles ------------------------------- */
88+
#swfuploadContent td {
89+
font: 10pt Helvetica, Arial, sans-serif;
90+
vertical-align: top;
91+
}
92+
93+
#swfuploadContent .progressWrapper {
94+
width: 347px;
95+
overflow: hidden;
96+
}
97+
98+
#swfuploadContent .progressContainer {
99+
margin: 0px;
100+
padding: 0px;
101+
border: solid 1px #E8E8E8;
102+
background-color: #F7F7F7;
103+
overflow: hidden;
104+
}
105+
/* Message */
106+
#swfuploadContent .message {
107+
margin: 1em 0;
108+
padding: 10px 20px;
109+
border: solid 1px #FFDD99;
110+
background-color: #FFFFCC;
111+
overflow: hidden;
112+
}
113+
/* Error */
114+
#swfuploadContent .red {
115+
border: solid 1px #B50000;
116+
background-color: #FFEBEB;
117+
}
118+
119+
/* Current */
120+
#swfuploadContent .green {
121+
border: solid 1px #DDF0DD;
122+
background-color: #EBFFEB;
123+
}
124+
125+
/* Complete */
126+
#swfuploadContent .blue {
127+
border: solid 1px #CEE2F2;
128+
background-color: #F0F5FF;
129+
}
130+
131+
#swfuploadContent .progressName {
132+
font-size: 8pt;
133+
font-weight: 700;
134+
color: #555;
135+
width: 323px;
136+
height: 14px;
137+
text-align: left;
138+
white-space: nowrap;
139+
overflow: hidden;
140+
display: inline;
141+
142+
}
143+
144+
#swfuploadContent .progressBarInProgress,
145+
#swfuploadContent .progressBarComplete,
146+
#swfuploadContent .progressBarError {
147+
font-size: 0;
148+
width: 0%;
149+
height: 2px;
150+
background-color: blue;
151+
margin-top: 2px;
152+
}
153+
154+
#swfuploadContent .progressBarComplete {
155+
width: 100%;
156+
background-color: green;
157+
visibility: hidden;
158+
}
159+
160+
#swfuploadContent .progressBarError {
161+
width: 100%;
162+
background-color: red;
163+
visibility: hidden;
164+
}
165+
166+
#swfuploadContent .progressBarStatus {
167+
margin-top: 2px;
168+
width: 100px;
169+
font-size: 7pt;
170+
font-family: Arial;
171+
text-align: left;
172+
white-space: nowrap;
173+
display:inline;
174+
margin-left: 5px;
175+
}
176+
177+
a.progressCancel {
178+
font-size: 0;
179+
display: block;
180+
height: 14px;
181+
width: 14px;
182+
background-image: url(../../images/icons/cancelbutton.gif);
183+
background-repeat: no-repeat;
184+
background-position: -14px 0px;
185+
float: right;
186+
}
187+
188+
a.progressCancel:hover {
189+
background-position: 0px 0px;
190+
}
191+
192+
193+
/* -- SWFUpload Object Styles ------------------------------- */
194+
#swfuploadContent .swfupload {
195+
vertical-align: top;
196+
}

0 commit comments

Comments
 (0)