mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-11-14 20:17:14 +01:00
artikeluebertragen WIP bulk transfer, switch to logger
This commit is contained in:
parent
7d18234567
commit
8ebfc49ad2
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Xentral\Components\Logger\Logger;
|
||||
|
||||
/** @var Logger $logger */
|
||||
$logger = $app->Container->get('Logger');
|
||||
|
||||
if (file_exists(dirname(__DIR__) . '/www/lib/class.erpapi_custom.php') && !class_exists('erpAPICustom')) {
|
||||
include_once dirname(__DIR__) . '/www/lib/class.erpapi_custom.php';
|
||||
}
|
||||
@ -29,7 +34,9 @@ if (empty($app->remote)) {
|
||||
}
|
||||
}
|
||||
|
||||
$app->erp->LogFile('Cronjob Artikeluebertragung Start');
|
||||
$logger->debug(
|
||||
'Start'
|
||||
);
|
||||
|
||||
$app->DB->Update(
|
||||
"UPDATE `prozessstarter`
|
||||
@ -38,11 +45,14 @@ $app->DB->Update(
|
||||
);
|
||||
|
||||
if ($app->DB->Select("SELECT `mutex` FROM `prozessstarter` WHERE (`parameter` = 'artikeluebertragen') LIMIT 1") == 1) {
|
||||
return;
|
||||
$logger->debug(
|
||||
'Mutex'
|
||||
);
|
||||
// return;
|
||||
}
|
||||
|
||||
$articles = $app->DB->SelectArr(
|
||||
'SELECT `id`,`shop`,`artikel` FROM `shopexport_artikeluebertragen_check` ORDER BY `id` LIMIT 10'
|
||||
'SELECT `id`,`shop`,`artikel` FROM `shopexport_artikeluebertragen_check` ORDER BY `id`'
|
||||
);
|
||||
if (!empty($articles)) {
|
||||
/** @var Shopexport $objShopexport */
|
||||
@ -52,6 +62,13 @@ if (!empty($articles)) {
|
||||
}
|
||||
}
|
||||
|
||||
$logger->debug(
|
||||
'Prepare',
|
||||
[
|
||||
'articles' => $articles
|
||||
]
|
||||
);
|
||||
|
||||
$anzChecked = [];
|
||||
$anzChanged = [];
|
||||
$lastids = [];
|
||||
@ -101,6 +118,9 @@ while (!empty($articles)) {
|
||||
$anzChecked[$article['shop']]
|
||||
);
|
||||
if (method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) {
|
||||
$logger->debug(
|
||||
'!canRunCronjob'
|
||||
);
|
||||
return;
|
||||
}
|
||||
$articles = $app->DB->SelectArr(
|
||||
@ -119,6 +139,8 @@ $app->DB->Update(
|
||||
SET `letzteausfuerhung`=NOW(), `mutex` = 1,`mutexcounter`=0
|
||||
WHERE `parameter` = 'artikeluebertragen'"
|
||||
);
|
||||
|
||||
/*
|
||||
while ($check > 0) {
|
||||
$shopartikel = $app->DB->Query(
|
||||
"SELECT `id`,`shop`,`artikel`,`check_nr` FROM `shopexport_artikeluebertragen` ORDER BY `id` LIMIT 10"
|
||||
@ -164,7 +186,65 @@ while ($check > 0) {
|
||||
}
|
||||
|
||||
$check = $app->DB->Select('SELECT COUNT(`id`) FROM `shopexport_artikeluebertragen`');
|
||||
}*/
|
||||
|
||||
|
||||
$sql = "SELECT DISTINCT `shop`, shopexport.`bezeichnung` FROM `shopexport_artikeluebertragen` INNER JOIN shopexport ON shopexport.id = `shop`";
|
||||
$shops_to_transmit = $app->DB->SelectArr($sql);
|
||||
|
||||
//$app->erp->LogFile('Cronjob artikeluebertragen '.(!empty($shops_to_transmit)?count($shops_to_transmit):0)." shops", print_r($shops_to_transmit, true));
|
||||
$logger->debug(
|
||||
'{count} Shops',
|
||||
[
|
||||
'count' => (!empty($shops_to_transmit)?count($shops_to_transmit):0),
|
||||
'shops_to_transmit' => $shops_to_transmit
|
||||
]
|
||||
);
|
||||
|
||||
foreach ($shops_to_transmit as $shop_to_transmit) {
|
||||
$sql = "SELECT `artikel` FROM `shopexport_artikeluebertragen` WHERE `shop` = '".$shop_to_transmit['shop']."'";
|
||||
$articles_to_transmit = $app->DB->SelectArr($sql);
|
||||
|
||||
$logger->debug(
|
||||
'{bezeichnung} (Shop {shop_to_transmit}) {count} Artikel',
|
||||
[
|
||||
'shop_to_transmit' => $shop_to_transmit['shop'],
|
||||
'bezeichnung' => $shop_to_transmit['bezeichnung'],
|
||||
'count' => (!empty($articles_to_transmit)?count($articles_to_transmit):0),
|
||||
'articles_to_transmit' => $articles_to_transmit
|
||||
]
|
||||
);
|
||||
|
||||
if (!empty($articles_to_transmit)) {
|
||||
|
||||
$article_ids_to_transmit = array_column($articles_to_transmit, 'artikel');
|
||||
|
||||
try {
|
||||
$result = $app->remote->RemoteSendArticleList($shop_to_transmit['shop'], $article_ids_to_transmit); // Expected result is array $articles_to_transmit, field status contains transmission status
|
||||
} catch (Execption $exception) {
|
||||
$logger->error(
|
||||
'Fehler {bezeichnung} (Shop {shop_to_transmit}) {count} Artikel',
|
||||
[
|
||||
'shop_to_transmit' => $shop_to_transmit['shop'],
|
||||
'bezeichnung' => $shop_to_transmit['bezeichnung'],
|
||||
'count' => (!empty($articles_to_transmit)?count($articles_to_transmit):0),
|
||||
'exception' => $exception
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($result as $article) {
|
||||
$app->erp->LagerSync($article['artikel'], true);
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$logger->debug(
|
||||
'Ende'
|
||||
);
|
||||
|
||||
$app->DB->Update(
|
||||
"UPDATE `prozessstarter`
|
||||
SET `letzteausfuerhung`= NOW(), `mutex` = 0,`mutexcounter`=0
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 OpenXE project
|
||||
* SPDX-FileCopyrightText: 2022 Andreas Palm
|
||||
* SPDX-FileCopyrightText: 2019 Xentral (c) Xentral ERP Software GmbH, Fuggerstrasse 11, D-86150 Augsburg, Germany
|
||||
*
|
||||
@ -21,14 +22,18 @@
|
||||
?>
|
||||
<?php
|
||||
use Xentral\Modules\Onlineshop\Data\ShopConnectorResponseInterface;
|
||||
use Xentral\Components\Logger\Logger;
|
||||
|
||||
class Remote
|
||||
{
|
||||
/** @var ApplicationCore $app */
|
||||
public $app;
|
||||
/** @var Logger $logger */
|
||||
public $logger;
|
||||
public function __construct($app)
|
||||
{
|
||||
$this->app=$app;
|
||||
$this->logger = $app->Container->get('Logger');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1171,6 +1176,14 @@ class Remote
|
||||
*/
|
||||
public function RemoteSendArticleList($id,$artikel_arr, $extnummer = '', $nurlager = false)
|
||||
{
|
||||
|
||||
$this->logger->debug(
|
||||
'RemoteSendArticleList',
|
||||
[
|
||||
'artikel_arr' => $artikel_arr
|
||||
]
|
||||
);
|
||||
|
||||
if(!class_exists('ObjGenArtikel') &&
|
||||
is_file(dirname(__DIR__) . '/objectapi/mysql/_gen/object.gen.artikel.php')){
|
||||
include_once dirname(__DIR__) . '/objectapi/mysql/_gen/object.gen.artikel.php';
|
||||
@ -1217,8 +1230,16 @@ class Remote
|
||||
|
||||
for($i=0;$i<$cartikel_arr;$i++)
|
||||
{
|
||||
|
||||
$artikel = $artikel_arr[$i];
|
||||
|
||||
$this->logger->debug(
|
||||
'RemoteSendArticleList',
|
||||
[
|
||||
'artikel' => $artikel,
|
||||
'i' => $i
|
||||
]
|
||||
);
|
||||
|
||||
$lagerexport = $this->app->erp->GetArtikelShopEinstellung('autolagerlampe', $artikel, $shopexportarr);
|
||||
$tmp->Select($artikel);
|
||||
$data[$i] = ['artikel' => $artikel,'artikelid' => $artikel];
|
||||
@ -1642,6 +1663,8 @@ class Remote
|
||||
AND (v.objekt = 'Standard' OR v.objekt = '') AND (v.adresse = '0' OR v.adresse = '')
|
||||
AND (v.gueltig_bis >= NOW() OR v.gueltig_bis = '0000-00-00')
|
||||
ORDER BY v.preis DESC LIMIT 1");
|
||||
|
||||
if (!empty($priceInformation)) {
|
||||
$priceInformation = reset($priceInformation);
|
||||
$defaultPrice = $priceInformation['preis'];
|
||||
$defaultCurrency = $priceInformation['waehrung'] ?: 'EUR';
|
||||
@ -1649,9 +1672,9 @@ class Remote
|
||||
$defaultCurrency = 'EUR'; //the follow up function imply EUR as the default currency
|
||||
$defaultPrice = $this->app->erp->GetVerkaufspreisGruppe($artikel, 1, $preisgruppe);
|
||||
}
|
||||
|
||||
$data[$i]['waehrung'] = $defaultCurrency;
|
||||
$data[$i]['preis'] = $defaultPrice;
|
||||
}
|
||||
|
||||
if(!empty($tmp->GetSteuersatz()) && $tmp->GetSteuersatz() != -1){
|
||||
$data[$i]['steuersatz'] = (float)$tmp->GetSteuersatz();
|
||||
@ -1759,8 +1782,6 @@ class Remote
|
||||
* @deprecated Ende
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
$data[$i]['bruttopreis'] = $data[$i]['preis'] * $steuer;
|
||||
}
|
||||
$data[$i]['checksum'] = $tmp->GetChecksum();
|
||||
@ -2445,10 +2466,18 @@ class Remote
|
||||
$this->app->DB->Update($query);
|
||||
|
||||
$this->app->erp->AuftragProtokoll($orderId, 'Versandmeldung an Shop fehlgeschlagen', $bearbeiter);
|
||||
$this->app->erp->Logfile('Versandmeldung an Shop fehlgeschlagen', print_r([
|
||||
/* $this->app->erp->Logfile('Versandmeldung an Shop fehlgeschlagen', print_r([
|
||||
'orderId' => $orderId,
|
||||
'shopId' => $shopId,
|
||||
'message' => $response->getMessage()],true));
|
||||
'message' => $response->getMessage()],true));*/
|
||||
|
||||
$this->logger->error('Versandmeldung an Shop fehlgeschlagen',
|
||||
[
|
||||
'orderId' => $orderId,
|
||||
'shopId' => $shopId,
|
||||
'message' => $response->getMessage()
|
||||
]
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -2857,7 +2886,14 @@ class Remote
|
||||
$post_data['data'] = base64_encode(serialize($data));
|
||||
$client->timeout = 120;
|
||||
if(!$client->post($geturl,$post_data)) {
|
||||
$this->app->erp->LogFile(mysqli_real_escape_string($this->app->DB->connection,'An error occurred: '.$client->getError()));
|
||||
// $this->app->erp->LogFile(mysqli_real_escape_string($this->app->DB->connection,'An error occurred: '.$client->getError()));
|
||||
|
||||
$this->logger->error('An error occurred',
|
||||
[
|
||||
'error' => $client->getError()
|
||||
]
|
||||
);
|
||||
|
||||
throw new Exception('An error occurred: '.$client->getError());
|
||||
//return 'Netzwerkverbindung von WaWison zu Shopimporter fehlgeschlagen: '.$client->getError();
|
||||
}
|
||||
@ -2932,7 +2968,14 @@ class Remote
|
||||
|
||||
if(!$client->post($geturl,$post_data))
|
||||
{
|
||||
$this->app->erp->LogFile(mysqli_real_escape_string($this->app->DB->connection,'An error occurred: '.$client->getError()));
|
||||
// $this->app->erp->LogFile(mysqli_real_escape_string($this->app->DB->connection,'An error occurred: '.$client->getError()));
|
||||
|
||||
$this->logger->error('An error occurred',
|
||||
[
|
||||
'error' => $client->getError()
|
||||
]
|
||||
);
|
||||
|
||||
throw new Exception('An error occurred: '.$client->getError());
|
||||
}
|
||||
return unserialize($aes->decrypt(base64_decode($client->getContent())));
|
||||
|
@ -384,6 +384,7 @@ class Shopimporter_Mirakl extends ShopimporterBase {
|
||||
$this->Log("Angebotsync nach Mirakl hat Fehler", print_r($offer_export_result, true));
|
||||
$message .= $komma."Angebotsync in Mirakl hat Fehler";
|
||||
} else {
|
||||
$this->Log("Angebotsync nach Mirakl ok", print_r($offer_export_result, true));
|
||||
$message .= $komma."Angebotsimport in Mirakl ok";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user