@@ -36,6 +36,7 @@ public function init()
36
36
$ this ->addCallBack ('CALLBACK_CORE_GET_JAVAUPLOAD_EXTRA_HTML ' , 'getExtraHtmlSimple ' );
37
37
$ this ->addCallBack ('CALLBACK_CORE_GET_REVISIONUPLOAD_EXTRA_HTML ' , 'getExtraHtmlRevision ' );
38
38
$ this ->addCallBack ('CALLBACK_CORE_VALIDATE_UPLOAD ' , 'validateUpload ' );
39
+ $ this ->addCallBack ('CALLBACK_CORE_VALIDATE_UPLOAD_REVISION ' , 'validateUploadRevision ' );
39
40
40
41
$ this ->enableWebAPI ($ this ->moduleName );
41
42
}
@@ -175,5 +176,49 @@ public function validateUpload($args)
175
176
}
176
177
return array ('status ' => true );
177
178
}
179
+
180
+ /**
181
+ * Return whether or not the upload is allowed. If uploading the revision
182
+ * will cause the size to surpass the quota, it will be rejected.
183
+ * @param size Size of the uploaded file
184
+ * @param itemId The id of the item being uploaded into
185
+ * @return array('status' => boolean, 'message' => 'error message if status is false')
186
+ */
187
+ public function validateUploadRevision ($ args )
188
+ {
189
+ $ modelLoader = new MIDAS_ModelLoader ();
190
+ $ folderModel = $ modelLoader ->loadModel ('Folder ' );
191
+ $ itemModel = $ modelLoader ->loadModel ('Item ' );
192
+ $ folderQuotaModel = $ modelLoader ->loadModel ('FolderQuota ' , $ this ->moduleName );
193
+
194
+ $ item = $ itemModel ->load ($ args ['itemId ' ]);
195
+ if (!$ item )
196
+ {
197
+ return array ('status ' => false , 'message ' => 'Invalid item id ' );
198
+ }
199
+ $ folders = $ item ->getFolders ();
200
+ if (count ($ folders ) == 0 )
201
+ {
202
+ return array ('status ' => false , 'message ' => 'Cannot upload into an orphaned item ' );
203
+ }
204
+ $ rootFolder = $ folderModel ->getRoot ($ folders [0 ]);
205
+ $ quota = $ folderQuotaModel ->getFolderQuota ($ rootFolder );
206
+ if ($ quota == '' )
207
+ {
208
+ return array ('status ' => true );
209
+ }
210
+
211
+ $ freeSpace = $ quota - $ folderModel ->getSize ($ rootFolder );
212
+ $ uploadSize = $ args ['size ' ];
213
+ if ($ uploadSize > $ freeSpace )
214
+ {
215
+ return array ('status ' => false ,
216
+ 'message ' => 'Upload quota exceeded. Free space: ' .$ freeSpace .
217
+ '. Attempted upload size: ' .$ uploadSize .
218
+ ' into item ' .$ args ['itemId ' ]);
219
+ }
220
+ return array ('status ' => true );
221
+ }
222
+
178
223
} //end class
179
224
?>
0 commit comments