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,31 +8,31 @@ | ||
| 8 | * Document Management Made Simple | 8 | * Document Management Made Simple |
| 9 | * Copyright (C) 2008 KnowledgeTree Inc. | 9 | * Copyright (C) 2008 KnowledgeTree Inc. |
| 10 | * Portions copyright The Jam Warehouse Software (Pty) Limited | 10 | * Portions copyright The Jam Warehouse Software (Pty) Limited |
| 11 | - * | 11 | + * |
| 12 | * This program is free software; you can redistribute it and/or modify it under | 12 | * This program is free software; you can redistribute it and/or modify it under |
| 13 | * the terms of the GNU General Public License version 3 as published by the | 13 | * the terms of the GNU General Public License version 3 as published by the |
| 14 | * Free Software Foundation. | 14 | * Free Software Foundation. |
| 15 | - * | 15 | + * |
| 16 | * This program is distributed in the hope that it will be useful, but WITHOUT | 16 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 18 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 19 | * details. | 19 | * details. |
| 20 | - * | 20 | + * |
| 21 | * You should have received a copy of the GNU General Public License | 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 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 | * California 94120-7775, or email info@knowledgetree.com. | 25 | * California 94120-7775, or email info@knowledgetree.com. |
| 26 | - * | 26 | + * |
| 27 | * The interactive user interfaces in modified source and object code versions | 27 | * The interactive user interfaces in modified source and object code versions |
| 28 | * of this program must display Appropriate Legal Notices, as required under | 28 | * of this program must display Appropriate Legal Notices, as required under |
| 29 | * Section 5 of the GNU General Public License version 3. | 29 | * Section 5 of the GNU General Public License version 3. |
| 30 | - * | 30 | + * |
| 31 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 31 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 32 | * these Appropriate Legal Notices must retain the display of the "Powered by | 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 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 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 | * copyright notice. | 36 | * copyright notice. |
| 37 | * Contributor( s): ______________________________________ | 37 | * Contributor( s): ______________________________________ |
| 38 | */ | 38 | */ |
| @@ -392,6 +392,14 @@ class KTFolderUtil { | @@ -392,6 +392,14 @@ class KTFolderUtil { | ||
| 392 | $oStorage =& KTStorageManagerUtil::getSingleton(); | 392 | $oStorage =& KTStorageManagerUtil::getSingleton(); |
| 393 | $oStorage->removeFolderTree($oStartFolder); | 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 | // documents all cleared. | 403 | // documents all cleared. |
| 396 | $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folders') . ' WHERE id IN (' . DBUtil::paramArray($aFolderIds) . ')'; | 404 | $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folders') . ' WHERE id IN (' . DBUtil::paramArray($aFolderIds) . ')'; |
| 397 | $aParams = $aFolderIds; | 405 | $aParams = $aFolderIds; |
| @@ -402,17 +410,22 @@ class KTFolderUtil { | @@ -402,17 +410,22 @@ class KTFolderUtil { | ||
| 402 | DBUtil::rollback(); | 410 | DBUtil::rollback(); |
| 403 | return PEAR::raiseError(_kt('Failure deleting folders.')); | 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 | // purge caches | 429 | // purge caches |
| 417 | KTEntityUtil::clearAllCaches('Folder'); | 430 | KTEntityUtil::clearAllCaches('Folder'); |
| 418 | 431 | ||
| @@ -584,7 +597,7 @@ class KTFolderUtil { | @@ -584,7 +597,7 @@ class KTFolderUtil { | ||
| 584 | 597 | ||
| 585 | return true; | 598 | return true; |
| 586 | } | 599 | } |
| 587 | - | 600 | + |
| 588 | /** | 601 | /** |
| 589 | * Create a symbolic link in the target folder | 602 | * Create a symbolic link in the target folder |
| 590 | * | 603 | * |
| @@ -634,7 +647,7 @@ class KTFolderUtil { | @@ -634,7 +647,7 @@ class KTFolderUtil { | ||
| 634 | return PEAR::raiseError(_kt('You\'re not authorized to create a shortcut to this folder')); | 647 | return PEAR::raiseError(_kt('You\'re not authorized to create a shortcut to this folder')); |
| 635 | } | 648 | } |
| 636 | } | 649 | } |
| 637 | - | 650 | + |
| 638 | //check if the shortcut doesn't already exists in the target folder | 651 | //check if the shortcut doesn't already exists in the target folder |
| 639 | $aSymlinks = $sourceFolder->getSymbolicLinks(); | 652 | $aSymlinks = $sourceFolder->getSymbolicLinks(); |
| 640 | foreach($aSymlinks as $iSymlink){ | 653 | foreach($aSymlinks as $iSymlink){ |
| @@ -643,7 +656,7 @@ class KTFolderUtil { | @@ -643,7 +656,7 @@ class KTFolderUtil { | ||
| 643 | return PEAR::raiseError(_kt('There already is a shortcut to this folder in the target folder.')); | 656 | return PEAR::raiseError(_kt('There already is a shortcut to this folder in the target folder.')); |
| 644 | } | 657 | } |
| 645 | } | 658 | } |
| 646 | - | 659 | + |
| 647 | //Create the link | 660 | //Create the link |
| 648 | $oSymlink = Folder::createFromArray(array( | 661 | $oSymlink = Folder::createFromArray(array( |
| 649 | 'iParentID' => $targetFolder->getId(), | 662 | 'iParentID' => $targetFolder->getId(), |
| @@ -677,7 +690,7 @@ class KTFolderUtil { | @@ -677,7 +690,7 @@ class KTFolderUtil { | ||
| 677 | } | 690 | } |
| 678 | if (!$folder->isSymbolicLink()) | 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 | if (is_null($user)) | 695 | if (is_null($user)) |
| 683 | { | 696 | { |
| @@ -692,17 +705,17 @@ class KTFolderUtil { | @@ -692,17 +705,17 @@ class KTFolderUtil { | ||
| 692 | $oPerm = KTPermission::getByName('ktcore.permissions.delete'); | 705 | $oPerm = KTPermission::getByName('ktcore.permissions.delete'); |
| 693 | if (!KTBrowseUtil::inAdminMode($user, $folder)) { | 706 | if (!KTBrowseUtil::inAdminMode($user, $folder)) { |
| 694 | if(!KTPermissionUtil::userHasPermissionOnItem($user, $oPerm, $folder)){ | 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 | // we only need to delete the folder entry for the link | 712 | // we only need to delete the folder entry for the link |
| 700 | $sql = "DELETE FROM folders WHERE id=?"; | 713 | $sql = "DELETE FROM folders WHERE id=?"; |
| 701 | DBUtil::runQuery(array($sql, array($folder->getId()))); | 714 | DBUtil::runQuery(array($sql, array($folder->getId()))); |
| 702 | 715 | ||
| 703 | } | 716 | } |
| 704 | - | ||
| 705 | - | 717 | + |
| 718 | + | ||
| 706 | } | 719 | } |
| 707 | 720 | ||
| 708 | ?> | 721 | ?> |