From 3eb72ad833c57f3846ae84d68cec4404ff896bcb Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 9 Mar 2021 17:55:51 +0100 Subject: [PATCH 1/5] truc --- htdocs/main.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index f72a933c688..3e4f70eeecc 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -44,7 +44,7 @@ if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) { // Add Xdebug code coverage //define('XDEBUGCOVERAGE',1); if (defined('XDEBUGCOVERAGE')) { - xdebug_start_code_coverage(); + xdebug_start_code_coverage('sdfd'); } } From 34080b19a11bced1d2cb47181ed336d8fada202f Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 9 Mar 2021 18:23:57 +0100 Subject: [PATCH 2/5] fix debug --- htdocs/main.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 3e4f70eeecc..f72a933c688 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -44,7 +44,7 @@ if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) { // Add Xdebug code coverage //define('XDEBUGCOVERAGE',1); if (defined('XDEBUGCOVERAGE')) { - xdebug_start_code_coverage('sdfd'); + xdebug_start_code_coverage(); } } From 7aec2fc02b333a7aede33e107e7048301c8fe67f Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 9 Mar 2021 18:52:52 +0100 Subject: [PATCH 3/5] create task --- .../modules/modEventOrganization.class.php | 2 +- ...ntOrganization_EventOrganization.class.php | 123 ++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php diff --git a/htdocs/core/modules/modEventOrganization.class.php b/htdocs/core/modules/modEventOrganization.class.php index b0527ad30b5..77d0cc0c81f 100644 --- a/htdocs/core/modules/modEventOrganization.class.php +++ b/htdocs/core/modules/modEventOrganization.class.php @@ -66,7 +66,7 @@ class modEventOrganization extends DolibarrModules // Define some features supported by module (triggers, login, substitutions, menus, css, etc...) $this->module_parts = array( // Set this to 1 if module has its own trigger directory (core/triggers) - 'triggers' => 0, + 'triggers' => 1, // Set this to 1 if module has its own login method file (core/login) 'login' => 0, // Set this to 1 if module has its own substitution function file (core/substitutions) diff --git a/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php b/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php new file mode 100644 index 00000000000..c5d978c7534 --- /dev/null +++ b/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php @@ -0,0 +1,123 @@ + + * Copyright (C) 2021 Florian Henry + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php + * \ingroup eventorganization + * \brief Trigger file for Event Organization module + */ + +require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; + + +/** + * Class of triggered functions for agenda module + */ +class InterfaceEventOrganization extends DolibarrTriggers +{ + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = "eventorganization"; + $this->description = "Triggers of this module to manage event organization triggers action"; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'action'; + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) + * + * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database: + * $object->actiontypecode (translation action code: AC_OTH, ...) + * $object->actionmsg (note, long text) + * $object->actionmsg2 (label, short text) + * $object->sendtoid (id of contact or array of ids of contacts) + * $object->socid (id of thirdparty) + * $object->fk_project + * $object->fk_element (ID of object to link action event to) + * $object->elementtype (->element of object to link action to) + * $object->module (if defined, elementtype in llx_actioncomm will be elementtype@module) + * + * @param string $action Event action code ('CONTRACT_MODIFY', 'RECRUITMENTCANDIDATURE_MODIFIY', ...) + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) + { + if (empty($conf->eventorganization->enabled)) { + return 0; // Module not active, we do nothing + } + $error=0; + // Actions + if ($action == 'PROJECT_VALIDATE') { + // Load translation files required by the page + $langs->loadLangs(array("eventorganization")); + + if (!empty($conf->global->EVENTORGANIZATION_TASK_LABEL)) { + $taskToDo = explode("\n", $conf->global->EVENTORGANIZATION_TASK_LABEL); + if (is_array($taskToDo) && count($taskToDo)>0) { + $this->db->begin(); + foreach ($taskToDo as $taskLabel) { + $task = new Task($this->db); + $task->label = $taskLabel; + $task->fk_project = $object->id; + $defaultref = ''; + $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON; + if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . ".php")) { + require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . '.php'; + $modTask = new $obj; + $defaultref = $modTask->getNextValue($object->thirdparty, null); + } + if (is_numeric($defaultref) && $defaultref <= 0) { + $defaultref = ''; + } + $task->ref = $defaultref; + $task->date_start = $object->date_start; + $task->date_end = $object->date_end; + $result = $task->create($user); + if ($result < 0) { + $this->errors=array_merge($this->errors, $task->errors); + $error++; + } + } + } + } + + if (empty($error)) { + $this->db->commit(); + return 1; + } else { + dol_syslog("InterfaceEventOrganization.class.php: ".implode(',', $this->errors), LOG_ERR); + $this->db->rollback(); + return -1; + } + } + } +} From 674224163992911d7962b00cd198bfe9200704f8 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 11 Mar 2021 16:55:49 +0100 Subject: [PATCH 4/5] better tranaction and condition --- ...ntOrganization_EventOrganization.class.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php b/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php index c5d978c7534..63b038196fa 100644 --- a/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php +++ b/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php @@ -80,7 +80,7 @@ class InterfaceEventOrganization extends DolibarrTriggers // Load translation files required by the page $langs->loadLangs(array("eventorganization")); - if (!empty($conf->global->EVENTORGANIZATION_TASK_LABEL)) { + if (!empty($conf->global->EVENTORGANIZATION_TASK_LABEL) && !empty($object->usage_organize_event)) { $taskToDo = explode("\n", $conf->global->EVENTORGANIZATION_TASK_LABEL); if (is_array($taskToDo) && count($taskToDo)>0) { $this->db->begin(); @@ -107,17 +107,18 @@ class InterfaceEventOrganization extends DolibarrTriggers $error++; } } + + if (empty($error)) { + $this->db->commit(); + return 1; + } else { + dol_syslog("InterfaceEventOrganization.class.php: ".implode(',', $this->errors), LOG_ERR); + $this->db->rollback(); + return -1; + } } } - - if (empty($error)) { - $this->db->commit(); - return 1; - } else { - dol_syslog("InterfaceEventOrganization.class.php: ".implode(',', $this->errors), LOG_ERR); - $this->db->rollback(); - return -1; - } } + return 0; } } From e8bbef8d2df154afc6cfc6adbea175b7116a69d9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Mar 2021 21:35:22 +0100 Subject: [PATCH 5/5] Update interface_50_modEventOrganization_EventOrganization.class.php --- ...ce_50_modEventOrganization_EventOrganization.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php b/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php index 63b038196fa..386a723bb5e 100644 --- a/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php +++ b/htdocs/core/triggers/interface_50_modEventOrganization_EventOrganization.class.php @@ -74,15 +74,17 @@ class InterfaceEventOrganization extends DolibarrTriggers if (empty($conf->eventorganization->enabled)) { return 0; // Module not active, we do nothing } + $error=0; + // Actions if ($action == 'PROJECT_VALIDATE') { - // Load translation files required by the page - $langs->loadLangs(array("eventorganization")); - if (!empty($conf->global->EVENTORGANIZATION_TASK_LABEL) && !empty($object->usage_organize_event)) { $taskToDo = explode("\n", $conf->global->EVENTORGANIZATION_TASK_LABEL); if (is_array($taskToDo) && count($taskToDo)>0) { + // Load translation files required by the page + $langs->loadLangs(array("eventorganization")); + $this->db->begin(); foreach ($taskToDo as $taskLabel) { $task = new Task($this->db);