From a343cddafc2801fbf7867c37ddd327d3993c4113 Mon Sep 17 00:00:00 2001 From: Kamel Khelifa Date: Wed, 4 Sep 2024 09:57:19 +0200 Subject: [PATCH] - Correction du traitement des webhooks : produit puis commande dans l'ordre du plus recent au plus vieux - Correction affichage de l'ordre de la liste des Webhooks --- ChangeLog.md | 7 ++- VERSION | 2 +- .../eCommercePendingWebHook.class.php | 60 ++++++++++--------- class/business/eCommerceSynchro.class.php | 3 + webhookslist.php | 2 +- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 9e96768..7182fb6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog +## [14.0.13] - 04-08-2024 +- Correction du traitement des webhooks : produit puis commande dans l'ordre du plus recent au plus vieux +- Correction affichage de l'ordre de la liste des Webhooks + ## [14.0.12] - 30-08-2024 - Correction et amelioration du support WPML pour les produits variables traduits synchronisés - Correction de la recuperation de l'id du pays pour les code pays des domtom @@ -935,7 +939,8 @@ - Initial version. -[Non Distribué]: https://github.com/OPEN-DSI/ecommerceng_woosync/compare/14.0.12...HEAD +[Non Distribué]: https://github.com/OPEN-DSI/ecommerceng_woosync/compare/14.0.13...HEAD +[14.0.13]: https://github.com/OPEN-DSI/ecommerceng_woosync/commits/14.0.13 [14.0.12]: https://github.com/OPEN-DSI/ecommerceng_woosync/commits/14.0.12 [14.0.11]: https://github.com/OPEN-DSI/ecommerceng_woosync/commits/14.0.11 [14.0.10]: https://github.com/OPEN-DSI/ecommerceng_woosync/commits/14.0.10 diff --git a/VERSION b/VERSION index c859491..4526d8d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -14.0.12 \ No newline at end of file +14.0.13 \ No newline at end of file diff --git a/class/business/eCommercePendingWebHook.class.php b/class/business/eCommercePendingWebHook.class.php index 2f85231..ce05ccb 100755 --- a/class/business/eCommercePendingWebHook.class.php +++ b/class/business/eCommercePendingWebHook.class.php @@ -568,40 +568,41 @@ public function cronProcessPendingWebHooks() return -1; } - $sql = "SELECT epw.rowid, epw.site_id, epw.webhook_topic, epw.webhook_resource, epw.webhook_event, epw.webhook_data"; - $sql .= " FROM " . MAIN_DB_PREFIX . "ecommerce_pending_webhooks AS epw"; -// $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ecommerce_site AS es ON es.rowid = epw.site_id"; - $sql .= " WHERE epw.status IN (" . self::STATUS_NOT_PROCESSED . ")"; -// $sql .= " AND es.entity IN (" . getEntity('ecommerceng') . ")"; - $sql .= " ORDER BY epw.webhook_topic DESC, epw.rowid DESC"; - - $resql = $this->db->query($sql); - if (!$resql) { - dolibarr_del_const($this->db, 'ECOMMERCE_PROCESSING_WEBHOOK_SYNCHRONIZATION', 0); - $this->error = 'Error ' . $this->db->lasterror(); - $this->errors = array(); - dol_syslog(__METHOD__ . " SQL: " . $sql . "; Error: " . $this->db->lasterror(), LOG_ERR); - return -1; - } - $stopwatch_id = eCommerceUtils::startAndLogStopwatch(__METHOD__); - while ($obj = $this->db->fetch_object($resql)) { - $result = $this->synchronize($obj->site_id, $obj->webhook_topic, $obj->webhook_resource, $obj->webhook_event, json_decode($obj->webhook_data, true)); - if ($result > 0) $result = $this->setStatusProcessed($obj->rowid); - elseif ($result == -2) $this->setStatusWarning($obj->rowid, $this->warningsToString()); - else $this->setStatusError($obj->rowid, $this->errorsToString()); - if ($result == -2) { - $output .= $langs->trans('ECommerceWarningSynchronizeWebHook', $obj->rowid, $obj->webhook_topic) . ":
"; - $output .= '' . $langs->trans('Warning') . ': ' . $this->warningsToString() . '' . "
"; - $error++; - } elseif ($result < 0) { - $output .= $langs->trans('ECommerceErrorSynchronizeWebHook', $obj->rowid, $obj->webhook_topic) . ":
"; - $output .= '' . $langs->trans('Error') . ': ' . $this->errorsToString() . '' . "
"; + foreach (['product', 'order'] as $resource) { + $sql = "SELECT epw.rowid, epw.site_id, epw.webhook_topic, epw.webhook_resource, epw.webhook_event, epw.webhook_data"; + $sql .= " FROM " . MAIN_DB_PREFIX . "ecommerce_pending_webhooks AS epw"; + //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ecommerce_site AS es ON es.rowid = epw.site_id"; + $sql .= " WHERE epw.status IN (" . self::STATUS_NOT_PROCESSED . ")"; + $sql .= " AND epw.webhook_resource = '" . $this->db->escape($resource) . "'"; + //$sql .= " AND es.entity IN (" . getEntity('ecommerceng') . ")"; + $sql .= " ORDER BY epw.webhook_topic DESC, epw.rowid DESC"; + + $resql = $this->db->query($sql); + if (!$resql) { + $this->error = 'Error ' . $this->db->lasterror(); + $this->errors = array(); $error++; + } else { + while ($obj = $this->db->fetch_object($resql)) { + $result = $this->synchronize($obj->site_id, $obj->webhook_topic, $obj->webhook_resource, $obj->webhook_event, json_decode($obj->webhook_data, true)); + if ($result > 0) $result = $this->setStatusProcessed($obj->rowid); + elseif ($result == -2) $this->setStatusWarning($obj->rowid, $this->warningsToString()); + else $this->setStatusError($obj->rowid, $this->errorsToString()); + if ($result == -2) { + $output .= $langs->trans('ECommerceWarningSynchronizeWebHook', $obj->rowid, $obj->webhook_topic) . ":
"; + $output .= '' . $langs->trans('Warning') . ': ' . $this->warningsToString() . '' . "
"; + $error++; + } elseif ($result < 0) { + $output .= $langs->trans('ECommerceErrorSynchronizeWebHook', $obj->rowid, $obj->webhook_topic) . ":
"; + $output .= '' . $langs->trans('Error') . ': ' . $this->errorsToString() . '' . "
"; + $error++; + } + } + $this->db->free($resql); } } - $this->db->free($resql); eCommerceUtils::stopAndLogStopwatch($stopwatch_id); @@ -610,6 +611,7 @@ public function cronProcessPendingWebHooks() if ($error) { $this->error = $output; $this->errors = array(); + dol_syslog(__METHOD__ . " SQL: " . $sql . "; Error: " . $this->db->lasterror(), LOG_ERR); return -1; } else { $output .= $langs->trans('ECommerceSynchronizeWebHooksSuccess'); diff --git a/class/business/eCommerceSynchro.class.php b/class/business/eCommerceSynchro.class.php index 20026bd..26dac70 100755 --- a/class/business/eCommerceSynchro.class.php +++ b/class/business/eCommerceSynchro.class.php @@ -2412,6 +2412,7 @@ public function synchronizeOrderFromData($raw_data) $this->error = ''; $this->errors = array(); + $this->warnings = array(); try { $order_data = $this->eCommerceRemoteAccess->convertOrderDataIntoProcessedData($raw_data); @@ -2444,6 +2445,7 @@ public function synchronizeProductFromData($raw_data) $this->error = ''; $this->errors = array(); + $this->warnings = array(); try { $product_data = $this->eCommerceRemoteAccess->convertProductDataIntoProcessedData($raw_data); @@ -2523,6 +2525,7 @@ public function deleteProductLink($remote_id) $this->error = ''; $this->errors = array(); + $this->warnings = array(); $error = 0; if (empty($remote_id)) { diff --git a/webhookslist.php b/webhookslist.php index 4405bfa..31bc16b 100755 --- a/webhookslist.php +++ b/webhookslist.php @@ -232,7 +232,7 @@ $reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; -$sql.= $db->order($sortfield, $sortorder); +$sql.= $db->order($sortfield . ", rowid", $sortorder . "," . $sortorder); // Count total nb of records $nbtotalofrecords = '';