From 6538fd89e77997aac608716760dd184ee0f21826 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 21 Jul 2003 11:10:17 +0000 Subject: [PATCH] (#2760) check if the unit root folder exists before creating it --- lib/foldermanagement/Folder.inc | 15 +++++++++++++++ lib/unitmanagement/Unit.inc | 20 ++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/foldermanagement/Folder.inc b/lib/foldermanagement/Folder.inc index b01ca3a..a4132d0 100644 --- a/lib/foldermanagement/Folder.inc +++ b/lib/foldermanagement/Folder.inc @@ -397,6 +397,21 @@ class Folder { $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderID . " table = folders"; return false; } + + /** + * Checks if a folder with the same name, description and parent exists in the database already + */ + function exists() { + global $default; + $sql = $default->db; + $sql->query("SELECT id FROM $default->owl_folders_table WHERE name='" . $this->sName . "' " . + "AND description = '" . $this->sDescription . "' AND parent_id=$this->iParentID"); + if ($sql->next_record()) { + return true; + } else { + return false; + } + } /** * Static function diff --git a/lib/unitmanagement/Unit.inc b/lib/unitmanagement/Unit.inc index a9ccd7d..5dac7fd 100644 --- a/lib/unitmanagement/Unit.inc +++ b/lib/unitmanagement/Unit.inc @@ -78,16 +78,20 @@ class Unit { $this->iId = $sql->insert_id(); // create a new unit root folder // FIXME: lookup the organisation for this unit and use the appropriate folder id for the org root folder - // TODO: check if a folder with this name exists before creating it $oFolder = new Folder($this->sName, $this->sName . " Unit Root Folder", 1, $_SESSION["userID"], $this->iId); - if ($oFolder->create()) { - if (PhysicalFolderManagement::createFolder(Folder::getFolderPath($oFolder->getID()))) { - return true; - } else { - return false; - } + if (!$oFolder->exists()) { + if ($oFolder->create()) { + if (PhysicalFolderManagement::createFolder(Folder::getFolderPath($oFolder->getID()))) { + return true; + } else { + return false; + } + } else { + return false; + } } else { - return false; + // a unit root folder already exists in the database + return true; } } $_SESSION["errorMessage"] = $lang_err_database; -- libgit2 0.21.4