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