Commit 6c79e19798ad01472d551986c26e3457c3c7a46a
1 parent
2601533d
KTS-4115. Implemented folder recursion so that folders containing documents whic…
…h cannot be moved for any reason are not allowed to be moved by bulk action at the folder level. "CLONE -Immutable documents can still be moved (SUP-1511)" Fixed Committed by: Paul Barrett Reviewed by: Megan Watson
Showing
1 changed file
with
48 additions
and
2 deletions
plugins/ktcore/KTBulkActions.php
| ... | ... | @@ -352,6 +352,52 @@ class KTBulkMoveAction extends KTBulkAction { |
| 352 | 352 | return PEAR::raiseError(_kt('Document cannot be moved')); |
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | + | |
| 356 | + if(is_a($oEntity, 'Folder')) { | |
| 357 | + $aDocuments = array(); | |
| 358 | + $aChildFolders = array(); | |
| 359 | + | |
| 360 | + $oFolder = $oEntity; | |
| 361 | + | |
| 362 | + // Get folder id | |
| 363 | + $sFolderId = $oFolder->getID(); | |
| 364 | + | |
| 365 | + // Get documents in folder | |
| 366 | + $sDocuments = $oFolder->getDocumentIDs($sFolderId); | |
| 367 | + $aDocuments = (!empty($sDocuments)) ? explode(',', $sDocuments) : array(); | |
| 368 | + | |
| 369 | + // Loop through documents and send to this function for checking | |
| 370 | + if(!empty($aDocuments)){ | |
| 371 | + foreach($aDocuments as $sDocID){ | |
| 372 | + $oDocument = Document::get($sDocID); | |
| 373 | + $res = $this->check_entity($oDocument); | |
| 374 | + if (PEAR::isError($res)) | |
| 375 | + { | |
| 376 | + return PEAR::raiseError(_kt('Folder cannot be moved')); | |
| 377 | + } | |
| 378 | + } | |
| 379 | + } | |
| 380 | + | |
| 381 | + // If all documents at the current level may be moved, we can continue | |
| 382 | + // Get any existing subfolders | |
| 383 | + $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR | |
| 384 | + parent_folder_ids LIKE '{$sFolderId},%' OR | |
| 385 | + parent_folder_ids LIKE '%,{$sFolderId},%' OR | |
| 386 | + parent_folder_ids LIKE '%,{$sFolderId}'"; | |
| 387 | + $aChildFolders = $this->oFolder->getList($sWhereClause); | |
| 388 | + | |
| 389 | + // Loop through subfolders and check each in the same way as the parent | |
| 390 | + if(!empty($aChildFolders)){ | |
| 391 | + foreach($aChildFolders as $oChild){ | |
| 392 | + $res = $this->check_entity($oChild); | |
| 393 | + if (PEAR::isError($res)) | |
| 394 | + { | |
| 395 | + return PEAR::raiseError(_kt('Folder cannot be moved')); | |
| 396 | + } | |
| 397 | + } | |
| 398 | + } | |
| 399 | + } | |
| 400 | + | |
| 355 | 401 | return parent::check_entity($oEntity); |
| 356 | 402 | } |
| 357 | 403 | |
| ... | ... | @@ -359,8 +405,8 @@ class KTBulkMoveAction extends KTBulkAction { |
| 359 | 405 | function do_collectinfo() { |
| 360 | 406 | $this->store_lists(); |
| 361 | 407 | $this->get_lists(); |
| 362 | - $oTemplating =& KTTemplating::getSingleton(); | |
| 363 | - $oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_info'); | |
| 408 | + $oTemplating =& KTTemplating::getSingleton(); | |
| 409 | + $oTemplate = $oTemplating->loadTemplate('ktcore/bulk_action_info'); | |
| 364 | 410 | return $oTemplate->render(array('context' => $this, |
| 365 | 411 | 'form' => $this->form_collectinfo())); |
| 366 | 412 | } | ... | ... |