update
This commit is contained in:
@@ -132,23 +132,6 @@ class Cron
|
||||
$products_temp_rows_total += (int) self::rebuild_products_temp_for_client( (int) $client['id'] );
|
||||
}
|
||||
|
||||
$xml_feed_report = null;
|
||||
if ( !empty( $client['xml_feed_url'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$xml_feed_report = \services\XmlFeedImporter::import_for_client( (int) $client['id'] );
|
||||
if ( !empty( $xml_feed_report['errors'] ) )
|
||||
{
|
||||
$products_errors = array_merge( $products_errors, (array) $xml_feed_report['errors'] );
|
||||
}
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
$products_errors[] = 'XML feed import: ' . $e -> getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$errors = array_merge( $campaign_errors, $products_errors );
|
||||
|
||||
self::output_cron_response( [
|
||||
@@ -169,7 +152,6 @@ class Cron
|
||||
'products_fetch_skipped_reasons' => array_keys( $products_fetch_skipped_reasons ),
|
||||
'history_30_products' => $history_30_products_total,
|
||||
'products_temp_rows' => $products_temp_rows_total,
|
||||
'xml_feed' => $xml_feed_report,
|
||||
'errors' => $errors
|
||||
] );
|
||||
}
|
||||
@@ -567,6 +549,87 @@ class Cron
|
||||
] );
|
||||
}
|
||||
|
||||
static public function cron_xml_feed_import()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
self::$current_cron_action = __FUNCTION__;
|
||||
self::touch_cron_invocation( __FUNCTION__ );
|
||||
|
||||
$clients_not_deleted_sql_c = self::sql_clients_not_deleted( 'c' );
|
||||
$client_id = (int) \S::get( 'client_id' );
|
||||
$debug_offer_id = trim( (string) \S::get( 'debug_offer_id' ) );
|
||||
if ( $debug_offer_id === '' )
|
||||
{
|
||||
$debug_offer_id = trim( (string) \S::get( 'offer_id' ) );
|
||||
}
|
||||
|
||||
$params = [];
|
||||
$where_client = '';
|
||||
if ( $client_id > 0 )
|
||||
{
|
||||
$where_client = 'AND c.id = :client_id';
|
||||
$params[':client_id'] = $client_id;
|
||||
}
|
||||
|
||||
$client = $mdb -> query(
|
||||
"SELECT c.id, c.name, c.xml_feed_url, c.xml_feed_last_sync_at
|
||||
FROM clients c
|
||||
WHERE " . $clients_not_deleted_sql_c . "
|
||||
AND COALESCE(c.active, 0) = 1
|
||||
AND TRIM(COALESCE(c.xml_feed_url, '')) <> ''
|
||||
" . $where_client . "
|
||||
ORDER BY CASE WHEN c.xml_feed_last_sync_at IS NULL THEN 0 ELSE 1 END ASC,
|
||||
c.xml_feed_last_sync_at ASC,
|
||||
c.id ASC
|
||||
LIMIT 1",
|
||||
$params
|
||||
) -> fetch( \PDO::FETCH_ASSOC );
|
||||
|
||||
if ( !$client )
|
||||
{
|
||||
self::output_cron_response( [
|
||||
'result' => $client_id > 0 ? 'Nie znaleziono aktywnego klienta z ustawionym XML Feed URL.' : 'Brak aktywnych klientow z ustawionym XML Feed URL.',
|
||||
'client_id' => $client_id ?: null,
|
||||
'errors' => []
|
||||
] );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$report = \services\XmlFeedImporter::import_for_client(
|
||||
(int) $client['id'],
|
||||
[ 'debug_offer_id' => $debug_offer_id ]
|
||||
);
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
self::output_cron_response( [
|
||||
'result' => 'Import XML feed zakonczony bledem.',
|
||||
'client_id' => (int) $client['id'],
|
||||
'client_name' => (string) ( $client['name'] ?? '' ),
|
||||
'feed_url' => (string) ( $client['xml_feed_url'] ?? '' ),
|
||||
'errors' => [ $e -> getMessage() ]
|
||||
] );
|
||||
}
|
||||
|
||||
$errors = (array) ( $report['errors'] ?? [] );
|
||||
self::output_cron_response( [
|
||||
'result' => empty( $errors ) ? 'Import XML feed zakonczony.' : 'Import XML feed zakonczony z bledami.',
|
||||
'client_id' => (int) $client['id'],
|
||||
'client_name' => (string) ( $client['name'] ?? '' ),
|
||||
'feed_url' => (string) ( $report['feed_url'] ?? ( $client['xml_feed_url'] ?? '' ) ),
|
||||
'fetched' => (int) ( $report['fetched'] ?? 0 ),
|
||||
'updated' => (int) ( $report['updated'] ?? 0 ),
|
||||
'inserted' => (int) ( $report['inserted'] ?? 0 ),
|
||||
'skipped' => (int) ( $report['skipped'] ?? 0 ),
|
||||
'peak_memory_mb' => (float) ( $report['peak_memory_mb'] ?? 0 ),
|
||||
'duration_ms' => (int) ( $report['duration_ms'] ?? 0 ),
|
||||
'debug_offer' => $report['debug_offer'] ?? null,
|
||||
'errors' => $errors
|
||||
] );
|
||||
}
|
||||
|
||||
static public function cron_products_urls()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
Reference in New Issue
Block a user