Commit 6538fd89e77997aac608716760dd184ee0f21826

Authored by michael
1 parent 26eec61e

(#2760) check if the unit root folder exists before creating it


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2398 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/foldermanagement/Folder.inc
@@ -397,6 +397,21 @@ class Folder { @@ -397,6 +397,21 @@ class Folder {
397 $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderID . " table = folders"; 397 $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iFolderID . " table = folders";
398 return false; 398 return false;
399 } 399 }
  400 +
  401 + /**
  402 + * Checks if a folder with the same name, description and parent exists in the database already
  403 + */
  404 + function exists() {
  405 + global $default;
  406 + $sql = $default->db;
  407 + $sql->query("SELECT id FROM $default->owl_folders_table WHERE name='" . $this->sName . "' " .
  408 + "AND description = '" . $this->sDescription . "' AND parent_id=$this->iParentID");
  409 + if ($sql->next_record()) {
  410 + return true;
  411 + } else {
  412 + return false;
  413 + }
  414 + }
400 415
401 /** 416 /**
402 * Static function 417 * Static function
lib/unitmanagement/Unit.inc
@@ -78,16 +78,20 @@ class Unit { @@ -78,16 +78,20 @@ class Unit {
78 $this->iId = $sql->insert_id(); 78 $this->iId = $sql->insert_id();
79 // create a new unit root folder 79 // create a new unit root folder
80 // FIXME: lookup the organisation for this unit and use the appropriate folder id for the org root folder 80 // FIXME: lookup the organisation for this unit and use the appropriate folder id for the org root folder
81 - // TODO: check if a folder with this name exists before creating it  
82 $oFolder = new Folder($this->sName, $this->sName . " Unit Root Folder", 1, $_SESSION["userID"], $this->iId); 81 $oFolder = new Folder($this->sName, $this->sName . " Unit Root Folder", 1, $_SESSION["userID"], $this->iId);
83 - if ($oFolder->create()) {  
84 - if (PhysicalFolderManagement::createFolder(Folder::getFolderPath($oFolder->getID()))) {  
85 - return true;  
86 - } else {  
87 - return false;  
88 - } 82 + if (!$oFolder->exists()) {
  83 + if ($oFolder->create()) {
  84 + if (PhysicalFolderManagement::createFolder(Folder::getFolderPath($oFolder->getID()))) {
  85 + return true;
  86 + } else {
  87 + return false;
  88 + }
  89 + } else {
  90 + return false;
  91 + }
89 } else { 92 } else {
90 - return false; 93 + // a unit root folder already exists in the database
  94 + return true;
91 } 95 }
92 } 96 }
93 $_SESSION["errorMessage"] = $lang_err_database; 97 $_SESSION["errorMessage"] = $lang_err_database;