From 9219dcfecb048e9778cf4815297f792af5fed601 Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 19 May 2021 11:52:34 +0200 Subject: [PATCH 1/3] Fix price log spam --- htdocs/product/class/product.class.php | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 188bcbfd355..124990d09e1 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1534,6 +1534,38 @@ class Product extends CommonObject } } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * check if price have really change to avoid log pollution + * + * @param int $level price level to change + * @return int <0 if KO, >0 if OK + */ + private function getArrayForPriceCompare($level = 0) + { + // phpcs:enable + + $testExit = array('multiprices','multiprices_ttc','multiprices_base_type','multiprices_min','multiprices_min_ttc','multiprices_tva_tx','multiprices_recuperableonly'); + + foreach ($testExit as $field){ + if (!isset($this->$field[$level])) { + return array(); + } + } + + $lastPrice = array( + 'level' => $level ? $level : 1, + 'multiprices' => doubleval($this->multiprices[$level]), + 'multiprices_ttc' => doubleval($this->multiprices_ttc[$level]), + 'multiprices_base_type' => $this->multiprices_base_type[$level], + 'multiprices_min' => doubleval($this->multiprices_min[$level]), + 'multiprices_min_ttc' => doubleval($this->multiprices_min_ttc[$level]), + 'multiprices_tva_tx' => doubleval($this->multiprices_tva_tx[$level]), + 'multiprices_recuperableonly' => doubleval($this->multiprices_recuperableonly[$level]), + ); + + return $lastPrice; + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1862,6 +1894,8 @@ class Product extends CommonObject { global $conf, $langs; + $lastPriceData = $this->getArrayForPriceCompare($level); // temporary store current price before update + $id = $this->id; dol_syslog(get_class($this)."::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr." newdefaultvatcode=".$newdefaultvatcode); @@ -1994,7 +2028,11 @@ class Product extends CommonObject // Price by quantity $this->price_by_qty = $newpbq; - $this->_log_price($user, $level); // Save price for level into table product_price + // check if price have really change before log + $newPriceData = $this->getArrayForPriceCompare($level); + if (!empty(array_diff_assoc($newPriceData, $lastPriceData)) || empty($conf->global->PRODUIT_MULTIPRICES)) { + $this->_log_price($user, $level); // Save price for level into table product_price + } $this->level = $level; // Store level of price edited for trigger From 1512abf96ab4412717c53f4877df56279a9b6921 Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 19 May 2021 12:00:27 +0200 Subject: [PATCH 2/3] Remove hpcs:disable --- htdocs/product/class/product.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 124990d09e1..87fb839b5c9 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1534,7 +1534,6 @@ class Product extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * check if price have really change to avoid log pollution * @@ -1543,7 +1542,6 @@ class Product extends CommonObject */ private function getArrayForPriceCompare($level = 0) { - // phpcs:enable $testExit = array('multiprices','multiprices_ttc','multiprices_base_type','multiprices_min','multiprices_min_ttc','multiprices_tva_tx','multiprices_recuperableonly'); From 3bf71d456ddc80564e29631ba714fe8d6368e096 Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 19 May 2021 12:01:47 +0200 Subject: [PATCH 3/3] fix doc --- htdocs/product/class/product.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 87fb839b5c9..685180e4659 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1535,10 +1535,10 @@ class Product extends CommonObject } /** - * check if price have really change to avoid log pollution + * used to check if price have really change to avoid log pollution * * @param int $level price level to change - * @return int <0 if KO, >0 if OK + * @return array */ private function getArrayForPriceCompare($level = 0) {