Commit 1f371729816eec7dbe784f2343840b7d9ee81ec9
1 parent
7e7d81ac
Added functionality to recurse down folder tree and update child paths
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1097 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
29 additions
and
5 deletions
lib/foldermanagement/Folder.inc
| @@ -257,21 +257,34 @@ class Folder { | @@ -257,21 +257,34 @@ class Folder { | ||
| 257 | * | 257 | * |
| 258 | * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] | 258 | * @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"] |
| 259 | */ | 259 | */ |
| 260 | - function update() { | 260 | + function update($bPathChange) { |
| 261 | global $default, $lang_err_database, $lang_err_object_key; | 261 | global $default, $lang_err_database, $lang_err_object_key; |
| 262 | //can only update the object if it has already been stored | 262 | //can only update the object if it has already been stored |
| 263 | if ($this->iId >= 0) { | 263 | if ($this->iId >= 0) { |
| 264 | $sql = $default->db; | 264 | $sql = $default->db; |
| 265 | - $result = $sql->query("UPDATE " . $default->owl_folders_table . " SET " . | 265 | + $sQuery = "UPDATE " . $default->owl_folders_table . " SET " . |
| 266 | "name = '" . addslashes($this->sName) . "', " . | 266 | "name = '" . addslashes($this->sName) . "', " . |
| 267 | "description = '" . addslashes($this->sDescription) . "', " . | 267 | "description = '" . addslashes($this->sDescription) . "', " . |
| 268 | "parent_id = $this->iParentID, " . | 268 | "parent_id = $this->iParentID, " . |
| 269 | "creator_id = $this->iCreatorID, " . | 269 | "creator_id = $this->iCreatorID, " . |
| 270 | "document_type_id = $this->iDocumentTypeID, " . | 270 | "document_type_id = $this->iDocumentTypeID, " . |
| 271 | - "unit_id = $this->iUnitID, " . | ||
| 272 | - "is_public = " . ($this->bIsPublic ? 1 : 0) . " " . | ||
| 273 | - "WHERE id = " . $this->iId); | 271 | + "unit_id = $this->iUnitID, "; |
| 272 | + if ($bPathChange) { | ||
| 273 | + $sFullPath = $this->generateFullFolderPath($this->iParentID); | ||
| 274 | + $this->sFullPath = substr($sFullPath, 1, strlen($sFullPath)); | ||
| 275 | + $sParentFolderIDs = $this->generateParentFolderIDS($this->iParentID); | ||
| 276 | + $this->sParentFolderIDs = substr($sParentFolderIDs, 1, strlen($sParentFolderIDs)); | ||
| 277 | + $sQuery .= "parent_folder_ids = '" . addslashes($this->sParentFolderIDs) . "'," . | ||
| 278 | + "full_path = '" . addslashes($this->sFullPath) . "', "; | ||
| 279 | + } | ||
| 280 | + $sQuery .= "is_public = " . ($this->bIsPublic ? 1 : 0) . " " . | ||
| 281 | + "WHERE id = " . $this->iId; | ||
| 282 | + $result = $sql->query($sQuery); | ||
| 274 | if ($result) { | 283 | if ($result) { |
| 284 | + if ($bPathChange) { | ||
| 285 | + //must update all the children paths | ||
| 286 | + $this->updateChildrenPaths($this->iId, $sql); | ||
| 287 | + } | ||
| 275 | return true; | 288 | return true; |
| 276 | } | 289 | } |
| 277 | $_SESSION["errorMessage"] = $lang_err_database; | 290 | $_SESSION["errorMessage"] = $lang_err_database; |
| @@ -280,6 +293,17 @@ class Folder { | @@ -280,6 +293,17 @@ class Folder { | ||
| 280 | $_SESSION["errorMessage"] = $lang_err_object_key; | 293 | $_SESSION["errorMessage"] = $lang_err_object_key; |
| 281 | } | 294 | } |
| 282 | 295 | ||
| 296 | + function updateChildrenPaths($iID, $sql) { | ||
| 297 | + global $default; | ||
| 298 | + $sql->query("SELECT id from $default->owl_folders_table WHERE parent_id = $iID"); | ||
| 299 | + while ($sql->next_record()) { | ||
| 300 | + $oFolder = Folder::get($sql->f("id")); | ||
| 301 | + $oFolder->update(true); | ||
| 302 | + $this->updateChildrenPaths($sql->f("id"), $sql); | ||
| 303 | + } | ||
| 304 | + return; | ||
| 305 | + } | ||
| 306 | + | ||
| 283 | 307 | ||
| 284 | /** | 308 | /** |
| 285 | * Delete the current object from the database | 309 | * Delete the current object from the database |