Commit 940036dc9475964b5c634a175dbf1ae4e40899f9
1 parent
067a18a9
remove swathes of deprecated code (grep shows no callers) and sql->query gumpf.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5506 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
24 additions
and
71 deletions
lib/foldermanagement/Folder.inc
| @@ -248,42 +248,18 @@ class Folder extends KTEntity { | @@ -248,42 +248,18 @@ class Folder extends KTEntity { | ||
| 248 | return true; | 248 | return true; |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | - /** | ||
| 252 | - * Get a folder's sub-folders | ||
| 253 | - * | ||
| 254 | - * @param int primary key of folder to get children for | ||
| 255 | - * | ||
| 256 | - * @return Array array of child ids | ||
| 257 | - */ | ||
| 258 | - function getChildren($iFolderID, & $aChildren) { | ||
| 259 | - global $default; | ||
| 260 | - $sql = $default->db; | ||
| 261 | - $sql->query(array("SELECT id from $default->folders_table WHERE parent_id = ?", $iFolderID));/*ok*/ | ||
| 262 | - while ($sql->next_record()) { | ||
| 263 | - $aChildren[count($aChildren)] = $sql->f("id"); | ||
| 264 | - Folder::getChildren($sql->f("id"), $aChildren); | ||
| 265 | - } | ||
| 266 | - return $aChildren; | ||
| 267 | - /* | ||
| 268 | - $oFolder = Folder::get($iFolderID); | ||
| 269 | - $path = $oFolder->getParentFolderIds() . ',' . $oFolder->getId(); | ||
| 270 | - return Folder::getList(array( | ||
| 271 | - sprintf('(parent_folder_ids = "%s" OR parent_folder_ids LIKE "%s,%%")', $path, $path), | ||
| 272 | - )); | ||
| 273 | - */ | ||
| 274 | - } | ||
| 275 | - | ||
| 276 | /** | 251 | /** |
| 277 | * Returns the documents in this folder | 252 | * Returns the documents in this folder |
| 278 | */ | 253 | */ |
| 279 | function getDocumentIDs($iFolderID) { | 254 | function getDocumentIDs($iFolderID) { |
| 280 | - global $default; | ||
| 281 | - $sql = $default->db; | ||
| 282 | - $sql->query(array("SELECT id from $default->documents_table WHERE folder_id = ?", $iFolderID));/*ok*/ | ||
| 283 | - while ($sql->next_record()) { | ||
| 284 | - $sChildString .= $sql->f("id") . ","; | 255 | + // FIXME appears to be deprecated. |
| 256 | + $sTable = KTUtil::getTableName('documents'); | ||
| 257 | + $aQuery = array('SELECT id FROM $sTable WHERE folder_id = ?', array($iFolderId)); | ||
| 258 | + $res = DBUtil::getResultArrayKey($aQuery,'id'); | ||
| 259 | + if (PEAR::isError($res)) { | ||
| 260 | + return ''; // return $res; | ||
| 285 | } | 261 | } |
| 286 | - return substr($sChildString,0, strlen($sChildString)-1); | 262 | + return implode(',', $res); |
| 287 | } | 263 | } |
| 288 | 264 | ||
| 289 | function &get($iFolderID) { | 265 | function &get($iFolderID) { |
| @@ -294,16 +270,14 @@ class Folder extends KTEntity { | @@ -294,16 +270,14 @@ class Folder extends KTEntity { | ||
| 294 | * Checks if a folder with the same name and parent exists in the database already | 270 | * Checks if a folder with the same name and parent exists in the database already |
| 295 | */ | 271 | */ |
| 296 | function exists() { | 272 | function exists() { |
| 297 | - global $default; | ||
| 298 | - $sql = $default->db; | ||
| 299 | - $sQuery = "SELECT id FROM $default->folders_table WHERE name = ? AND parent_id = ?";/*ok*/ | 273 | + $sTable = KTUtil::getTableName('folders'); |
| 274 | + $sQuery = "SELECT count(*) as folder_count FROM $sTable WHERE name = ? AND parent_id = ?";/*ok*/ | ||
| 300 | $aParams = array($this->sName, $this->iParentID); | 275 | $aParams = array($this->sName, $this->iParentID); |
| 301 | - $sql->query(array($sQuery, $aParams)); | ||
| 302 | - if ($sql->next_record()) { | ||
| 303 | - return true; | ||
| 304 | - } else { | ||
| 305 | - return false; | ||
| 306 | - } | 276 | + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'folder_count'); |
| 277 | + if (PEAR::isError($res)) { | ||
| 278 | + return false; // return $res | ||
| 279 | + } | ||
| 280 | + return ($res != 0); // handle pre-existing duplicates gracefully. | ||
| 307 | } | 281 | } |
| 308 | 282 | ||
| 309 | /** | 283 | /** |
| @@ -457,14 +431,12 @@ class Folder extends KTEntity { | @@ -457,14 +431,12 @@ class Folder extends KTEntity { | ||
| 457 | * @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"] | 431 | * @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"] |
| 458 | */ | 432 | */ |
| 459 | function folderExistsID($iFolderID) { | 433 | function folderExistsID($iFolderID) { |
| 460 | - global $default, $lang_err_folder_exist; | ||
| 461 | - $sql = $default->db; | ||
| 462 | - $sql->query(array("SELECT * FROM " . $default->folders_table . " WHERE id = ?", $iFolderID));/*ok*/ | ||
| 463 | - if ($sql->next_record()) { | ||
| 464 | - return true; | 434 | + $oFolder = Folder::get($iFolderID); |
| 435 | + if (PEAR::isError($oFolder)) { | ||
| 436 | + return false; // no such folder, or bad ID | ||
| 437 | + } else { | ||
| 438 | + return true; | ||
| 465 | } | 439 | } |
| 466 | - $_SESSION["errorMessage"] =$lang_err_folder_exist . "id " . $iFolderID; | ||
| 467 | - return false; | ||
| 468 | } | 440 | } |
| 469 | 441 | ||
| 470 | /** | 442 | /** |
| @@ -475,33 +447,14 @@ class Folder extends KTEntity { | @@ -475,33 +447,14 @@ class Folder extends KTEntity { | ||
| 475 | * @return String name on success, false otherwise and set $_SESSION["errorMessage"] | 447 | * @return String name on success, false otherwise and set $_SESSION["errorMessage"] |
| 476 | */ | 448 | */ |
| 477 | function getFolderName($iFolderID) { | 449 | function getFolderName($iFolderID) { |
| 478 | - global $default, $lang_err_database; | ||
| 479 | - $sql = $default->db; | ||
| 480 | - $sql->query(array("SELECT name FROM " . $default->folders_table . " WHERE id = ?", $iFolderID));/*ok*/ | ||
| 481 | - if ($sql->next_record()) { | ||
| 482 | - return $sql->f("name"); | 450 | + $oFolder = Folder::get($iFolderID); |
| 451 | + if (PEAR::isError($oFolder)) { | ||
| 452 | + return false; // return $oFolder; | ||
| 453 | + } else { | ||
| 454 | + return $oFolder->getName(); | ||
| 483 | } | 455 | } |
| 484 | - $_SESSION["errorMessage"] = $lang_err_database; | ||
| 485 | - return false; | ||
| 486 | } | 456 | } |
| 487 | 457 | ||
| 488 | - /** | ||
| 489 | - * Get the folder id using the folder name | ||
| 490 | - * | ||
| 491 | - * @param string the name of the folder to get the ID for | ||
| 492 | - * | ||
| 493 | - * @return int name on success, false otherwise and set $_SESSION["errorMessage"] | ||
| 494 | - */ | ||
| 495 | - function getFolderID($sFolderName) { | ||
| 496 | - global $default, $lang_err_database; | ||
| 497 | - $sql = $default->db; | ||
| 498 | - $sql->query(array("SELECT id FROM " . $default->folders_table . " WHERE name = ?", $sFolderName));/*ok*/ | ||
| 499 | - if ($sql->next_record()) { | ||
| 500 | - return $sql->f("id"); | ||
| 501 | - } | ||
| 502 | - $_SESSION["errorMessage"] = $lang_err_database; | ||
| 503 | - return false; | ||
| 504 | - } | ||
| 505 | 458 | ||
| 506 | function getByParentIDAndLookupID($iParentID, $iLookupID) { | 459 | function getByParentIDAndLookupID($iParentID, $iLookupID) { |
| 507 | return KTEntityUtil::getByDict('Folder', array( | 460 | return KTEntityUtil::getByDict('Folder', array( |