Skip to content

Commit

Permalink
- Correction du traitement des webhooks : produit puis commande dans …
Browse files Browse the repository at this point in the history
…l'ordre du plus recent au plus vieux

- Correction affichage de l'ordre de la liste des Webhooks
  • Loading branch information
kkhelifa-opendsi committed Sep 4, 2024
1 parent eea1395 commit a343cdd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
7 changes: 6 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.0.12
14.0.13
60 changes: 31 additions & 29 deletions class/business/eCommercePendingWebHook.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) . ":<br>";
$output .= '<span style="color: orangered;">' . $langs->trans('Warning') . ': ' . $this->warningsToString() . '</span>' . "<br>";
$error++;
} elseif ($result < 0) {
$output .= $langs->trans('ECommerceErrorSynchronizeWebHook', $obj->rowid, $obj->webhook_topic) . ":<br>";
$output .= '<span style="color: red;">' . $langs->trans('Error') . ': ' . $this->errorsToString() . '</span>' . "<br>";
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) . ":<br>";
$output .= '<span style="color: orangered;">' . $langs->trans('Warning') . ': ' . $this->warningsToString() . '</span>' . "<br>";
$error++;
} elseif ($result < 0) {
$output .= $langs->trans('ECommerceErrorSynchronizeWebHook', $obj->rowid, $obj->webhook_topic) . ":<br>";
$output .= '<span style="color: red;">' . $langs->trans('Error') . ': ' . $this->errorsToString() . '</span>' . "<br>";
$error++;
}
}
$this->db->free($resql);
}
}
$this->db->free($resql);

eCommerceUtils::stopAndLogStopwatch($stopwatch_id);

Expand All @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions class/business/eCommerceSynchro.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2523,6 +2525,7 @@ public function deleteProductLink($remote_id)

$this->error = '';
$this->errors = array();
$this->warnings = array();
$error = 0;

if (empty($remote_id)) {
Expand Down
2 changes: 1 addition & 1 deletion webhookslist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down

0 comments on commit a343cdd

Please sign in to comment.