From 66d5d6905f2dffddb9847b5659d1e0d092e0593c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 10 Aug 2011 19:55:21 +0000 Subject: [PATCH] Fix: works on repair broken features --- htdocs/comm/propal.php | 6 +- htdocs/comm/propal/class/propal.class.php | 34 +++-------- htdocs/commande/class/commande.class.php | 48 +++------------ htdocs/commande/fiche.php | 6 +- htdocs/compta/facture.php | 6 +- htdocs/compta/facture/class/facture.class.php | 60 +++++-------------- htdocs/compta/facture/fiche-rec.php | 10 +--- htdocs/contact/fiche.php | 39 +++--------- htdocs/core/class/html.formfile.class.php | 4 +- ...face_modWorkflow_WorkflowManager.class.php | 18 +++++- 10 files changed, 67 insertions(+), 164 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index b208161d7e0..26cc657d6f0 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -26,7 +26,7 @@ * \file htdocs/comm/propal.php * \ingroup propale * \brief Page of commercial proposals card and list - * \version $Id: propal.php,v 1.618 2011/08/10 18:05:49 hregis Exp $ + * \version $Id: propal.php,v 1.619 2011/08/10 19:55:22 hregis Exp $ */ require("../main.inc.php"); @@ -101,7 +101,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes') } else { - $result=$object->createFromClone($id,0,GETPOST('socid')); + $result=$object->createFromClone($id,0,GETPOST('socid'),$hookmanager); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); @@ -1926,6 +1926,6 @@ else } $db->close(); -llxFooter('$Date: 2011/08/10 18:05:49 $ - $Revision: 1.618 $'); +llxFooter('$Date: 2011/08/10 19:55:22 $ - $Revision: 1.619 $'); ?> diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 3d90dc99837..9f6325841f3 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -29,7 +29,7 @@ * \author Rodolphe Qiedeville * \author Eric Seigne * \author Laurent Destailleur - * \version $Id: propal.class.php,v 1.111 2011/08/08 01:53:26 eldy Exp $ + * \version $Id: propal.class.php,v 1.112 2011/08/10 19:55:22 hregis Exp $ */ require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); @@ -826,7 +826,7 @@ class Propal extends CommonObject * @param socid Id of thirdparty * @return int New id of clone */ - function createFromClone($fromid,$invertdetail=0,$socid=0) + function createFromClone($fromid,$invertdetail=0,$socid=0,$hookmanager=false) { global $user,$langs,$conf; @@ -836,12 +836,6 @@ class Propal extends CommonObject $object=new Propal($this->db); - // Instantiate hooks of thirdparty module - if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) - { - $object->callHooks('propalcard'); - } - $this->db->begin(); // Load source object @@ -906,24 +900,12 @@ class Propal extends CommonObject if (! $error) { - // Hook for external modules - if (! empty($object->hooks)) - { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'createfrom')) - { - $result = $module->createfrom($objFrom,$result,$object->element); - if ($result < 0) $error++; - } - } - } - } - } + // Hook of thirdparty module + if (is_object($hookmanager)) + { + $reshook=$hookmanager->executeHooks('createfrom','',$objFrom,$result,$object->element); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; + } // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index b0a046939f0..c13d1987225 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -24,7 +24,7 @@ * \file htdocs/commande/class/commande.class.php * \ingroup commande * \brief Fichier des classes de commandes - * \version $Id: commande.class.php,v 1.121 2011/08/08 01:10:07 eldy Exp $ + * \version $Id: commande.class.php,v 1.122 2011/08/10 19:55:22 hregis Exp $ */ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); @@ -769,7 +769,7 @@ class Commande extends CommonObject * @param socid Id of thirdparty * @return int New id of clone */ - function createFromClone($fromid,$invertdetail=0,$socid=0) + function createFromClone($fromid,$invertdetail=0,$socid=0,$hookmanager=false) { global $conf,$user,$langs; @@ -777,12 +777,6 @@ class Commande extends CommonObject $object=new Commande($this->db); - // Instantiate hooks of thirdparty module - if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) - { - $object->callHooks('ordercard'); - } - $this->db->begin(); // Load source object @@ -829,22 +823,10 @@ class Commande extends CommonObject if (! $error) { // Hook of thirdparty module - if (! empty($object->hooks)) + if (is_object($hookmanager)) { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'createfrom')) - { - $result = $module->createfrom($objFrom,$result,$object->element); - if ($result < 0) $error++; - } - } - } - } + $reshook=$hookmanager->executeHooks('createfrom','',$objFrom,$result,$object->element); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; } // Appel des triggers @@ -875,7 +857,7 @@ class Commande extends CommonObject * @param invertdetail Reverse sign of amounts for lines * @return int <0 if KO, 0 if nothing done, 1 if OK */ - function createFromProposal($object,$invertdetail=0) + function createFromProposal($object,$invertdetail=0,$hookmanager=false) { global $conf,$user,$langs; @@ -932,22 +914,10 @@ class Commande extends CommonObject if ($ret > 0) { // Hook of thirdparty module - if (! empty($object->hooks)) + if (is_object($hookmanager)) { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'createfrom')) - { - $result = $module->createfrom($object,$ret,$this->element); - if ($result < 0) $error++; - } - } - } - } + $reshook=$hookmanager->executeHooks('createfrom','',$object,$ret,$this->element); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; } if (! $error) diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index cad6b8148ec..a0b897c8a29 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -25,7 +25,7 @@ * \file htdocs/commande/fiche.php * \ingroup commande * \brief Page to show customer order - * \version $Id: fiche.php,v 1.531 2011/08/10 18:04:58 hregis Exp $ + * \version $Id: fiche.php,v 1.532 2011/08/10 19:55:22 hregis Exp $ */ require("../main.inc.php"); @@ -85,7 +85,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes') } else { - $result=$object->createFromClone($id, 0, GETPOST('socid')); + $result=$object->createFromClone($id, 0, GETPOST('socid'), $hookmanager); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); @@ -2063,5 +2063,5 @@ else $db->close(); -llxFooter('$Date: 2011/08/10 18:04:58 $ - $Revision: 1.531 $'); +llxFooter('$Date: 2011/08/10 19:55:22 $ - $Revision: 1.532 $'); ?> diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index f744229f4a8..54e6d2640cc 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -25,7 +25,7 @@ * \file htdocs/compta/facture.php * \ingroup facture * \brief Page to create/see an invoice - * \version $Id: facture.php,v 1.852 2011/08/10 18:04:41 hregis Exp $ + * \version $Id: facture.php,v 1.853 2011/08/10 19:55:21 hregis Exp $ */ require('../main.inc.php'); @@ -95,7 +95,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes') } else { - $result=$object->createFromClone($id); + $result=$object->createFromClone($id,0,$hookmanager); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$result); @@ -3178,5 +3178,5 @@ else $db->close(); -llxFooter('$Date: 2011/08/10 18:04:41 $ - $Revision: 1.852 $'); +llxFooter('$Date: 2011/08/10 19:55:21 $ - $Revision: 1.853 $'); ?> diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index d0242e9a77c..256f0f170f0 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -27,7 +27,7 @@ * \file htdocs/compta/facture/class/facture.class.php * \ingroup facture * \brief Fichier de la classe des factures clients - * \version $Id: facture.class.php,v 1.124 2011/08/03 00:46:25 eldy Exp $ + * \version $Id: facture.class.php,v 1.125 2011/08/10 19:55:21 hregis Exp $ */ require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); @@ -518,7 +518,7 @@ class Facture extends CommonObject * @param invertdetail Reverse sign of amounts for lines * @return int New id of clone */ - function createFromClone($fromid,$invertdetail=0) + function createFromClone($fromid,$invertdetail=0,$hookmanager=false) { global $conf,$user,$langs; @@ -532,12 +532,6 @@ class Facture extends CommonObject $object=new Facture($this->db); $object->fetch($fromid); - // Instantiate hooks of thirdparty module - if (is_array($conf->hooks_modules) && ! empty($conf->hooks_modules)) - { - $object->callHooks('invoicecard'); - } - $this->db->begin(); $object->id=0; @@ -576,24 +570,12 @@ class Facture extends CommonObject if (! $error) { - // Hook for external modules - if (! empty($object->hooks)) - { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'createfrom')) - { - $result = $module->createfrom($objFrom,$result,$object->element); - if ($result < 0) $error++; - } - } - } - } - } + // Hook of thirdparty module + if (is_object($hookmanager)) + { + $reshook=$hookmanager->executeHooks('createfrom','',$objFrom,$result,$object->element); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; + } // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); @@ -621,7 +603,7 @@ class Facture extends CommonObject * @param object Object source * @return int <0 if KO, 0 if nothing done, 1 if OK */ - function createFromOrder($object) + function createFromOrder($object, $hookmanager=false) { global $conf,$user,$langs; @@ -675,24 +657,12 @@ class Facture extends CommonObject if ($ret > 0) { - // Hook for external modules - if (! empty($object->hooks)) - { - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'createfrom')) - { - $result = $module->createfrom($objFrom,$result,$object->element); - if ($result < 0) $error++; - } - } - } - } - } + // Hook of thirdparty module + if (is_object($hookmanager)) + { + $reshook=$hookmanager->executeHooks('createfrom','',$objFrom,$result,$object->element); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; + } if (! $error) { diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 0e188af4810..57115e2d6a8 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -21,7 +21,7 @@ * \file htdocs/compta/facture/fiche-rec.php * \ingroup facture * \brief Page to show predefined invoice - * \version $Id: fiche-rec.php,v 1.75 2011/07/31 22:23:13 eldy Exp $ + * \version $Id: fiche-rec.php,v 1.76 2011/08/10 19:55:22 hregis Exp $ */ require("../../main.inc.php"); @@ -109,12 +109,6 @@ if ($_GET["action"] == 'create') $facture = new Facture($db); // Source invoice $product_static=new Product($db); - // Instantiate hooks of thirdparty module - if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) - { - $facture->callHooks('invoicecard'); - } - if ($facture->fetch($_GET["facid"]) > 0) { print '
'; @@ -575,5 +569,5 @@ else $db->close(); -llxFooter('$Date: 2011/07/31 22:23:13 $ - $Revision: 1.75 $'); +llxFooter('$Date: 2011/08/10 19:55:22 $ - $Revision: 1.76 $'); ?> diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 82e537ddbe7..8a09fe31430 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -23,7 +23,7 @@ * \file htdocs/contact/fiche.php * \ingroup societe * \brief Card of a contact - * \version $Id: fiche.php,v 1.222 2011/07/31 23:54:12 eldy Exp $ + * \version $Id: fiche.php,v 1.223 2011/08/10 19:55:22 hregis Exp $ */ require("../main.inc.php"); @@ -67,43 +67,18 @@ else $result = restrictedArea($user, 'contact', $id, 'socpeople'); // If we create a contact with no company (shared contacts), no check on write permission } -// Instantiate hooks of thirdparty module -if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) -{ - $object->callHooks('contactcard'); -} +// 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->callHooks(array('contactcard')); /* * Actions */ -$reshook=0; +$reshook=$hookmanager->executeHooks('doActions',$action,$object,$id); // Note that $action and $object may have been modified by some hooks -// Hook of actions. After that, reshook is 0 if we need to process standard actions, >0 otherwise. -if (! empty($object->hooks)) -{ - foreach($object->hooks as $hook) - { - if (! empty($hook['modules'])) - { - foreach($hook['modules'] as $module) - { - if (method_exists($module,'doActions')) - { - $resaction+=$module->doActions($object,$action,$id); // object is deprecated, action can be changed by method (to go back to other action for example), id can be changed/set by method (during creation for example) - if ($resaction < 0 || ! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0)) - { - $error=$module->error; $errors=$module->errors; - if ($action=='add') $action='create'; - if ($action=='update') $action='edit'; - } - else $reshook+=$resaction; - } - } - } - } -} // ---------- start deprecated. Use hook to hook actions. // If canvas actions are defined, because on url, or because contact was created with canvas feature on, we use the canvas feature. @@ -973,5 +948,5 @@ else $db->close(); -llxFooter('$Date: 2011/07/31 23:54:12 $ - $Revision: 1.222 $'); +llxFooter('$Date: 2011/08/10 19:55:22 $ - $Revision: 1.223 $'); ?> diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 8f540c134ad..c05b5051643 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -21,7 +21,7 @@ * \file htdocs/core/class/html.formfile.class.php * \ingroup core * \brief File of class to offer components to list and upload files - * \version $Id: html.formfile.class.php,v 1.52 2011/08/10 10:55:37 hregis Exp $ + * \version $Id: html.formfile.class.php,v 1.53 2011/08/10 19:55:22 hregis Exp $ */ @@ -146,7 +146,7 @@ class FormFile * @param title Title to show on top of form * @param buttonlabel Label on submit button * @param codelang Default language code to use on lang combo box if multilang is enabled - * @param hooks Object hook of external modules + * @param hookmanager Object hook of external modules * @return int <0 if KO, number of shown files if OK */ function show_documents($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$hookmanager=false) diff --git a/htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php b/htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php index 61b21f3b761..1c2b408e76a 100755 --- a/htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php +++ b/htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php @@ -20,7 +20,7 @@ * \file htdocs/includes/triggers/interface_modWorkflow_WorkflowManager.class.php * \ingroup core * \brief Trigger file for workflows - * \version $Id: interface_modWorkflow_WorkflowManager.class.php,v 1.8 2011/07/31 23:29:45 eldy Exp $ + * \version $Id: interface_modWorkflow_WorkflowManager.class.php,v 1.9 2011/08/10 19:55:21 hregis Exp $ */ @@ -105,7 +105,13 @@ class InterfaceWorkflowManager { include_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'); $order = new Commande($this->db); - $ret=$order->createFromProposal($object,0); + + // Actions on extra fields (by external module or standard code) + include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); + $hookmanager=new HookManager($this->db); + $hookmanager->callHooks(array('ordercard')); + + $ret=$order->createFromProposal($object,0,$hookmanager); if ($ret < 0) { $this->error=$invoice->error; $this->errors[]=$invoice->error; } return $ret; } @@ -119,7 +125,13 @@ class InterfaceWorkflowManager { include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'); $invoice = new Facture($this->db); - $ret=$invoice->createFromOrder($object,0); + + // Actions on extra fields (by external module or standard code) + include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); + $hookmanager=new HookManager($this->db); + $hookmanager->callHooks(array('invoicecard')); + + $ret=$invoice->createFromOrder($object,$hookmanager); if ($ret < 0) { $this->error=$invoice->error; $this->errors[]=$invoice->error; } return $ret; }