Add trigger on commonObject setProject
This commit is contained in:
parent
bb6f73136a
commit
19cedae1c1
@ -2238,8 +2238,11 @@ abstract class CommonObject
|
|||||||
* @param int $projectid Project id to link element to
|
* @param int $projectid Project id to link element to
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function setProject($projectid)
|
public function setProject($projectid, $notrigger = 0)
|
||||||
{
|
{
|
||||||
|
global $user;
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
if (!$this->table_element) {
|
if (!$this->table_element) {
|
||||||
dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined", LOG_ERR);
|
dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined", LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
@ -2270,13 +2273,33 @@ abstract class CommonObject
|
|||||||
$sql .= " WHERE rowid = ".((int) $this->id);
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::setProject", LOG_DEBUG);
|
dol_syslog(get_class($this)."::setProject", LOG_DEBUG);
|
||||||
if ($this->db->query($sql)) {
|
if ($this->db->query($sql)) {
|
||||||
$this->fk_project = ((int) $projectid);
|
$this->fk_project = ((int) $projectid);
|
||||||
return 1;
|
|
||||||
} else {
|
} else {
|
||||||
dol_print_error($this->db);
|
dol_print_error($this->db);
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Triggers
|
||||||
|
if (!$error && !$notrigger) {
|
||||||
|
// Call triggers
|
||||||
|
$result = $this->call_trigger(strtoupper($this->element) . '_MODIFY', $user);
|
||||||
|
if ($result < 0) {
|
||||||
|
$error++;
|
||||||
|
} //Do also here what you must do to rollback action if trigger fail
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit or rollback
|
||||||
|
if ($error) {
|
||||||
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
|
} else {
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user