Merge pull request #964 from FHenry/3.4

Revert Class rewrite and ficheinter line trigger
This commit is contained in:
Laurent Destailleur 2013-05-20 07:35:11 -07:00
commit 2321170540
2 changed files with 36 additions and 101 deletions

View File

@ -82,11 +82,9 @@ class Fichinter extends CommonObject
/** /**
* Create an intervention into data base * Create an intervention into data base
* *
* @param User $user Objet user that make creation
* @param int $notrigger Disable all triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function create($user, $notrigger=0) function create()
{ {
global $conf, $user, $langs; global $conf, $user, $langs;
@ -146,7 +144,7 @@ class Fichinter extends CommonObject
$sql.= ", '".$this->db->idate($now)."'"; $sql.= ", '".$this->db->idate($now)."'";
$sql.= ", '".$this->ref."'"; $sql.= ", '".$this->ref."'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", ".$user->id; $sql.= ", ".$this->author;
$sql.= ", ".($this->description?"'".$this->db->escape($this->description)."'":"null"); $sql.= ", ".($this->description?"'".$this->db->escape($this->description)."'":"null");
$sql.= ", '".$this->modelpdf."'"; $sql.= ", '".$this->modelpdf."'";
$sql.= ", ".($this->fk_project ? $this->fk_project : 0); $sql.= ", ".($this->fk_project ? $this->fk_project : 0);
@ -177,16 +175,17 @@ class Fichinter extends CommonObject
if (! $ret) dol_print_error($this->db); if (! $ret) dol_print_error($this->db);
} }
if (! $notrigger)
{ // Appel des triggers
// Appel des triggers 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); $tmpuser=new User($this->db);
$result=$interface->run_triggers('FICHINTER_CREATE',$this,$user,$langs,$conf); $tmpuser->fetch($this->author);
if ($result < 0) { $result=$interface->run_triggers('FICHINTER_CREATE',$this,$tmpuser,$langs,$conf);
$error++; $this->errors=$interface->errors; if ($result < 0) {
} $error++; $this->errors=$interface->errors;
} }
// Fin appel triggers
if (! $error) if (! $error)
{ {
@ -214,11 +213,9 @@ class Fichinter extends CommonObject
/** /**
* Update an intervention * Update an intervention
* *
* @param User $user Objet user that make creation
* @param int $notrigger Disable all triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function update($user, $notrigger=0) function update()
{ {
if (! is_numeric($this->duree)) { if (! is_numeric($this->duree)) {
$this->duree = 0; $this->duree = 0;
@ -240,18 +237,15 @@ class Fichinter extends CommonObject
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
// Appel des triggers
if (! $notrigger) include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
{ $interface=new Interfaces($this->db);
// Appel des triggers $result=$interface->run_triggers('FICHINTER_MODIFY',$this,$user,$langs,$conf);
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; if ($result < 0) {
$interface=new Interfaces($this->db); $error++; $this->errors=$interface->errors;
$result=$interface->run_triggers('FICHINTER_UPDATE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
} }
// Fin appel triggers
$this->db->commit(); $this->db->commit();
return 1; return 1;
@ -526,7 +520,7 @@ class Fichinter extends CommonObject
* @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only * @param int $withpicto 0=_No picto, 1=Includes the picto in the linkn, 2=Picto only
* @return string String with URL * @return string String with URL
*/ */
function getNomUrl($withpicto=0,$option='') function getNomUrl($withpicto=0)
{ {
global $langs; global $langs;
@ -652,7 +646,7 @@ class Fichinter extends CommonObject
* @param User $user Object user who delete * @param User $user Object user who delete
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function delete($user, $notrigger=0) function delete($user)
{ {
global $conf; global $conf;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -719,8 +713,6 @@ class Fichinter extends CommonObject
} }
} }
if (! $notrigger)
{
// Appel des triggers // Appel des triggers
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);
@ -729,7 +721,7 @@ class Fichinter extends CommonObject
$error++; $this->errors=$interface->errors; $error++; $this->errors=$interface->errors;
} }
// Fin appel triggers // Fin appel triggers
}
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
@ -817,14 +809,13 @@ class Fichinter extends CommonObject
/** /**
* Adding a line of intervention into data base * Adding a line of intervention into data base
* *
* @param user $user User that do the action
* @param int $fichinterid Id of intervention * @param int $fichinterid Id of intervention
* @param string $desc Line description * @param string $desc Line description
* @param date $date_intervention Intervention date * @param date $date_intervention Intervention date
* @param int $duration Intervention duration * @param int $duration Intervention duration
* @return int >0 if ok, <0 if ko * @return int >0 if ok, <0 if ko
*/ */
function addline($user,$fichinterid, $desc, $date_intervention, $duration) function addline($fichinterid, $desc, $date_intervention, $duration)
{ {
dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration"); dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration");
@ -840,7 +831,7 @@ class Fichinter extends CommonObject
$line->datei = $date_intervention; $line->datei = $date_intervention;
$line->duration = $duration; $line->duration = $duration;
$result=$line->insert($user); $result=$line->insert();
if ($result > 0) if ($result > 0)
{ {
$this->db->commit(); $this->db->commit();
@ -1007,13 +998,10 @@ class FichinterLigne
/** /**
* Insert the line into database * Insert the line into database
* *
* @param User $user Objet user that make creation
* @param int $notrigger Disable all triggers
* @return int <0 if ko, >0 if ok * @return int <0 if ko, >0 if ok
*/ */
function insert($user, $notrigger=0) function insert()
{ {
global $langs,$conf;
dol_syslog("FichinterLigne::insert rang=".$this->rang); dol_syslog("FichinterLigne::insert rang=".$this->rang);
@ -1057,21 +1045,6 @@ class FichinterLigne
if ($result > 0) if ($result > 0)
{ {
$this->rang=$rangToUse; $this->rang=$rangToUse;
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$resulttrigger=$interface->run_triggers('FICHINTERDET_CREATE',$this,$user,$langs,$conf);
if ($resulttrigger < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
}
if (!$error) {
$this->db->commit(); $this->db->commit();
return $result; return $result;
} }
@ -1094,14 +1067,10 @@ class FichinterLigne
/** /**
* Update intervention into database * Update intervention into database
* *
* @param User $user Objet user that make creation
* @param int $notrigger Disable all triggers
* @return int <0 if ko, >0 if ok * @return int <0 if ko, >0 if ok
*/ */
function update($user,$notrigger=0) function update()
{ {
global $langs,$conf;
$this->db->begin(); $this->db->begin();
// Mise a jour ligne en base // Mise a jour ligne en base
@ -1118,22 +1087,6 @@ class FichinterLigne
{ {
$result=$this->update_total(); $result=$this->update_total();
if ($result > 0) if ($result > 0)
{
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$resulttrigger=$interface->run_triggers('FICHINTERDET_UPDATE',$this,$user,$langs,$conf);
if ($resulttrigger < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
}
if (!$error)
{ {
$this->db->commit(); $this->db->commit();
return $result; return $result;
@ -1210,14 +1163,10 @@ class FichinterLigne
/** /**
* Delete a intervention line * Delete a intervention line
* *
* @param User $user Objet user that make creation
* @param int $notrigger Disable all triggers
* @return int >0 if ok, <0 if ko * @return int >0 if ok, <0 if ko
*/ */
function deleteline($user,$notrigger=0) function deleteline()
{ {
global $langs,$conf;
if ($this->statut == 0) if ($this->statut == 0)
{ {
dol_syslog(get_class($this)."::deleteline lineid=".$this->rowid); dol_syslog(get_class($this)."::deleteline lineid=".$this->rowid);
@ -1233,19 +1182,6 @@ class FichinterLigne
if ($result > 0) if ($result > 0)
{ {
$this->db->commit(); $this->db->commit();
if (! $notrigger)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$resulttrigger=$interface->run_triggers('FICHINTERDET_DELETE',$this,$user,$langs,$conf);
if ($resulttrigger < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
return $result; return $result;
} }
else else

View File

@ -134,6 +134,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
$object->socid = $socid; $object->socid = $socid;
$object->duree = GETPOST('duree','int'); $object->duree = GETPOST('duree','int');
$object->fk_project = GETPOST('projectid','int'); $object->fk_project = GETPOST('projectid','int');
$object->author = $user->id;
$object->description = GETPOST('description'); $object->description = GETPOST('description');
$object->ref = $ref; $object->ref = $ref;
$object->modelpdf = GETPOST('model','alpha'); $object->modelpdf = GETPOST('model','alpha');
@ -174,7 +175,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
$object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
} }
$id = $object->create($user); $id = $object->create();
if ($id > 0) if ($id > 0)
{ {
@ -245,7 +246,6 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
$duration = 3600; $duration = 3600;
$result = $object->addline( $result = $object->addline(
$user,
$id, $id,
$desc, $desc,
$date_intervention, $date_intervention,
@ -276,7 +276,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
} }
else else
{ {
$result = $object->create($user); $result = $object->create();
if ($result > 0) if ($result > 0)
{ {
$id=$result; // Force raffraichissement sur fiche venant d'etre cree $id=$result; // Force raffraichissement sur fiche venant d'etre cree
@ -306,7 +306,7 @@ else if ($action == 'update' && $user->rights->ficheinter->creer)
$object->description = GETPOST('description','alpha'); $object->description = GETPOST('description','alpha');
$object->ref = $ref; $object->ref = $ref;
$result=$object->update($user); $result=$object->update();
if ($result<0) { if ($result<0) {
setEventMessage($object->error,'errors'); setEventMessage($object->error,'errors');
} }
@ -427,7 +427,6 @@ else if ($action == "addline" && $user->rights->ficheinter->creer)
$duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int')); $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int'));
$result=$object->addline( $result=$object->addline(
$user,
$id, $id,
$desc, $desc,
$date_intervention, $date_intervention,
@ -503,7 +502,7 @@ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST(
$objectline->datei = $date_inter; $objectline->datei = $date_inter;
$objectline->desc = $desc; $objectline->desc = $desc;
$objectline->duration = $duration; $objectline->duration = $duration;
$result = $objectline->update($user); $result = $objectline->update();
if ($result < 0) if ($result < 0)
{ {
dol_print_error($db); dol_print_error($db);
@ -537,7 +536,7 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->
dol_print_error($db); dol_print_error($db);
exit; exit;
} }
$result=$objectline->deleteline($user); $result=$objectline->deleteline();
if ($object->fetch($objectline->fk_fichinter) <= 0) if ($object->fetch($objectline->fk_fichinter) <= 0)
{ {