diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index cf376520fa7..81bfa2621cb 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3319,6 +3319,48 @@ abstract class CommonObject return 0; } } + + /** + * Delete a link to resource line + * + * @param int $rowid Id of resource line to delete + * @param int $element element name (for trigger) TODO: use $this->element into commonobject class + * @param int $notrigger Disable all triggers + * @return int >0 if OK, <0 if KO + */ + function delete_resource($rowid, $element, $notrigger=0) + { + global $user,$langs,$conf; + + $error=0; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; + $sql.= " WHERE rowid =".$rowid; + + dol_syslog(get_class($this)."::delete_resource sql=".$sql); + if ($this->db->query($sql)) + { + if (! $notrigger) + { + // Call triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers(strtoupper($element).'_DELETE_RESOURCE',$this,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // End call triggers + } + + return 1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::delete_resource error=".$this->error, LOG_ERR); + return -1; + } + } /** diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php index 49491580ce8..6b3f0d6d6ee 100644 --- a/htdocs/resource/class/resource.class.php +++ b/htdocs/resource/class/resource.class.php @@ -371,6 +371,7 @@ class Resource extends CommonObject return -1; } } + /** * Load resource objects into $this->lines *