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,198 +1,172 @@
<?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')) {
include_once dirname(__DIR__) . '/www/lib/class.erpapi_custom.php';
class app_t {
var $DB;
var $erp;
var $user;
var $remote;
} }
*/ if (empty($app->Conf)) {
//ENDE $conf = new Config();
if(file_exists(dirname(__DIR__).'/www/lib/class.erpapi_custom.php') && !class_exists('erpAPICustom')){ $app->Conf = $conf;
include_once dirname(__DIR__) . '/www/lib/class.erpapi_custom.php';
} }
if(empty($app->Conf)) { if (empty($app->DB) || empty($app->DB->connection)) {
$conf = new Config(); $app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport);
$app->Conf = $conf;
} }
if(empty($app->DB) || empty($app->DB->connection)) { if (!isset($app->erp) || !$app->erp) {
$app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport); if (class_exists('erpAPICustom')) {
} $erp = new erpAPICustom($app);
if(!isset($app->erp) || !$app->erp) { } else {
if (class_exists('erpAPICustom')) { $erp = new erpAPI($app);
$erp = new erpAPICustom($app); }
} else { $app->erp = $erp;
$erp = new erpAPI($app); }
} if (empty($app->remote)) {
//$remote = new Remote($app); if (is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')) {
$app->erp = $erp; if (!class_exists('RemoteCustom')) {
//$app->remote= $remote; require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php';
} }
if(empty($app->remote)) { $app->remote = new RemoteCustom($app);
if(is_file(dirname(__DIR__) . '/www/lib/class.remote_custom.php')) { } else {
if(!class_exists('RemoteCustom')){ $app->remote = new Remote($app);
require_once dirname(__DIR__) . '/www/lib/class.remote_custom.php';
} }
$app->remote = new RemoteCustom($app);
}
else {
$app->remote = new Remote($app);
}
} }
$app->erp->LogFile('Cronjob Artikeluebertragung Start'); $app->erp->LogFile('Cronjob Artikeluebertragung Start');
$app->DB->Update( $app->DB->Update(
"UPDATE `prozessstarter` "UPDATE `prozessstarter`
SET `mutexcounter` = `mutexcounter` + 1 SET `mutexcounter` = `mutexcounter` + 1
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();
} }
} }
$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']])) {
$anzChecked[$article['shop']] = 0;
}
if (!isset($lastids[$article['shop']])) {
$lastids[$article['shop']] = (int) $app->erp->GetKonfiguration(
'shopexport_artikeluebertragen_check_lastid_' . $article['shop']
);
}
$changed = $objShopexport->hasArticleHashChanged($article['artikel'], $article['shop']);
if ($changed['changed']) {
$app->DB->Insert(
sprintf(
'INSERT INTO `shopexport_artikeluebertragen` (`artikel`, `shop`, `check_nr`) VALUES (%d, %d, %d)',
$article['artikel'], $article['shop'], $lastids[$article['shop']]
)
);
$anzChanged[$article['shop']]++;
}
$anzChecked[$article['shop']]++;
$app->DB->Delete(
sprintf(
'DELETE FROM `shopexport_artikeluebertragen_check` WHERE `id` = %d',
$article['id']
)
);
$app->DB->Update(
sprintf(
"UPDATE `shopexport` SET `autosendarticle_last` = NOW() WHERE `id` = %d",
$article['shop']
)
);
} }
if(empty($anzChecked[$article['shop']])) { $app->erp->SetKonfigurationValue(
$anzChecked[$article['shop']] = 0; 'shopexport_artikeluebertragen_check_changed_' . $article['shop'],
$anzChanged[$article['shop']]
);
$app->erp->SetKonfigurationValue(
'shopexport_artikeluebertragen_check_checked_' . $article['shop'],
$anzChecked[$article['shop']]
);
if (method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) {
return;
} }
if(!isset($lastids[$article['shop']])) { $articles = $app->DB->SelectArr(
$lastids[$article['shop']] = (int)$app->erp->GetKonfiguration( 'SELECT `id`,`shop`,`artikel` FROM `shopexport_artikeluebertragen_check` ORDER BY `id` LIMIT 10'
'shopexport_artikeluebertragen_check_lastid_' . $article['shop']
);
}
$changed = $objShopexport->hasArticleHashChanged($article['artikel'], $article['shop']);
if($changed['changed']) {
$app->DB->Insert(
sprintf(
'INSERT INTO `shopexport_artikeluebertragen` (`artikel`, `shop`, `check_nr`) VALUES (%d, %d, %d)',
$article['artikel'], $article['shop'], $lastids[$article['shop']]
)
);
$anzChanged[$article['shop']]++;
}
$anzChecked[$article['shop']]++;
$app->DB->Delete(
sprintf(
'DELETE FROM `shopexport_artikeluebertragen_check` WHERE `id` = %d',
$article['id']
)
); );
$app->DB->Update( $app->DB->Update(
sprintf( "UPDATE `prozessstarter`
"UPDATE `shopexport` SET `autosendarticle_last` = NOW() WHERE `id` = %d",
$article['shop']
)
);
}
$app->erp->SetKonfigurationValue(
'shopexport_artikeluebertragen_check_changed_'.$article['shop'],
$anzChanged[$article['shop']]
);
$app->erp->SetKonfigurationValue(
'shopexport_artikeluebertragen_check_checked_'.$article['shop'],
$anzChecked[$article['shop']]
);
if(method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) {
return;
}
$articles = $app->DB->SelectArr(
'SELECT `id`,`shop`,`artikel` FROM `shopexport_artikeluebertragen_check` ORDER BY `id` LIMIT 10'
);
$app->DB->Update(
"UPDATE `prozessstarter`
SET `letzteausfuerhung`=NOW(), `mutex` = 1,`mutexcounter`=0 SET `letzteausfuerhung`=NOW(), `mutex` = 1,`mutexcounter`=0
WHERE `parameter` = 'artikeluebertragen'" WHERE `parameter` = 'artikeluebertragen'"
); );
} }
$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(
"UPDATE `prozessstarter` "UPDATE `prozessstarter`
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( sprintf(
sprintf( 'DELETE FROM `shopexport_artikeluebertragen` WHERE `id`= %d LIMIT 1',
'DELETE FROM `shopexport_artikeluebertragen` WHERE `id`= %d LIMIT 1', $row['id']
$row['id'] )
) );
);
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(
"UPDATE `prozessstarter` "UPDATE `prozessstarter`
SET `letzteausfuerhung`=NOW(), `mutex` = 1,`mutexcounter`=0 SET `letzteausfuerhung`=NOW(), `mutex` = 1,`mutexcounter`=0
WHERE `parameter` = 'artikeluebertragen'" WHERE `parameter` = 'artikeluebertragen'"
); );
}
$app->DB->free($shopartikel);
} }
$app->DB->free($shopartikel); if (method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) {
} return;
}
if(method_exists($app->erp, 'canRunCronjob') && !$app->erp->canRunCronjob(['artikeluebertragen'])) { $check = $app->DB->Select('SELECT COUNT(`id`) FROM `shopexport_artikeluebertragen`');
return;
}
//sleep(20); // das performance nicht total spinnt
$check = $app->DB->Select('SELECT COUNT(`id`) FROM `shopexport_artikeluebertragen`');
} }
$app->DB->Update( $app->DB->Update(
"UPDATE `prozessstarter` "UPDATE `prozessstarter`
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 = "";