From e8b139d1c64a647434f7dd6c7a6e39e820224b41 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 13 Jun 2019 22:48:31 +0200 Subject: [PATCH] Fix repeated logs and fetch --- htdocs/comm/action/class/actioncomm.class.php | 13 ++++--- htdocs/core/class/discount.class.php | 4 +- htdocs/core/class/html.formactions.class.php | 39 +++++++++++-------- .../modules/facture/mod_facture_terre.php | 4 +- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 905b562ab5d..6e4e3fb941b 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -120,7 +120,7 @@ class ActionComm extends CommonObject * Object user that create action * @var User * @deprecated - * @see authorid + * @see $authorid */ public $author; @@ -128,7 +128,7 @@ class ActionComm extends CommonObject * Object user that modified action * @var User * @deprecated - * @see usermodid + * @see $usermodid */ public $usermod; @@ -1010,7 +1010,7 @@ class ActionComm extends CommonObject /** * Load all objects with filters. - * WARNING: This make a fetch on all records instead of making one request with a join. + * @TODO WARNING: This make a fetch on all records instead of making one request with a join. * * @param DoliDb $db Database handler * @param int $socid Filter by thirdparty @@ -1020,7 +1020,7 @@ class ActionComm extends CommonObject * @param string $sortfield Sort on this field * @param string $sortorder ASC or DESC * @param string $limit Limit number of answers - * @return array or string Error string if KO, array with actions if OK + * @return array|string Error string if KO, array with actions if OK */ public static function getActions($db, $socid = 0, $fk_element = 0, $elementtype = '', $filter = '', $sortfield = 'a.datep', $sortorder = 'DESC', $limit = 0) { @@ -1028,6 +1028,8 @@ class ActionComm extends CommonObject $resarray=array(); + dol_syslog(get_class()."::getActions", LOG_DEBUG); + $sql = "SELECT a.id"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql.= " WHERE a.entity IN (".getEntity('agenda').")"; @@ -1041,7 +1043,6 @@ class ActionComm extends CommonObject if ($sortorder && $sortfield) $sql.=$db->order($sortfield, $sortorder); $sql.=$db->plimit($limit, 0); - dol_syslog(get_class()."::getActions", LOG_DEBUG); $resql=$db->query($sql); if ($resql) { @@ -1285,7 +1286,7 @@ class ActionComm extends CommonObject if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips - if ((!$user->rights->agenda->allactions->read && $this->author->id != $user->id) || (!$user->rights->agenda->myactions->read && $this->author->id == $user->id)) + if ((!$user->rights->agenda->allactions->read && $this->authorid != $user->id) || (!$user->rights->agenda->myactions->read && $this->authorid == $user->id)) $option = 'nolink'; $label = $this->label; diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index 93b51d0ddf8..8e66b29a3f8 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -497,8 +497,9 @@ class DiscountAbsolute { global $conf; + dol_syslog(get_class($this)."::getAvailableDiscounts discount_type=".$discount_type, LOG_DEBUG); + $sql = "SELECT SUM(rc.amount_ttc) as amount"; - //$sql = "SELECT rc.amount_ttc as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; $sql.= " WHERE rc.entity = " . $conf->entity; $sql.= " AND rc.discount_type=".intval($discount_type); @@ -512,7 +513,6 @@ class DiscountAbsolute if ($filter) $sql.=' AND ('.$filter.')'; if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue); - dol_syslog(get_class($this)."::getAvailableDiscounts", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index 31353ea3d10..bb1cf5fbfe7 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -213,24 +213,22 @@ class FormActions $page=0; $param=''; - $total = 0; - print '
'; print ''; print ''; - print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); - print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); - print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); + print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); + print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); + print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); - print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, '', $sortfield, $sortorder, 'center ', 1); - print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, 'right ', 1); + print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, '', $sortfield, $sortorder, 'center ', 1); + print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, 'right ', 1); print ''; print "\n"; - $userstatic = new User($this->db); - - if (count($listofactions)) + if (is_array($listofactions) && count($listofactions)) { + $cacheusers=array(); + $cursorevent = 0; foreach($listofactions as $action) { @@ -246,8 +244,20 @@ class FormActions print ''; // Type @@ -284,10 +294,7 @@ class FormActions } print ''; print ''; print ''; diff --git a/htdocs/core/modules/facture/mod_facture_terre.php b/htdocs/core/modules/facture/mod_facture_terre.php index c01fa9d2e09..a4cc1762766 100644 --- a/htdocs/core/modules/facture/mod_facture_terre.php +++ b/htdocs/core/modules/facture/mod_facture_terre.php @@ -184,6 +184,8 @@ class mod_facture_terre extends ModeleNumRefFactures { global $db; + dol_syslog(get_class($this)."::getNextValue mode=".$mode, LOG_DEBUG); + if ($invoice->type == 2) $prefix=$this->prefixcreditnote; elseif ($invoice->type == 3) $prefix=$this->prefixdeposit; else $prefix=$this->prefixinvoice; @@ -195,7 +197,6 @@ class mod_facture_terre extends ModeleNumRefFactures $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; $resql=$db->query($sql); - dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); if ($resql) { $obj = $db->fetch_object($resql); @@ -219,7 +220,6 @@ class mod_facture_terre extends ModeleNumRefFactures $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; $sql.= " ORDER BY ref DESC"; - dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); $resql=$db->query($sql); if ($resql) {
'; if (! empty($action->userownerid)) { - $userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched - print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', ''); + if (is_object($cacheusers[$action->userownerid])) + { + $tmpuser = $cacheusers[$action->userownerid]; + } + else + { + $tmpuser = new User($this->db); + $tmpuser->fetch($action->userownerid); + $cacheusers[$action->userownerid] = $tmpuser; + } + if ($tmpuser->id > 0) + { + print $tmpuser->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', ''); + } } print ''; - if (! empty($action->author->id)) - { - print $action->getLibStatut(3); - } + print $action->getLibStatut(3); print '