Commit 3b3d3ba27f2bc0586e08bea806c50aaded8e8d24

Authored by michael
1 parent ed3beef6

(#2760) fixed delete- refactored group mapping check and called before attempting to delete unit


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2387 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 25 additions and 23 deletions
lib/unitmanagement/Unit.inc
@@ -78,6 +78,7 @@ class Unit { @@ -78,6 +78,7 @@ 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
81 $oFolder = new Folder($this->sName, $this->sName . " Unit Root Folder", 1, $_SESSION["userID"], $this->iId); 82 $oFolder = new Folder($this->sName, $this->sName . " Unit Root Folder", 1, $_SESSION["userID"], $this->iId);
82 if ($oFolder->create()) { 83 if ($oFolder->create()) {
83 if (PhysicalFolderManagement::createFolder(Folder::getFolderPath($oFolder->getID()))) { 84 if (PhysicalFolderManagement::createFolder(Folder::getFolderPath($oFolder->getID()))) {
@@ -130,6 +131,7 @@ class Unit { @@ -130,6 +131,7 @@ class Unit {
130 //reverse the database changes if the physical rename failed 131 //reverse the database changes if the physical rename failed
131 $oFolder->setName($sOldName); 132 $oFolder->setName($sOldName);
132 $oFolder->update(true); 133 $oFolder->update(true);
  134 + // TODO: revert unit name change also
133 return false; 135 return false;
134 } 136 }
135 } 137 }
@@ -152,31 +154,15 @@ class Unit { @@ -152,31 +154,15 @@ class Unit {
152 */ 154 */
153 function delete() { 155 function delete() {
154 global $default, $lang_err_database, $lang_err_object_key; 156 global $default, $lang_err_database, $lang_err_object_key;
  157 +
155 //only delete the object if it exists in the database 158 //only delete the object if it exists in the database
156 -  
157 if ($this->iId >= 0) { 159 if ($this->iId >= 0) {
158 - //check to see if group is linked to a unit  
159 - $sql = $default->db;  
160 - $query = "SELECT unit_id FROM ". $default->owl_groups_units_table ." WHERE unit_id = '" . $this->iId . "'";  
161 - $sql->query($query);  
162 - $rows = $sql->num_rows($sql);  
163 -  
164 -  
165 -  
166 - if ($rows > 0) {  
167 - // duplicate link exists  
168 - $_SESSION["errorMessage"] = "Group::The Group " . $this->sName . " exits!";  
169 - return false;  
170 -  
171 - } else {  
172 - $sql = $default->db;  
173 - $result = $sql->query("DELETE FROM $default->owl_units_table WHERE id = $this->iId");  
174 - if ($result) {  
175 - return true;  
176 - }  
177 - $_SESSION["errorMessage"] = $lang_err_database;  
178 - return false;  
179 - } 160 + $sql = $default->db;
  161 + if ($sql->query("DELETE FROM $default->owl_units_table WHERE id = $this->iId")) {
  162 + return true;
  163 + }
  164 + $_SESSION["errorMessage"] = $lang_err_database;
  165 + return false;
180 } 166 }
181 $_SESSION["errorMessage"] = $lang_err_object_key; 167 $_SESSION["errorMessage"] = $lang_err_object_key;
182 return false; 168 return false;
@@ -207,6 +193,22 @@ class Unit { @@ -207,6 +193,22 @@ class Unit {
207 return false; 193 return false;
208 } 194 }
209 195
  196 + /**
  197 + * Returns true if the unit has groups linked to it
  198 + */
  199 + function hasGroups() {
  200 + global $default;
  201 + // check to see if group is linked to a unit
  202 + $sql = $default->db;
  203 + $query = "SELECT unit_id FROM ". $default->owl_groups_units_table ." WHERE unit_id = " . $this->iId;
  204 + $sql->query($query);
  205 + if ($sql->num_rows($sql) > 0) {
  206 + return true;
  207 + } else {
  208 + return false;
  209 + }
  210 + }
  211 +
210 /** 212 /**
211 * static function 213 * static function
212 * 214 *