New: Add trigger CATEGORY_LINK and CATEGORY_UNLINK.

This commit is contained in:
Laurent Destailleur 2013-08-10 02:40:11 +02:00
parent 0621233b9a
commit 8e5537f1ce
3 changed files with 43 additions and 18 deletions

View File

@ -47,7 +47,6 @@ For users:
- New: [ task #918 ] Stock replenishment - New: [ task #918 ] Stock replenishment
- Fix: [ bug #992 ] Proforma invoices don't have a separated numeric count - Fix: [ bug #992 ] Proforma invoices don't have a separated numeric count
For translators: For translators:
- Qual: Normalized sort order of all languages files with english reference files. - Qual: Normalized sort order of all languages files with english reference files.
- New: Add language code files for South Africa. - New: Add language code files for South Africa.
@ -72,6 +71,7 @@ For developers:
separated by a coma, of other POST parameters, Dolibarr will automatically save this parameters separated by a coma, of other POST parameters, Dolibarr will automatically save this parameters
into user cookies. into user cookies.
- New: Add hook addHomeSetup. - New: Add hook addHomeSetup.
- New: Add trigger CATEGORY_LINK and CATEGORY_UNLINK.
WARNING: Following change may create regression for some external modules, but was necessary to make WARNING: Following change may create regression for some external modules, but was necessary to make
Dolibarr better: Dolibarr better:

View File

@ -360,6 +360,7 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
} }
// Rajoute l'utilisateur dans les divers abonnements (mailman, spip, etc...) // Rajoute l'utilisateur dans les divers abonnements (mailman, spip, etc...)
// TODO Move this into update trigger MEMBER_MODIFY
if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid))
{ {
if ($object->oldcopy->email != $object->email) // If email has changed we delete mailman subscription for old email if ($object->oldcopy->email != $object->email) // If email has changed we delete mailman subscription for old email

View File

@ -391,15 +391,15 @@ class Categorie
{ {
global $conf; global $conf;
$error=0;
if ($this->id == -1) return -2; if ($this->id == -1) return -2;
if ($type == 'company') $type='societe'; if ($type == 'company') $type='societe';
if ($type == 'fournisseur') $type='societe'; if ($type == 'fournisseur') $type='societe';
$column_name=$type; $column_name=$type;
if ($type=='contact') { if ($type=='contact') $column_name='socpeople';
$column_name='socpeople';
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".$type." (fk_categorie, fk_".$column_name.")"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".$type." (fk_categorie, fk_".$column_name.")";
$sql .= " VALUES (".$this->id.", ".$obj->id.")"; $sql .= " VALUES (".$this->id.", ".$obj->id.")";
@ -407,7 +407,8 @@ class Categorie
dol_syslog(get_class($this).'::add_type sql='.$sql); dol_syslog(get_class($this).'::add_type sql='.$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
if (!empty($conf->global->CATEGORIE_RECURSIV_ADD)) { if (!empty($conf->global->CATEGORIE_RECURSIV_ADD))
{
$sql = 'SELECT fk_parent FROM '.MAIN_DB_PREFIX.'categorie'; $sql = 'SELECT fk_parent FROM '.MAIN_DB_PREFIX.'categorie';
$sql.= " WHERE rowid = '".$this->id."'"; $sql.= " WHERE rowid = '".$this->id."'";
@ -428,12 +429,23 @@ class Categorie
} }
else else
{ {
$this->error=$this->db->error().' sql='.$sql; $this->error=$this->db->lasterror();
return -1; return -1;
} }
} }
return 1; // Save object we want to link category to into category instance to provide information to trigger
$this->linkto=$object;
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CATEGORY_LINK',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; $this->error=join(',',$this->errors); }
// Fin appel triggers
if (! $error) return 1;
else return -2;
} }
else else
{ {
@ -444,7 +456,7 @@ class Categorie
} }
else else
{ {
$this->error=$this->db->error().' sql='.$sql; $this->error=$this->db->lasterror();
} }
return -1; return -1;
} }
@ -459,6 +471,7 @@ class Categorie
*/ */
function del_type($obj,$type) function del_type($obj,$type)
{ {
$error=0;
if ($type == 'company') $type='societe'; if ($type == 'company') $type='societe';
if ($type == 'fournisseur') $type='societe'; if ($type == 'fournisseur') $type='societe';
@ -473,11 +486,22 @@ class Categorie
dol_syslog(get_class($this).'::del_type sql='.$sql); dol_syslog(get_class($this).'::del_type sql='.$sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
return 1; // Save object we want to unlink category off into category instance to provide information to trigger
$this->unlinkoff=$obj;
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CATEGORY_UNLINK',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; $this->error=join(',',$this->errors); }
// Fin appel triggers
if (! $error) return 1;
else return -2;
} }
else else
{ {
$this->error=$this->db->error().' sql='.$sql; $this->error=$this->db->lasterror();
return -1; return -1;
} }
} }