Commit 0528958fd3f93338a39cf7394088debf6e2ea269

Authored by nbm
1 parent 59ab0bad

Update document paths when renaming folders.

Submitted by:	Nicolas Quienot (nquienot)
SF Tracker:	1199699


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3265 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 27 additions and 2 deletions
lib/foldermanagement/Folder.inc
... ... @@ -25,6 +25,7 @@
25 25 * @package lib.foldermanagement
26 26 */
27 27 require_once("$default->fileSystemRoot/lib/foldermanagement/PhysicalFolderManagement.inc");
  28 +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
28 29  
29 30 class Folder extends KTEntity {
30 31  
... ... @@ -314,7 +315,9 @@ class Folder extends KTEntity {
314 315 $res = parent::update();
315 316 if ($res === true) {
316 317 if ($bPathChange) {
317   - $this->updateChildPaths($this->iId, $sql);
  318 + // XXX: TransactionCheckPoint
  319 + $this->updateChildPaths($this->iId);
  320 + $this->updateDocumentPaths($this->iId);
318 321 }
319 322 }
320 323 return $res;
... ... @@ -329,7 +332,7 @@ class Folder extends KTEntity {
329 332 * the paths of the children in the database
330 333 *
331 334 */
332   - function updateChildPaths($iID, $sql) {
  335 + function updateChildPaths($iID) {
333 336 global $default;
334 337 //get the direct children
335 338 $sql = $default->db;
... ... @@ -342,6 +345,28 @@ class Folder extends KTEntity {
342 345 }
343 346 return;
344 347 }
  348 +
  349 + /**
  350 + * When a folder's path changes, we must update the paths in the
  351 + * documents in that folder. Sub-folders are handled elsewhere in
  352 + * update().
  353 + */
  354 +
  355 + function updateDocumentPaths($iID) {
  356 + $aDocuments = Document::getList(array('folder_id = ?', $iID));
  357 + if (PEAR::isError($aDocuments)) {
  358 + return $aDocuments;
  359 + }
  360 + foreach ($aDocuments as $oDocument) {
  361 + // Document->update() automatically adjusts the path.
  362 + $oDocument->update();
  363 + // XXX: Should handle failure here somehow, but rather get
  364 + // most working than just the first two. Must find a sane
  365 + // way to handle transactions.
  366 + // TransactionCheckPoint
  367 + }
  368 + return true;
  369 + }
345 370  
346 371 /**
347 372 * Get a folder's sub-folders
... ...