cronjob artikeluebertragen format

This commit is contained in:
OpenXE 2024-06-26 17:01:40 +02:00
parent 35add7d292
commit 7d18234567
2 changed files with 124 additions and 148 deletions

View File

@ -1,52 +1,30 @@
<?php <?php
/*
include(dirname(__FILE__)."/../conf/main.conf.php");
include(dirname(__FILE__)."/../phpwf/plugins/class.mysql.php");
include(dirname(__FILE__)."/../www/lib/imap.inc.php");
include(dirname(__FILE__)."/../www/lib/class.erpapi.php");
include(dirname(__FILE__)."/../www/lib/class.erpapi_custom.php");
include(dirname(__FILE__)."/../www/lib/class.remote.php");
include(dirname(__FILE__)."/../www/lib/class.httpclient.php");
include(dirname(__FILE__)."/../www/lib/class.aes.php");
if (file_exists(dirname(__DIR__) . '/www/lib/class.erpapi_custom.php') && !class_exists('erpAPICustom')) {
class app_t {
var $DB;
var $erp;
var $user;
var $remote;
}
*/
//ENDE
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';
} }
if(empty($app->Conf)) { if (empty($app->Conf)) {
$conf = new Config(); $conf = new Config();
$app->Conf = $conf; $app->Conf = $conf;
} }
if(empty($app->DB) || empty($app->DB->connection)) { if (empty($app->DB) || empty($app->DB->connection)) {
$app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport); $app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport);
} }
if(!isset($app->erp) || !$app->erp) { if (!isset($app->erp) || !$app->erp) {
if (class_exists('erpAPICustom')) { if (class_exists('erpAPICustom')) {
$erp = new erpAPICustom($app); $erp = new erpAPICustom($app);
} else { } else {
$erp = new erpAPI($app); $erp = new erpAPI($app);
} }
//$remote = new Remote($app);
$app->erp = $erp; $app->erp = $erp;
//$app->remote= $remote;
} }
if(empty($app->remote)) { if (empty($app->remote)) {
if(is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')) { if (is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')) {
if(!class_exists('RemoteCustom')){ if (!class_exists('RemoteCustom')) {
require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php'; require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php';
} }
$app->remote = new RemoteCustom($app); $app->remote = new RemoteCustom($app);
} } else {
else {
$app->remote = new Remote($app); $app->remote = new Remote($app);
} }
} }
@ -59,17 +37,17 @@ $app->DB->Update(
WHERE `mutex` = 1 AND (`parameter` = 'artikeluebertragen') AND `aktiv` = 1" WHERE `mutex` = 1 AND (`parameter` = 'artikeluebertragen') AND `aktiv` = 1"
); );
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; 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` LIMIT 10'
); );
if(!empty($articles)) { if (!empty($articles)) {
/** @var Shopexport $objShopexport */ /** @var Shopexport $objShopexport */
$objShopexport = $app->loadModule('shopexport'); $objShopexport = $app->loadModule('shopexport');
if($objShopexport !== null && method_exists($objShopexport, 'addChangedArticles')) { if ($objShopexport !== null && method_exists($objShopexport, 'addChangedArticles')) {
$objShopexport->addChangedArticles(); $objShopexport->addChangedArticles();
} }
} }
@ -77,21 +55,21 @@ if(!empty($articles)) {
$anzChecked = []; $anzChecked = [];
$anzChanged = []; $anzChanged = [];
$lastids = []; $lastids = [];
while(!empty($articles)) { while (!empty($articles)) {
foreach($articles as $article) { foreach ($articles as $article) {
if(empty($anzChanged[$article['shop']])) { if (empty($anzChanged[$article['shop']])) {
$anzChanged[$article['shop']] = 0; $anzChanged[$article['shop']] = 0;
} }
if(empty($anzChecked[$article['shop']])) { if (empty($anzChecked[$article['shop']])) {
$anzChecked[$article['shop']] = 0; $anzChecked[$article['shop']] = 0;
} }
if(!isset($lastids[$article['shop']])) { if (!isset($lastids[$article['shop']])) {
$lastids[$article['shop']] = (int)$app->erp->GetKonfiguration( $lastids[$article['shop']] = (int) $app->erp->GetKonfiguration(
'shopexport_artikeluebertragen_check_lastid_' . $article['shop'] 'shopexport_artikeluebertragen_check_lastid_' . $article['shop']
); );
} }
$changed = $objShopexport->hasArticleHashChanged($article['artikel'], $article['shop']); $changed = $objShopexport->hasArticleHashChanged($article['artikel'], $article['shop']);
if($changed['changed']) { if ($changed['changed']) {
$app->DB->Insert( $app->DB->Insert(
sprintf( sprintf(
'INSERT INTO `shopexport_artikeluebertragen` (`artikel`, `shop`, `check_nr`) VALUES (%d, %d, %d)', 'INSERT INTO `shopexport_artikeluebertragen` (`artikel`, `shop`, `check_nr`) VALUES (%d, %d, %d)',
@ -115,14 +93,14 @@ while(!empty($articles)) {
); );
} }
$app->erp->SetKonfigurationValue( $app->erp->SetKonfigurationValue(
'shopexport_artikeluebertragen_check_changed_'.$article['shop'], 'shopexport_artikeluebertragen_check_changed_' . $article['shop'],
$anzChanged[$article['shop']] $anzChanged[$article['shop']]
); );
$app->erp->SetKonfigurationValue( $app->erp->SetKonfigurationValue(
'shopexport_artikeluebertragen_check_checked_'.$article['shop'], 'shopexport_artikeluebertragen_check_checked_' . $article['shop'],
$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'])) {
return; return;
} }
$articles = $app->DB->SelectArr( $articles = $app->DB->SelectArr(
@ -141,23 +119,22 @@ $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"
); );
if(!empty($shopartikel)) { if (!empty($shopartikel)) {
$anz = 0; $anz = 0;
while ($row = $app->DB->Fetch_Assoc($shopartikel)) { while ($row = $app->DB->Fetch_Assoc($shopartikel)) {
if(!isset($lastids[$row['shop']])) { if (!isset($lastids[$row['shop']])) {
$lastids[$row['shop']] = (int)$app->erp->GetKonfiguration('shopexport_artikeluebertragen_check_lastid_' . $row['shop']); $lastids[$row['shop']] = (int) $app->erp->GetKonfiguration('shopexport_artikeluebertragen_check_lastid_' . $row['shop']);
} }
$anz++; $anz++;
try { try {
$app->remote->RemoteSendArticleList($row['shop'], array($row['artikel'])); $app->remote->RemoteSendArticleList($row['shop'], array($row['artikel']));
$app->erp->LagerSync($row['artikel'], true); $app->erp->LagerSync($row['artikel'], true);
} } catch (Execption $exception) {
catch (Execption $exception) {
$app->erp->LogFile($app->DB->real_escape_string($exception->getMessage())); $app->erp->LogFile($app->DB->real_escape_string($exception->getMessage()));
} }
$app->DB->Delete( $app->DB->Delete(
@ -167,9 +144,9 @@ while($check > 0) {
) )
); );
if(!empty($row['check_nr']) && $row['check_nr'] == $lastids[$row['shop']]) { if (!empty($row['check_nr']) && $row['check_nr'] == $lastids[$row['shop']]) {
$transfered = 1+(int)$app->erp->GetKonfiguration('shopexport_artikeluebertragen_check_transfered_'.$row['shop']); $transfered = 1 + (int) $app->erp->GetKonfiguration('shopexport_artikeluebertragen_check_transfered_' . $row['shop']);
$app->erp->SetKonfigurationValue('shopexport_artikeluebertragen_check_transfered_'.$row['shop'], $transfered); $app->erp->SetKonfigurationValue('shopexport_artikeluebertragen_check_transfered_' . $row['shop'], $transfered);
} }
$app->DB->Update( $app->DB->Update(
@ -182,11 +159,10 @@ while($check > 0) {
$app->DB->free($shopartikel); $app->DB->free($shopartikel);
} }
if(method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) { if (method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) {
return; return;
} }
//sleep(20); // das performance nicht total spinnt
$check = $app->DB->Select('SELECT COUNT(`id`) FROM `shopexport_artikeluebertragen`'); $check = $app->DB->Select('SELECT COUNT(`id`) FROM `shopexport_artikeluebertragen`');
} }
$app->DB->Update( $app->DB->Update(
@ -194,5 +170,3 @@ $app->DB->Update(
SET `letzteausfuerhung`= NOW(), `mutex` = 0,`mutexcounter`=0 SET `letzteausfuerhung`= NOW(), `mutex` = 0,`mutexcounter`=0
WHERE `parameter` = 'artikeluebertragen'" WHERE `parameter` = 'artikeluebertragen'"
); );

View File

@ -808,6 +808,8 @@ class Shopimporter_Mirakl extends ShopimporterBase {
$number_of_articles = 0; $number_of_articles = 0;
$this->Log('Produktexport Start', print_r($csv,true));
// Build CSV // Build CSV
$csv_header = ""; $csv_header = "";
$newline = ""; $newline = "";