13
13
/** Upload Controller */
14
14
class UploadController extends AppController
15
15
{
16
- public $ _models = array ('User ' , 'Item ' , 'ItemRevision ' , 'Folder ' , 'Itempolicyuser ' , "ItemKeyword " , 'Itempolicygroup ' , 'Group ' , 'Feed ' , "Feedpolicygroup " , "Feedpolicyuser " , 'Bitstream ' , 'Assetstore ' );
17
- public $ _daos = array ('User ' , 'Item ' , 'ItemRevision ' , 'Bitstream ' , 'Folder ' , "ItemKeyword " );
16
+ public $ _models = array ('Assetstore ' , ' User ' , 'Item ' , 'ItemRevision ' , 'Folder ' , 'Itempolicyuser ' , "ItemKeyword " , 'Itempolicygroup ' , 'Group ' , 'Feed ' , "Feedpolicygroup " , "Feedpolicyuser " , 'Bitstream ' , 'Assetstore ' );
17
+ public $ _daos = array ('Assetstore ' , ' User ' , 'Item ' , 'ItemRevision ' , 'Bitstream ' , 'Folder ' , "ItemKeyword " );
18
18
public $ _components = array ('Httpupload ' , 'Upload ' );
19
19
public $ _forms = array ('Upload ' );
20
20
@@ -28,11 +28,32 @@ function init()
28
28
$ maxPost = str_replace ("M " , "" , ini_get ('post_max_size ' ));
29
29
if ($ maxFile < $ maxPost )
30
30
{
31
- $ this ->view ->maxSizeFile = $ maxFile ;
31
+ $ this ->view ->maxSizeFile = $ maxFile * 1024 * 1024 ;
32
32
}
33
33
else
34
34
{
35
- $ this ->view ->maxSizeFile = $ maxPost ;
35
+ $ this ->view ->maxSizeFile = $ maxPost * 1024 * 1024 ;
36
+ }
37
+
38
+ if ($ this ->isTestingEnv ())
39
+ {
40
+ $ assetstores = $ this ->Assetstore ->getAll ();
41
+ if (empty ($ assetstores ))
42
+ {
43
+ $ assetstoreDao = new AssetstoreDao ();
44
+ $ assetstoreDao ->setName ('Default ' );
45
+ $ assetstoreDao ->setPath (BASE_PATH .'/data/assetstore ' );
46
+ $ assetstoreDao ->setType (MIDAS_ASSETSTORE_LOCAL );
47
+ $ this ->Assetstore = new AssetstoreModel (); //reset Database adapter
48
+ $ this ->Assetstore ->save ($ assetstoreDao );
49
+ }
50
+ else
51
+ {
52
+ $ assetstoreDao = $ assetstores [0 ];
53
+ }
54
+ $ config = Zend_Registry::get ('configGlobal ' );
55
+ $ config ->defaultassetstore ->id = $ assetstoreDao ->getKey ();
56
+ Zend_Registry::set ('configGlobal ' , $ config );
36
57
}
37
58
}
38
59
@@ -43,11 +64,11 @@ public function simpleuploadAction()
43
64
{
44
65
throw new Zend_Exception ("You have to be logged in to do that " );
45
66
}
46
- if (!$ this ->getRequest ()->isXmlHttpRequest ())
67
+ if (!$ this ->getRequest ()->isXmlHttpRequest ()&& ! $ this -> isTestingEnv () )
47
68
{
48
69
throw new Zend_Exception ("Error, should be an ajax action. " );
49
70
}
50
- $ this ->_helper -> layout -> disableLayout ();
71
+ $ this ->disableLayout ();
51
72
$ this ->view ->form = $ this ->getFormAsArray ($ this ->Form ->Upload ->createUploadLinkForm ());
52
73
$ this ->userSession ->uploaded = array ();
53
74
$ this ->view ->selectedLicense = Zend_Registry::get ('configGlobal ' )->defaultlicense ;
@@ -65,6 +86,7 @@ public function simpleuploadAction()
65
86
$ this ->view ->defaultUploadLocationText = $ parent ->getName ();
66
87
}
67
88
}
89
+
68
90
}//end simple upload
69
91
70
92
/** upload new revision*/
@@ -74,11 +96,11 @@ public function revisionAction()
74
96
{
75
97
throw new Zend_Exception ("You have to be logged in to do that " );
76
98
}
77
- if (!$ this ->getRequest ()->isXmlHttpRequest ())
99
+ if (!$ this ->getRequest ()->isXmlHttpRequest () && ! $ this -> isTestingEnv () )
78
100
{
79
101
throw new Zend_Exception ("Error, should be an ajax action. " );
80
102
}
81
- $ this ->_helper -> layout -> disableLayout ();
103
+ $ this ->disableLayout ();
82
104
$ itemId = $ this ->_getParam ('itemId ' );
83
105
$ item = $ this ->Item ->load ($ itemId );
84
106
@@ -103,13 +125,13 @@ public function savelinkAction()
103
125
{
104
126
throw new Zend_Exception ("You have to be logged in to do that " );
105
127
}
106
- if (!$ this ->getRequest ()->isXmlHttpRequest ())
128
+ if (!$ this ->getRequest ()->isXmlHttpRequest () && ! $ this -> isTestingEnv () )
107
129
{
108
130
throw new Zend_Exception ("Error, should be an ajax action. " );
109
131
}
110
-
111
- $ this ->_helper -> layout -> disableLayout ();
112
- $ this ->_helper -> viewRenderer -> setNoRender ();
132
+
133
+ $ this ->disableLayout ();
134
+ $ this ->disableView ();
113
135
$ parent = $ this ->_getParam ("parent " );
114
136
$ name = $ this ->_getParam ("name " );
115
137
$ url = $ this ->_getParam ("url " );
@@ -136,13 +158,25 @@ public function javauploadAction()
136
158
$ this ->_helper ->layout ->disableLayout ();
137
159
$ this ->view ->protocol = "http " ;
138
160
$ this ->view ->host = empty ($ _SERVER ['HTTP_X_FORWARDED_HOST ' ]) ? $ _SERVER ['HTTP_HOST ' ] : $ _SERVER ['HTTP_X_FORWARDED_HOST ' ];
161
+ $ this ->view ->selectedLicense = Zend_Registry::get ('configGlobal ' )->defaultlicense ;
162
+
163
+ $ parent = $ this ->_getParam ('parent ' );
164
+ $ license = $ this ->_getParam ('license ' );
165
+ if (!empty ($ parent ) && !empty ($ license ))
166
+ {
167
+ $ this ->disableView ();
168
+ $ this ->userSession ->JavaUpload ->parent = $ parent ;
169
+ $ this ->userSession ->JavaUpload ->license = $ license ;
170
+ }
139
171
}//end java upload
140
172
141
173
142
174
/** used to see how much of a file made it to the server during an
143
175
* interrupted upload attempt **/
144
176
function gethttpuploadoffsetAction ()
145
177
{
178
+ $ this ->disableLayout ();
179
+ $ this ->disableView ();
146
180
$ params = $ this ->_getAllParams ();
147
181
$ url = $ this ->view ->url ();
148
182
$ url = substr ($ url , 0 , strrpos ($ url , '/ ' ));
@@ -153,6 +187,8 @@ function gethttpuploadoffsetAction()
153
187
/** java upload function, didn 't check what it does :-) */
154
188
function gethttpuploaduniqueidentifierAction ()
155
189
{
190
+ $ this ->disableLayout ();
191
+ $ this ->disableView ();
156
192
$ params = $ this ->_getAllParams ();
157
193
$ this ->Component ->Httpupload ->get_http_upload_unique_identifier ($ params );
158
194
} //end get_http_upload_unique_identifier
@@ -166,15 +202,31 @@ function processjavauploadAction()
166
202
{
167
203
throw new Zend_Exception ("You have to be logged in to do that " );
168
204
}
169
- $ this ->_helper -> layout -> disableLayout ();
170
- $ this ->_helper -> viewRenderer -> setNoRender ();
205
+ $ this ->disableLayout ();
206
+ $ this ->disableView ();
171
207
172
208
$ TMP_DIR = BASE_PATH .'/tmp/misc/ ' ;
173
209
list ($ filename , $ path , $ length ) = $ this ->Component ->Httpupload ->process_http_upload ($ params );
174
210
175
211
if (!empty ($ path ) && file_exists ($ path ) && $ length > 0 )
176
212
{
177
- $ item = $ this ->Component ->Upload ->createUploadedItem ($ this ->userSession ->Dao , $ filename , $ path );
213
+ if (isset ($ this ->userSession ->JavaUpload ->parent ))
214
+ {
215
+ $ parent = $ this ->userSession ->JavaUpload ->parent ;
216
+ }
217
+ else
218
+ {
219
+ $ parent = null ;
220
+ }
221
+ if (isset ($ this ->userSession ->JavaUpload ->license ))
222
+ {
223
+ $ license = $ this ->userSession ->JavaUpload ->license ;
224
+ }
225
+ else
226
+ {
227
+ $ license = null ;
228
+ }
229
+ $ item = $ this ->Component ->Upload ->createUploadedItem ($ this ->userSession ->Dao , $ filename , $ path , $ parent , $ license );
178
230
$ this ->userSession ->uploaded [] = $ item ->getKey ();
179
231
}
180
232
} //end processjavaupload
@@ -187,30 +239,44 @@ public function saveuploadedAction()
187
239
{
188
240
throw new Zend_Exception ("You have to be logged in to do that " );
189
241
}
190
- $ this ->_helper ->layout ->disableLayout ();
191
- $ this ->_helper ->viewRenderer ->setNoRender ();
192
- $ upload = new Zend_File_Transfer ();
193
- $ upload ->receive ();
194
- $ path = $ upload ->getFileName ();
195
- $ file_size = filesize ($ path );
242
+
243
+ $ this ->disableLayout ();
244
+ $ this ->disableView ();
245
+
246
+ if ($ this ->isTestingEnv ())
247
+ {
248
+ //simulate file upload
249
+ $ path = BASE_PATH .'/tests/testfiles/search.png ' ;
250
+ $ file_size = filesize ($ path );
251
+ $ filename = 'search.png ' ;
252
+ }
253
+ else
254
+ {
255
+ $ upload = new Zend_File_Transfer ();
256
+ $ upload ->receive ();
257
+ $ path = $ upload ->getFileName ();
258
+ $ file_size = filesize ($ path );
259
+ $ filename = $ upload ->getFilename (null , false );
260
+ }
261
+
196
262
$ parent = $ this ->_getParam ("parent " );
197
263
$ license = $ this ->_getParam ("license " );
198
- if (!empty ($ path ) && file_exists ($ path ) && $ upload -> getFileSize () > 0 )
264
+ if (!empty ($ path ) && file_exists ($ path ) && $ file_size > 0 )
199
265
{
200
266
$ tmp = explode ('- ' , $ parent );
201
267
if (count ($ tmp ) == 2 ) //means we upload a new revision
202
268
{
203
269
$ changes = $ this ->_getParam ("changes " );
204
- $ this ->Component ->Upload ->createNewRevision ($ this ->userSession ->Dao , $ upload -> getFilename ( null , false ), $ upload -> getFilename () , $ tmp , $ changes , $ license );
270
+ $ this ->Component ->Upload ->createNewRevision ($ this ->userSession ->Dao , $ filename , $ path , $ tmp , $ changes , $ license );
205
271
}
206
272
else
207
273
{
208
- $ item = $ this ->Component ->Upload ->createUploadedItem ($ this ->userSession ->Dao , $ upload -> getFilename ( null , false ), $ upload -> getFilename () , $ parent , $ license );
274
+ $ item = $ this ->Component ->Upload ->createUploadedItem ($ this ->userSession ->Dao , $ filename , $ path , $ parent , $ license );
209
275
$ this ->userSession ->uploaded [] = $ item ->getKey ();
210
276
}
211
277
212
278
$ info = array ();
213
- $ info ['name ' ] = basename ($ upload -> getFileName () );
279
+ $ info ['name ' ] = basename ($ path );
214
280
$ info ['size ' ] = $ file_size ;
215
281
echo json_encode ($ info );
216
282
}
0 commit comments