Commit b610cbbefa21d48860c2aa180ba154406d30b263
1 parent
31339a8d
fix for KTS-828: Bulk import doesn't handle existing files/folders gracefully.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5434 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
34 additions
and
7 deletions
lib/foldermanagement/Folder.inc
| @@ -439,15 +439,13 @@ class Folder extends KTEntity { | @@ -439,15 +439,13 @@ class Folder extends KTEntity { | ||
| 439 | * @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"] | 439 | * @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"] |
| 440 | */ | 440 | */ |
| 441 | function folderExistsName($sName, $iParentID) { | 441 | function folderExistsName($sName, $iParentID) { |
| 442 | - global $default, $lang_err_folder_exist; | ||
| 443 | - $sql = $default->db; | ||
| 444 | - $sQuery = "SELECT * FROM " . $default->folders_table . " WHERE name = ? AND parent_id = ?";/*ok*/ | 442 | + $sQuery = "SELECT id FROM " . KTUtil::getTableName('folders') . " WHERE name = ? AND parent_id = ?";/*ok*/ |
| 445 | $aParams = array($sName, $iParentID); | 443 | $aParams = array($sName, $iParentID); |
| 446 | - $sql->query(array($sQuery, $aParams)); | ||
| 447 | - if ($sql->next_record()) { | 444 | + $res = DBUtil::getResultArray(array($sQuery, $aParams)); |
| 445 | + var_dump($res); | ||
| 446 | + if (count($res) != 0) { | ||
| 448 | return true; | 447 | return true; |
| 449 | } | 448 | } |
| 450 | - $_SESSION["errorMessage"] = $lang_err_folder_exist . $sName . " parent_id " . $iParentID; | ||
| 451 | return false; | 449 | return false; |
| 452 | } | 450 | } |
| 453 | 451 |
lib/foldermanagement/folderutil.inc.php
| @@ -60,6 +60,11 @@ class KTFolderUtil { | @@ -60,6 +60,11 @@ class KTFolderUtil { | ||
| 60 | if (PEAR::isError($oFolder)) { | 60 | if (PEAR::isError($oFolder)) { |
| 61 | return $oFolder; | 61 | return $oFolder; |
| 62 | } | 62 | } |
| 63 | + | ||
| 64 | + // check for conflicts first | ||
| 65 | + if (Folder::folderExistsName(KTUtil::getId($oParentfolder), $sFolderName)) { | ||
| 66 | + return PEAR::raiseError(sprintf(_kt('The folder %s already exists.'), $sFolderName)); | ||
| 67 | + } | ||
| 63 | 68 | ||
| 64 | $oTransaction = KTFolderTransaction::createFromArray(array( | 69 | $oTransaction = KTFolderTransaction::createFromArray(array( |
| 65 | 'folderid' => $oFolder->getId(), | 70 | 'folderid' => $oFolder->getId(), |
lib/import/bulkimport.inc.php
| @@ -74,7 +74,20 @@ class KTBulkImportManager { | @@ -74,7 +74,20 @@ class KTBulkImportManager { | ||
| 74 | return $aFolderPaths; | 74 | return $aFolderPaths; |
| 75 | } | 75 | } |
| 76 | foreach ($aFolderPaths as $sFolderPath) { | 76 | foreach ($aFolderPaths as $sFolderPath) { |
| 77 | - $oThisFolder = KTFolderUtil::add($oFolder, basename($sFolderPath), $this->oUser); | 77 | + if (Folder::folderExistsName($sFolderPath, KTUtil::getId($oFolder))) { |
| 78 | + $_SESSION['KTErrorMessage'][] = sprintf(_kt("The folder %s is already present in %s. Adding files into pre-existing folder."), $sFolderPath, $oFolder->getName()); | ||
| 79 | + $aOptions = Folder::getList("parent_id = " . KTUtil::getId($oFolder) . ' AND name = "' . DBUtil::escapeSimple($sFolderPath) . '"'); | ||
| 80 | + if (PEAR::isError($aOptions)) { | ||
| 81 | + return $aOptions; | ||
| 82 | + } | ||
| 83 | + if (count($aOptions) != 1) { | ||
| 84 | + return PEAR::raiseError(sprintf(_kt("Two folders named %s present in %s. Unable to decide which to use..."), $sFolderName, $oFolder->getName())); | ||
| 85 | + } else { | ||
| 86 | + $oThisFolder = $aOptions[0]; | ||
| 87 | + } | ||
| 88 | + } else { | ||
| 89 | + $oThisFolder = KTFolderUtil::add($oFolder, basename($sFolderPath), $this->oUser); | ||
| 90 | + } | ||
| 78 | if (PEAR::isError($oThisFolder)) { | 91 | if (PEAR::isError($oThisFolder)) { |
| 79 | return $oThisFolder; | 92 | return $oThisFolder; |
| 80 | } | 93 | } |
| @@ -90,6 +103,17 @@ class KTBulkImportManager { | @@ -90,6 +103,17 @@ class KTBulkImportManager { | ||
| 90 | if (PEAR::isError($aInfo)) { | 103 | if (PEAR::isError($aInfo)) { |
| 91 | return $aInfo; | 104 | return $aInfo; |
| 92 | } | 105 | } |
| 106 | + // need to check both of these. | ||
| 107 | + if (KTDocumentUtil::nameExists($oFolder, basename($sPath))) { | ||
| 108 | + $_SESSION['KTErrorMessage'][] = sprintf(_kt("The document %s is already present in %s. Ignoring."), basename($sPath), $oFolder->getName()); | ||
| 109 | + $oDocument =& Document::getByNameAndFolder(basename($sPath), KTUtil::getId($oFolder)); | ||
| 110 | + return $oDocument; | ||
| 111 | + } else if (KTDocumentUtil::fileExists($oFolder, basename($sPath))) { | ||
| 112 | + $_SESSION['KTErrorMessage'][] = sprintf(_kt("The document %s is already present in %s. Ignoring."), basename($sPath), $oFolder->getName()); | ||
| 113 | + $oDocument =& Document::getByFilenameAndFolder(basename($sPath), KTUtil::getId($oFolder)); | ||
| 114 | + return $oDocument; | ||
| 115 | + } | ||
| 116 | + // else | ||
| 93 | $aOptions = array( | 117 | $aOptions = array( |
| 94 | // XXX: Multiversion Import | 118 | // XXX: Multiversion Import |
| 95 | 'contents' => $aInfo->aVersions[0], | 119 | 'contents' => $aInfo->aVersions[0], |