Init list of triggers only when we need it. Avoid Select at each
webhook.
This commit is contained in:
parent
de07195aa9
commit
3d8541513b
3 changed files with 31 additions and 67 deletions
|
|
@ -96,7 +96,7 @@ class Target extends CommonObject
|
|||
'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
|
||||
'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'index' => 1, 'searchall' => 1, 'validate' => 1, 'comment' => "Reference of object"),
|
||||
'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 0, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'csslist'=>'tdoverflowmax150', 'showoncombobox' => 2, 'validate' => 1,),
|
||||
'trigger_codes' => array('type' => 'text', 'label' => 'TriggerCodes', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 1, 'help' => "TriggerCodeInfo", 'tdcss'=>'titlefieldmiddle', 'css' => 'minwidth400', 'arrayofkeyval' => array('c_action_trigger' => 'c_action_trigger'), 'multiinput' => 1,),
|
||||
'trigger_codes' => array('type' => 'text', 'label' => 'TriggerCodes', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 1, 'help' => "TriggerCodeInfo", 'tdcss'=>'titlefieldmiddle', 'css' => 'minwidth400', 'arrayofkeyval' => array('defined_in_constructor' => 'defined_from_c_action_trigger'), 'multiinput' => 1,),
|
||||
'url' => array('type' => 'varchar(255)', 'label' => 'Url', 'enabled' => 1, 'position' => 55, 'notnull' => 1, 'visible' => 1,),
|
||||
'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 3, 'validate' => 1,),
|
||||
'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0, 'cssview' => 'wordbreak', 'validate' => 1,),
|
||||
|
|
@ -170,7 +170,7 @@ class Target extends CommonObject
|
|||
*/
|
||||
public function __construct(DoliDB $db)
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $langs;
|
||||
|
||||
$this->db = $db;
|
||||
|
||||
|
|
@ -191,7 +191,26 @@ class Target extends CommonObject
|
|||
}
|
||||
}
|
||||
|
||||
// Translate some data of arrayofkeyval
|
||||
if (is_object($langs)) {
|
||||
foreach ($this->fields as $key => $val) {
|
||||
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
|
||||
foreach ($val['arrayofkeyval'] as $key2 => $val2) {
|
||||
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the list of available triggers;
|
||||
*
|
||||
* @return int Return integer <0 if KO, >0 if OK
|
||||
*/
|
||||
public function initListOfTriggers()
|
||||
{
|
||||
// Define the array $arrayofkeyval for $this->fields["trigger_codes"]
|
||||
if (!empty($this->fields["trigger_codes"]['arrayofkeyval']) && is_array($this->fields["trigger_codes"]['arrayofkeyval']) && !empty($this->fields["trigger_codes"]["multiinput"])) {
|
||||
$sql = "SELECT c.code, c.label FROM ".MAIN_DB_PREFIX."c_action_trigger as c ORDER BY c.rang DESC";
|
||||
$resql = $this->db->query($sql);
|
||||
|
|
@ -211,17 +230,7 @@ class Target extends CommonObject
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Translate some data of arrayofkeyval
|
||||
if (is_object($langs)) {
|
||||
foreach ($this->fields as $key => $val) {
|
||||
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
|
||||
foreach ($val['arrayofkeyval'] as $key2 => $val2) {
|
||||
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -386,8 +395,6 @@ class Target extends CommonObject
|
|||
*/
|
||||
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
|
||||
$records = array();
|
||||
|
|
@ -494,7 +501,7 @@ class Target extends CommonObject
|
|||
*/
|
||||
public function validate($user, $notrigger = 0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $conf;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
|
|
@ -563,7 +570,7 @@ class Target extends CommonObject
|
|||
$this->error = $this->db->lasterror();
|
||||
}
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'target/".$this->db->escape($this->newref)."'";
|
||||
$sql .= " WHERE filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
|
||||
$sql .= " WHERE filepath = 'target/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
$error++;
|
||||
|
|
@ -877,28 +884,6 @@ class Target extends CommonObject
|
|||
return $this->initAsSpecimenCommon();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an array of lines
|
||||
*
|
||||
* @return array|int array of lines if OK, <0 if KO
|
||||
*/
|
||||
public function getLinesArray()
|
||||
{
|
||||
$this->lines = array();
|
||||
|
||||
$objectline = new TargetLine($this->db);
|
||||
$result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_target:=:'.((int) $this->id).')');
|
||||
|
||||
if (is_numeric($result)) {
|
||||
$this->error = $objectline->error;
|
||||
$this->errors = $objectline->errors;
|
||||
return $result;
|
||||
} else {
|
||||
$this->lines = $result;
|
||||
return $this->lines;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference to the following non used object depending on the active numbering module.
|
||||
*
|
||||
|
|
@ -957,8 +942,6 @@ class Target extends CommonObject
|
|||
*/
|
||||
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$result = 0;
|
||||
$includedocgeneration = 0;
|
||||
|
||||
|
|
@ -990,7 +973,7 @@ class Target extends CommonObject
|
|||
*/
|
||||
public function doScheduledJob()
|
||||
{
|
||||
global $conf, $langs;
|
||||
//global $conf, $langs;
|
||||
|
||||
//$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
|
||||
|
||||
|
|
@ -1000,7 +983,7 @@ class Target extends CommonObject
|
|||
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
|
||||
$now = dol_now();
|
||||
//$now = dol_now();
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
|
@ -1011,27 +994,3 @@ class Target extends CommonObject
|
|||
return $error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
|
||||
|
||||
/**
|
||||
* Class TargetLine. You can also remove this and generate a CRUD class for lines objects.
|
||||
*/
|
||||
class TargetLine extends CommonObjectLine
|
||||
{
|
||||
// To complete with content of an object TargetLine
|
||||
// We should have a field rowid, fk_target and position
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct(DoliDB $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
|
||||
$this->isextrafieldmanaged = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,6 +173,8 @@ $form = new Form($db);
|
|||
$formfile = new FormFile($db);
|
||||
$formproject = new FormProjets($db);
|
||||
|
||||
$object->initListOfTriggers();
|
||||
|
||||
$title = $langs->trans("Target");
|
||||
$help_url = '';
|
||||
llxHeader('', $title, $help_url);
|
||||
|
|
@ -385,6 +387,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||
//$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
|
||||
//unset($object->fields['fk_project']); // Hide field already shown in banner
|
||||
//unset($object->fields['fk_soc']); // Hide field already shown in banner
|
||||
// TODO Remove this part of code
|
||||
$arraytriggercodes = explode(",", $object->trigger_codes);
|
||||
foreach ($arraytriggercodes as $key => $value) {
|
||||
if (isset($object->fields["trigger_codes"]['arrayofkeyval'][$value])) {
|
||||
|
|
|
|||
|
|
@ -215,6 +215,8 @@ if (empty($reshook)) {
|
|||
|
||||
$form = new Form($db);
|
||||
|
||||
$object->initListOfTriggers();
|
||||
|
||||
$now = dol_now();
|
||||
//$help_url = "EN:Module_Target|FR:Module_Target_FR|ES:Módulo_Target";
|
||||
$help_url = '';
|
||||
|
|
|
|||
Loading…
Reference in a new issue