Commit cdd0fd3287c2ee7857ba3dbfcf0d20204fafd2ef
1 parent
ce2ecbe3
KTC-621
"Deleting a folder causes the error: PEAR_Error::getSymbolicLinks()" Fixed. Moved the loop to get the symbolic links above the code to delete the folder. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9467 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
40 additions
and
27 deletions
lib/foldermanagement/folderutil.inc.php
| ... | ... | @@ -8,31 +8,31 @@ |
| 8 | 8 | * Document Management Made Simple |
| 9 | 9 | * Copyright (C) 2008 KnowledgeTree Inc. |
| 10 | 10 | * Portions copyright The Jam Warehouse Software (Pty) Limited |
| 11 | - * | |
| 11 | + * | |
| 12 | 12 | * This program is free software; you can redistribute it and/or modify it under |
| 13 | 13 | * the terms of the GNU General Public License version 3 as published by the |
| 14 | 14 | * Free Software Foundation. |
| 15 | - * | |
| 15 | + * | |
| 16 | 16 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | 18 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 19 | 19 | * details. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You should have received a copy of the GNU General Public License |
| 22 | 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | - * | |
| 24 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | + * | |
| 24 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 25 | 25 | * California 94120-7775, or email info@knowledgetree.com. |
| 26 | - * | |
| 26 | + * | |
| 27 | 27 | * The interactive user interfaces in modified source and object code versions |
| 28 | 28 | * of this program must display Appropriate Legal Notices, as required under |
| 29 | 29 | * Section 5 of the GNU General Public License version 3. |
| 30 | - * | |
| 30 | + * | |
| 31 | 31 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 32 | 32 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 33 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 33 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 34 | 34 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 35 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 35 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 36 | 36 | * copyright notice. |
| 37 | 37 | * Contributor( s): ______________________________________ |
| 38 | 38 | */ |
| ... | ... | @@ -392,6 +392,14 @@ class KTFolderUtil { |
| 392 | 392 | $oStorage =& KTStorageManagerUtil::getSingleton(); |
| 393 | 393 | $oStorage->removeFolderTree($oStartFolder); |
| 394 | 394 | |
| 395 | + // Check for symbolic links to the folder and its sub folders | |
| 396 | + $aSymlinks = array(); | |
| 397 | + foreach($aFolderIds as $iFolder){ | |
| 398 | + $oFolder = Folder::get($iFolder); | |
| 399 | + $aLinks = $oFolder->getSymbolicLinks(); | |
| 400 | + array_merge($aSymlinks, $aLinks); | |
| 401 | + } | |
| 402 | + | |
| 395 | 403 | // documents all cleared. |
| 396 | 404 | $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folders') . ' WHERE id IN (' . DBUtil::paramArray($aFolderIds) . ')'; |
| 397 | 405 | $aParams = $aFolderIds; |
| ... | ... | @@ -402,17 +410,22 @@ class KTFolderUtil { |
| 402 | 410 | DBUtil::rollback(); |
| 403 | 411 | return PEAR::raiseError(_kt('Failure deleting folders.')); |
| 404 | 412 | } |
| 405 | - | |
| 406 | - //delete all folder shortcuts | |
| 407 | - foreach($aFolderIds as $iFolder){ | |
| 408 | - $oFolder = Folder::get($iFolder); | |
| 409 | - $aSymlinks = $oFolder->getSymbolicLinks(); | |
| 410 | - | |
| 411 | - foreach($aSymlinks as $aSymlink){ | |
| 412 | - KTFolderUtil::deleteSymbolicLink($aSymlink['id']); | |
| 413 | - } | |
| 413 | + | |
| 414 | + // now that the folder has been deleted we delete all the shortcuts | |
| 415 | + if(!empty($aSymlinks)){ | |
| 416 | + $links = array(); | |
| 417 | + foreach($aSymlinks as $link){ | |
| 418 | + $links[] = $link['id']; | |
| 419 | + } | |
| 420 | + $linkIds = implode(',', $links); | |
| 421 | + | |
| 422 | + $query = "DELETE FROM folders WHERE id IN ($linkIds)"; | |
| 423 | + } | |
| 424 | + | |
| 425 | + foreach($aSymlinks as $aSymlink){ | |
| 426 | + KTFolderUtil::deleteSymbolicLink($aSymlink['id']); | |
| 414 | 427 | } |
| 415 | - | |
| 428 | + | |
| 416 | 429 | // purge caches |
| 417 | 430 | KTEntityUtil::clearAllCaches('Folder'); |
| 418 | 431 | |
| ... | ... | @@ -584,7 +597,7 @@ class KTFolderUtil { |
| 584 | 597 | |
| 585 | 598 | return true; |
| 586 | 599 | } |
| 587 | - | |
| 600 | + | |
| 588 | 601 | /** |
| 589 | 602 | * Create a symbolic link in the target folder |
| 590 | 603 | * |
| ... | ... | @@ -634,7 +647,7 @@ class KTFolderUtil { |
| 634 | 647 | return PEAR::raiseError(_kt('You\'re not authorized to create a shortcut to this folder')); |
| 635 | 648 | } |
| 636 | 649 | } |
| 637 | - | |
| 650 | + | |
| 638 | 651 | //check if the shortcut doesn't already exists in the target folder |
| 639 | 652 | $aSymlinks = $sourceFolder->getSymbolicLinks(); |
| 640 | 653 | foreach($aSymlinks as $iSymlink){ |
| ... | ... | @@ -643,7 +656,7 @@ class KTFolderUtil { |
| 643 | 656 | return PEAR::raiseError(_kt('There already is a shortcut to this folder in the target folder.')); |
| 644 | 657 | } |
| 645 | 658 | } |
| 646 | - | |
| 659 | + | |
| 647 | 660 | //Create the link |
| 648 | 661 | $oSymlink = Folder::createFromArray(array( |
| 649 | 662 | 'iParentID' => $targetFolder->getId(), |
| ... | ... | @@ -677,7 +690,7 @@ class KTFolderUtil { |
| 677 | 690 | } |
| 678 | 691 | if (!$folder->isSymbolicLink()) |
| 679 | 692 | { |
| 680 | - return PEAR::raiseError(_kt('Focument must be a symbolic link entity')); | |
| 693 | + return PEAR::raiseError(_kt('Folder must be a symbolic link entity')); | |
| 681 | 694 | } |
| 682 | 695 | if (is_null($user)) |
| 683 | 696 | { |
| ... | ... | @@ -692,17 +705,17 @@ class KTFolderUtil { |
| 692 | 705 | $oPerm = KTPermission::getByName('ktcore.permissions.delete'); |
| 693 | 706 | if (!KTBrowseUtil::inAdminMode($user, $folder)) { |
| 694 | 707 | if(!KTPermissionUtil::userHasPermissionOnItem($user, $oPerm, $folder)){ |
| 695 | - return PEAR::raiseError(_kt('You\'re not authorized to create shortcuts')); | |
| 708 | + return PEAR::raiseError(_kt('You\'re not authorized to delete shortcuts')); | |
| 696 | 709 | } |
| 697 | 710 | } |
| 698 | - | |
| 711 | + | |
| 699 | 712 | // we only need to delete the folder entry for the link |
| 700 | 713 | $sql = "DELETE FROM folders WHERE id=?"; |
| 701 | 714 | DBUtil::runQuery(array($sql, array($folder->getId()))); |
| 702 | 715 | |
| 703 | 716 | } |
| 704 | - | |
| 705 | - | |
| 717 | + | |
| 718 | + | |
| 706 | 719 | } |
| 707 | 720 | |
| 708 | 721 | ?> | ... | ... |