From ec8b260bf6ce7bb41a5622f2aac325390f0a3c71 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 12 Jan 2013 14:34:16 +0100 Subject: [PATCH] New: Prepare 3.4 branch New: Add hook for agenda, info and category tabs --- dev/initdata/savedemo.sh | 1 + htdocs/categories/categorie.php | 146 ++++++++++-------- htdocs/core/class/hookmanager.class.php | 6 +- htdocs/filefunc.inc.php | 2 +- htdocs/install/check.php | 5 +- .../install/mysql/migration/3.3.0-3.4.0.sql | 17 ++ htdocs/societe/agenda.php | 8 + htdocs/societe/info.php | 23 ++- 8 files changed, 133 insertions(+), 75 deletions(-) create mode 100755 htdocs/install/mysql/migration/3.3.0-3.4.0.sql diff --git a/dev/initdata/savedemo.sh b/dev/initdata/savedemo.sh index 2dd19e55fd4..dc1141f504b 100755 --- a/dev/initdata/savedemo.sh +++ b/dev/initdata/savedemo.sh @@ -188,6 +188,7 @@ export list=" --ignore-table=$base.llx_cabinetmed_examenprescrit --ignore-table=$base.llx_cabinetmed_motifcons --ignore-table=$base.llx_cabinetmed_patient + --ignore-table=$base.llx_cabinetmed_societe --ignore-table=$base.llx_publi_c_contact_list --ignore-table=$base.llx_publi_c_dnd_list --ignore-table=$base.llx_publi_c_method_list diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index 011e500eed4..61351343556 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -85,84 +85,96 @@ if ($id || $ref) if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid); +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager=new HookManager($db); +$hookmanager->initHooks(array('categorycard')); + /* * Actions */ -//Suppression d'un objet d'une categorie -if ($removecat > 0) +$parameters=array('id'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); + +if (empty($reshook)) { - if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer)) + //Suppression d'un objet d'une categorie + if ($removecat > 0) { - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - $object = new Product($db); - $result = $object->fetch($id, $ref); - $elementtype = 'product'; - } - if ($type==1 && $user->rights->societe->creer) - { - $object = new Societe($db); - $result = $object->fetch($objectid); - } - if ($type==2 && $user->rights->societe->creer) - { - $object = new Societe($db); - $result = $object->fetch($objectid); - } - if ($type == 3 && $user->rights->adherent->creer) - { - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - $object = new Adherent($db); - $result = $object->fetch($objectid); - } - $cat = new Categorie($db); - $result=$cat->fetch($removecat); + if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer)) + { + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + $object = new Product($db); + $result = $object->fetch($id, $ref); + $elementtype = 'product'; + } + if ($type==1 && $user->rights->societe->creer) + { + $object = new Societe($db); + $result = $object->fetch($objectid); + } + if ($type==2 && $user->rights->societe->creer) + { + $object = new Societe($db); + $result = $object->fetch($objectid); + } + if ($type == 3 && $user->rights->adherent->creer) + { + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + $object = new Adherent($db); + $result = $object->fetch($objectid); + } + $cat = new Categorie($db); + $result=$cat->fetch($removecat); - $result=$cat->del_type($object,$elementtype); -} + $result=$cat->del_type($object,$elementtype); + } -// Add object into a category -if ($parent > 0) -{ - if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer)) + // Add object into a category + if ($parent > 0) { - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - $object = new Product($db); - $result = $object->fetch($id, $ref); - $elementtype = 'product'; - } - if ($type==1 && $user->rights->societe->creer) - { - $object = new Societe($db); - $result = $object->fetch($objectid); - $elementtype = 'fournisseur'; - } - if ($type==2 && $user->rights->societe->creer) - { - $object = new Societe($db); - $result = $object->fetch($objectid); - $elementtype = 'societe'; - } - if ($type==3 && $user->rights->adherent->creer) - { - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - $object = new Adherent($db); - $result = $object->fetch($objectid); - $elementtype = 'member'; - } - $cat = new Categorie($db); - $result=$cat->fetch($parent); + if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer)) + { + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + $object = new Product($db); + $result = $object->fetch($id, $ref); + $elementtype = 'product'; + } + if ($type==1 && $user->rights->societe->creer) + { + $object = new Societe($db); + $result = $object->fetch($objectid); + $elementtype = 'fournisseur'; + } + if ($type==2 && $user->rights->societe->creer) + { + $object = new Societe($db); + $result = $object->fetch($objectid); + $elementtype = 'societe'; + } + if ($type==3 && $user->rights->adherent->creer) + { + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + $object = new Adherent($db); + $result = $object->fetch($objectid); + $elementtype = 'member'; + } + $cat = new Categorie($db); + $result=$cat->fetch($parent); - $result=$cat->add_type($object,$elementtype); - if ($result >= 0) - { - $mesg='
'.$langs->trans("WasAddedSuccessfully",$cat->label).'
'; - } - else - { - if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') $mesg='
'.$langs->trans("ObjectAlreadyLinkedToCategory").'
'; - else $mesg=$langs->trans("Error").' '.$cat->error; + $result=$cat->add_type($object,$elementtype); + if ($result >= 0) + { + $mesg='
'.$langs->trans("WasAddedSuccessfully",$cat->label).'
'; + } + else + { + if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') $mesg='
'.$langs->trans("ObjectAlreadyLinkedToCategory").'
'; + else $mesg=$langs->trans("Error").' '.$cat->error; + } } } diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 91db5b31419..d18f1fafa0b 100755 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -115,7 +115,7 @@ class HookManager * @param Object &$object Object to use hooks on * @param string &$action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) * @return mixed For doActions,formObjectOptions: Return 0 if we want to keep standard actions, >0 if if want to stop standard actions, <0 means KO. - * For printSearchForm,printLeftBlock,printTopRightMenu,formAddObjectLine,...: Return HTML string. TODO Must always return an int and things to print into ->resprints. + * For printSearchForm,printLeftBlock,printTopRightMenu,formAddObjectLine,...: Return HTML string. TODO Must always return an int and things to print into ->resprints. * Can also return some values into an array ->results. * $this->error or this->errors are also defined by class called by this function if error. */ @@ -136,6 +136,8 @@ class HookManager { foreach($modules as $module => $actionclassinstance) { + //print 'class='.get_class($actionclassinstance).' method='.$method.' action='.$action; + // jump to next class if method does not exists if (! method_exists($actionclassinstance,$method)) continue; // test to avoid to run twice a hook, when a module implements several active contexts @@ -178,7 +180,7 @@ class HookManager } } - if ($method != 'doActions' && $method != 'formObjectOptions') return $this->resPrint; // TODO remove this. When there is something to print, ->resPrint is filled. + if ($method != 'doActions' && $method != 'formObjectOptions') return $this->resPrint; // TODO remove this. When there is something to print, ->resPrint is filled. return ($error?-1:$resaction); } diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 35404140050..739a2372430 100755 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -29,7 +29,7 @@ * \brief File that include conf.php file and commons lib like functions.lib.php */ -if (! defined('DOL_VERSION')) define('DOL_VERSION','3.3.0-beta'); +if (! defined('DOL_VERSION')) define('DOL_VERSION','3.4.0-alpha'); if (! defined('EURO')) define('EURO',chr(128)); // Define syslog constants diff --git a/htdocs/install/check.php b/htdocs/install/check.php index afd2ae450b3..250bbd2b049 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -394,8 +394,9 @@ else array('from'=>'2.9.0', 'to'=>'3.0.0'), array('from'=>'3.0.0', 'to'=>'3.1.0'), array('from'=>'3.1.0', 'to'=>'3.2.0'), - array('from'=>'3.2.0', 'to'=>'3.3.0') - ); + array('from'=>'3.2.0', 'to'=>'3.3.0'), + array('from'=>'3.3.0', 'to'=>'3.4.0') + ); $count=0; foreach ($migrationscript as $migarray) diff --git a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql new file mode 100755 index 00000000000..0943c5aca11 --- /dev/null +++ b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql @@ -0,0 +1,17 @@ +-- +-- Be carefull to requests order. +-- This file must be loaded by calling /install/index.php page +-- when current version is 3.4.0 or higher. +-- +-- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; +-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; +-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); +-- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; +-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); +-- To restrict request to Mysql version x.y use -- VMYSQLx.y +-- To restrict request to Pgsql version x.y use -- VPGSQLx.y + + +-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); +-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); + diff --git a/htdocs/societe/agenda.php b/htdocs/societe/agenda.php index b922db4c50d..a377f5c6e4c 100644 --- a/htdocs/societe/agenda.php +++ b/htdocs/societe/agenda.php @@ -37,11 +37,19 @@ $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe', $socid, '&societe'); +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager=new HookManager($db); +$hookmanager->initHooks(array('agendathirdparty')); + /* * Actions */ +$parameters=array('id'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); diff --git a/htdocs/societe/info.php b/htdocs/societe/info.php index 21d3549ed86..240fdaaf66d 100644 --- a/htdocs/societe/info.php +++ b/htdocs/societe/info.php @@ -37,12 +37,29 @@ $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe', $socid, '&societe'); +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager=new HookManager($db); +$hookmanager->initHooks(array('infothirdparty')); + + + +/* + * Actions + */ + +$parameters=array('id'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); + + /* -* View -*/ + * View + */ -llxHeader(); +$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; +llxHeader('',$langs->trans("ThirdParty"),$help_url); $soc = new Societe($db); $soc->fetch($socid);