New: Add trigger ACTION_DELETE and ACTION_MODIFY

Fix: LOG_ERROR must be LOG_ERR
This commit is contained in:
Laurent Destailleur 2011-11-01 13:22:39 +01:00
parent 28d6fc03f9
commit 2996ee7639
6 changed files with 647 additions and 573 deletions

View File

@ -32,6 +32,7 @@ For developers:
- New: Add webservice to get or create a prodcut or service. - New: Add webservice to get or create a prodcut or service.
- New: Log module outputs can be setup with "or" rule (not only "xor"). - New: Log module outputs can be setup with "or" rule (not only "xor").
- New: Add FirePHP output for logging module. - New: Add FirePHP output for logging module.
- New: Add trigger ACTION_DELETE and ACTION_MODIFY
- Qual: Data structure for supplier prices is simpler. - Qual: Data structure for supplier prices is simpler.
- Qual: Removed no more used external libraries. - Qual: Removed no more used external libraries.
- Qual: Cleaned a lot of dead code. - Qual: Cleaned a lot of dead code.

View File

@ -92,7 +92,7 @@ if ($_REQUEST['action'] == 'confirm_purge' && $_REQUEST['confirm'] == 'yes' && $
else else
{ {
$error++; $error++;
dol_syslog($securityevent->error, LOG_ERROR); dol_syslog($securityevent->error, LOG_ERR);
$db->rolback(); $db->rolback();
} }
} }

View File

@ -1,22 +1,22 @@
<?php <?php
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* \file htdocs/comm/action/class/actioncomm.class.php * \file htdocs/comm/action/class/actioncomm.class.php
@ -37,11 +37,10 @@ class ActionComm extends CommonObject
public $table_rowid = 'id'; public $table_rowid = 'id';
protected $ismultientitymanaged = 2; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe protected $ismultientitymanaged = 2; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $id;
var $type_id; var $type_id;
var $type_code; var $type_code;
var $type; var $type;
var $id;
var $label; var $label;
var $datec; // Date creation record (datec) var $datec; // Date creation record (datec)
@ -51,14 +50,14 @@ class ActionComm extends CommonObject
var $datep; // Date action start (datep) var $datep; // Date action start (datep)
var $datef; // Date action end (datep2) var $datef; // Date action end (datep2)
var $durationp = -1; var $durationp = -1; // -1=Unkown duration
//var $date; // Date action realise debut (datea) // deprecated
//var $dateend; // Date action realise fin (datea2) // deprecated
//var $durationa = -1; // Duration // deprecated
var $priority;
var $fulldayevent = 0; // 1=Event on full day var $fulldayevent = 0; // 1=Event on full day
var $punctual = 1; var $punctual = 1; // Milestone
var $location; var $percentage; // Percentage
var $location; // Location
var $priority; // Free text ('' By default)
var $note; // Description
var $usertodo; // Object user that must do action var $usertodo; // Object user that must do action
var $userdone; // Object user that did action var $userdone; // Object user that did action
@ -67,8 +66,6 @@ class ActionComm extends CommonObject
var $contact; // Contact linked tot action (optionnal) var $contact; // Contact linked tot action (optionnal)
var $fk_project; // Id of project (optionnal) var $fk_project; // Id of project (optionnal)
var $note;
var $percentage;
// Properties for links to other objects // Properties for links to other objects
var $fk_element; // Id of record var $fk_element; // Id of record
@ -102,6 +99,7 @@ class ActionComm extends CommonObject
{ {
global $langs,$conf; global $langs,$conf;
$error=0;
$now=dol_now(); $now=dol_now();
// Clean parameters // Clean parameters
@ -158,10 +156,10 @@ class ActionComm extends CommonObject
$sql.= "(datec,"; $sql.= "(datec,";
$sql.= "datep,"; $sql.= "datep,";
$sql.= "datep2,"; $sql.= "datep2,";
$sql.= "datea,"; //$sql.= "datea,";
$sql.= "datea2,"; //$sql.= "datea2,";
$sql.= "durationp,"; $sql.= "durationp,";
$sql.= "durationa,"; //$sql.= "durationa,";
$sql.= "fk_action,"; $sql.= "fk_action,";
$sql.= "fk_soc,"; $sql.= "fk_soc,";
$sql.= "fk_project,"; $sql.= "fk_project,";
@ -178,10 +176,10 @@ class ActionComm extends CommonObject
$sql.= "'".$this->db->idate($now)."',"; $sql.= "'".$this->db->idate($now)."',";
$sql.= (strval($this->datep)!=''?"'".$this->db->idate($this->datep)."'":"null").","; $sql.= (strval($this->datep)!=''?"'".$this->db->idate($this->datep)."'":"null").",";
$sql.= (strval($this->datef)!=''?"'".$this->db->idate($this->datef)."'":"null").","; $sql.= (strval($this->datef)!=''?"'".$this->db->idate($this->datef)."'":"null").",";
$sql.= (strval($this->date)!=''?"'".$this->db->idate($this->date)."'":"null").","; //$sql.= (strval($this->date)!=''?"'".$this->db->idate($this->date)."'":"null").",";
$sql.= (strval($this->dateend)!=''?"'".$this->db->idate($this->dateend)."'":"null").","; //$sql.= (strval($this->dateend)!=''?"'".$this->db->idate($this->dateend)."'":"null").",";
$sql.= ($this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null").","; $sql.= ($this->durationp >= 0 && $this->durationp != ''?"'".$this->durationp."'":"null").",";
$sql.= ($this->durationa >= 0 && $this->durationa != ''?"'".$this->durationa."'":"null").","; //$sql.= ($this->durationa >= 0 && $this->durationa != ''?"'".$this->durationa."'":"null").",";
$sql.= " '".$this->type_id."',"; $sql.= " '".$this->type_id."',";
$sql.= ($this->societe->id>0?" '".$this->societe->id."'":"null").","; $sql.= ($this->societe->id>0?" '".$this->societe->id."'":"null").",";
$sql.= ($this->fk_project>0?" '".$this->fk_project."'":"null").","; $sql.= ($this->fk_project>0?" '".$this->fk_project."'":"null").",";
@ -208,7 +206,9 @@ class ActionComm extends CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('ACTION_CREATE',$this,$user,$langs,$conf); $result=$interface->run_triggers('ACTION_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers // Fin appel triggers
} }
@ -217,15 +217,16 @@ class ActionComm extends CommonObject
} }
else else
{ {
$this->error=$this->db->lasterror().' sql='.$sql;
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::add ".$this->error,LOG_ERR);
return -1; return -1;
} }
} }
/** /**
* Charge l'objet action depuis la base * Load object from database
* *
* @param int $id id de l'action a recuperer * @param int $id id de l'action a recuperer
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
@ -235,6 +236,8 @@ class ActionComm extends CommonObject
global $langs; global $langs;
$sql = "SELECT a.id,"; $sql = "SELECT a.id,";
$sql.= " a.id as ref";
$sql.= " a.ref_ext";
$sql.= " a.datep,"; $sql.= " a.datep,";
$sql.= " a.datep2,"; $sql.= " a.datep2,";
$sql.= " a.datec,"; $sql.= " a.datec,";
@ -265,7 +268,8 @@ class ActionComm extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->id; $this->id = $obj->id;
$this->ref = $obj->id; $this->ref = $obj->ref;
$this->ref_ext = $obj->ref_ext;
$this->type_id = $obj->type_id; $this->type_id = $obj->type_id;
$this->type_code = $obj->type_code; $this->type_code = $obj->type_code;
@ -313,35 +317,71 @@ class ActionComm extends CommonObject
} }
/** /**
* Supprime l'action de la base * Delete event from database
* *
* @param int $notrigger 1 = disable triggers, 0 = enable triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function delete() function delete($notrigger=0)
{ {
global $user,$langs,$conf;
$error=0;
$this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm";
$sql.= " WHERE id=".$this->id; $sql.= " WHERE id=".$this->id;
dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
if (! $notrigger)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ACTION_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
if (! $error)
{
$this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->lasterror()." sql=".$sql; $this->db->rollback();
return -2;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete ".$this->error,LOG_ERR);
return -1; return -1;
} }
} }
/** /**
* Met a jour l'action en base. * Update action into database
* Si percentage = 100, on met a jour date 100% * If percentage = 100, on met a jour date 100%
* *
* @param User $user Object user making change
* @param int $notrigger 1 = disable triggers, 0 = enable triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function update($user) function update($user,$notrigger=0)
{ {
global $langs,$conf;
$error=0;
// Clean parameters // Clean parameters
$this->label=trim($this->label); $this->label=trim($this->label);
$this->note=trim($this->note); $this->note=trim($this->note);
@ -363,6 +403,8 @@ class ActionComm extends CommonObject
return -1; return -1;
} }
$this->db->begin();
//print 'eeea'.$this->datep.'-'.(strval($this->datep) != '').'-'.$this->db->idate($this->datep); //print 'eeea'.$this->datep.'-'.(strval($this->datep) != '').'-'.$this->db->idate($this->datep);
$sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm "; $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
$sql.= " SET percent='".$this->percentage."'"; $sql.= " SET percent='".$this->percentage."'";
@ -386,11 +428,34 @@ class ActionComm extends CommonObject
dol_syslog(get_class($this)."::update sql=".$sql); dol_syslog(get_class($this)."::update sql=".$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
if (! $notrigger)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ACTION_MODIFY',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
if (! $error)
{
$this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->error=$this->db->error(); $this->db->rollback();
dol_syslog(get_class($this)."::update ".join(',',$this->errors),LOG_ERR);
return -2;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR); dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
return -1; return -1;
} }
@ -899,11 +964,19 @@ class ActionComm extends CommonObject
$this->specimen=1; $this->specimen=1;
$this->type_code='AC_OTH'; $this->type_code='AC_OTH';
$this->label='Event Specimen'; $this->label='Label of event Specimen';
$this->note = 'Note'; $this->datec=$now;
$this->location='Location'; $this->datem=$now;
$this->datep=$now; $this->datep=$now;
$this->datef=$now; $this->datef=$now;
$this->author=$user;
$this->usermod=$user;
$this->fulldayevent=0;
$this->punctual=0;
$this->percentage=0;
$this->location='Location';
$this->priority='Priority X';
$this->note = 'Note';
} }
} }

View File

@ -1036,7 +1036,7 @@ class BonPrelevement extends CommonObject
else else
{ {
$this->db->rollback(); $this->db->rollback();
dol_syslog("Error",LOG_ERROR); dol_syslog("Error",LOG_ERR);
} }
return count($factures_prev); return count($factures_prev);

View File

@ -331,7 +331,7 @@ class CMailFile
if (! $dest) if (! $dest)
{ {
$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid"; $this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERROR); dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
} }
else else
{ {
@ -360,7 +360,7 @@ class CMailFile
if (! $res) if (! $res)
{ {
$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Check your server logs and your firewalls setup"; $this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Check your server logs and your firewalls setup";
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERROR); dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
} }
else else
{ {

View File

@ -59,7 +59,7 @@ class Interfaces
// Check parameters // Check parameters
if (! is_object($object) || ! is_object($conf)) // Error if (! is_object($object) || ! is_object($conf)) // Error
{ {
dol_syslog('interface::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_ERROR); dol_syslog('interface::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_ERR);
return -1; return -1;
} }
if (! is_object($user) || ! is_object($langs)) // Warning if (! is_object($user) || ! is_object($langs)) // Warning
@ -154,7 +154,7 @@ class Interfaces
} }
else else
{ {
dol_syslog("Interfaces::run_triggers action=".$action." Failed to instantiate trigger for file '".$file."'",LOG_ERROR); dol_syslog("Interfaces::run_triggers action=".$action." Failed to instantiate trigger for file '".$file."'",LOG_ERR);
} }
} }
} }