@@ -40,6 +40,20 @@ public function simpleuploadAction()
40
40
$ this ->view ->form =$ this ->getFormAsArray ($ this ->Form ->Upload ->createUploadLinkForm ());
41
41
$ this ->userSession ->uploaded =array ();
42
42
$ 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
+ }
43
57
}//end simple upload
44
58
45
59
@@ -149,10 +163,11 @@ public function saveuploadedAction()
149
163
$ upload ->receive ();
150
164
$ path =$ upload ->getFileName ();
151
165
$ file_size =filesize ($ path );
152
- $ privacy =$ this ->_getParam ("privacy " );
166
+ $ parent =$ this ->_getParam ("parent " );
167
+ $ license =$ this ->_getParam ("license " );
153
168
if (!empty ($ path )&& file_exists ($ path ) && $ upload ->getFileSize () > 0 )
154
169
{
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 );
156
171
$ this ->userSession ->uploaded []=$ item ->getKey ();
157
172
158
173
$ info = array ();
@@ -163,8 +178,27 @@ public function saveuploadedAction()
163
178
}//end saveuploaded
164
179
165
180
/** 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 )
167
182
{
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
+
168
202
$ item = new ItemDao ;
169
203
$ item ->setName ($ name );
170
204
$ item ->setDate (date ('c ' ));
@@ -173,25 +207,19 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
173
207
$ item ->setThumbnail ('' );
174
208
$ this ->Item ->save ($ item );
175
209
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 );
189
216
$ this ->Itempolicyuser ->createPolicy ($ userDao ,$ item ,MIDAS_POLICY_ADMIN );
190
217
191
218
$ itemRevisionDao = new ItemRevisionDao ;
192
219
$ itemRevisionDao ->setChanges ('Initial revision ' );
193
220
$ itemRevisionDao ->setUser_id ($ userDao ->getKey ());
194
221
$ itemRevisionDao ->setDate (date ('c ' ));
222
+ $ itemRevisionDao ->setLicense ($ license );
195
223
$ this ->Item ->addRevision ($ item ,$ itemRevisionDao );
196
224
197
225
// Set the keyword for the item
@@ -237,7 +265,7 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
237
265
}
238
266
$ this ->ItemRevision ->addBitstream ($ itemRevisionDao ,$ bitstreamDao );
239
267
240
- $ this ->getLogger ()->info (__METHOD__ ." Upload ok ( " . $ privacy . " ) : " .$ path );
268
+ $ this ->getLogger ()->info (__METHOD__ ." Upload ok : " .$ path );
241
269
return $ item ;
242
270
}//end createUploadedItem
243
271
0 commit comments