feat: enhance product URL validation logic in Cron class for better merchant URL handling
This commit is contained in:
@@ -224,9 +224,7 @@ class Clients
|
||||
$data[ $row['client_id'] ]['products'] = [ (int) $row['done'], (int) $row['total'] ];
|
||||
}
|
||||
|
||||
// Walidacja Merchant (cron_campaigns_product_alerts_merchant) dziala na kursorze klienta.
|
||||
// Pokazujemy postep per klient jako 0/1 albo 1/1 w aktualnym cyklu.
|
||||
$merchant_cursor_client_id = (int) \services\GoogleAdsApi::get_setting( 'cron_campaigns_product_alerts_last_client_id' );
|
||||
// Postep pobierania URL produktow z Merchant Center - per klient (przetworzone/wszystkie).
|
||||
$merchant_clients_ids = $mdb -> query(
|
||||
"SELECT id
|
||||
FROM clients
|
||||
@@ -238,16 +236,40 @@ class Clients
|
||||
ORDER BY id ASC"
|
||||
) -> fetchAll( \PDO::FETCH_COLUMN );
|
||||
|
||||
foreach ( (array) $merchant_clients_ids as $merchant_client_id )
|
||||
if ( !empty( $merchant_clients_ids ) )
|
||||
{
|
||||
$merchant_client_id = (int) $merchant_client_id;
|
||||
if ( $merchant_client_id <= 0 )
|
||||
$merchant_clients_ids_int = array_values( array_map( 'intval', $merchant_clients_ids ) );
|
||||
$merchant_progress_rows = $mdb -> query(
|
||||
"SELECT
|
||||
p.client_id,
|
||||
COUNT(*) AS total,
|
||||
SUM( CASE WHEN
|
||||
( TRIM( COALESCE( p.product_url, '' ) ) <> '' AND LOWER( TRIM( p.product_url ) ) NOT IN ( '0', '-', 'null' ) )
|
||||
OR COALESCE( p.merchant_url_not_found, 0 ) = 1
|
||||
THEN 1 ELSE 0 END ) AS processed
|
||||
FROM products p
|
||||
WHERE p.client_id IN (" . implode( ',', $merchant_clients_ids_int ) . ")
|
||||
AND TRIM( COALESCE( p.offer_id, '' ) ) <> ''
|
||||
GROUP BY p.client_id"
|
||||
) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
|
||||
foreach ( $merchant_progress_rows as $row )
|
||||
{
|
||||
continue;
|
||||
$cid = (int) $row['client_id'];
|
||||
$total = max( 1, (int) $row['total'] );
|
||||
$processed = (int) $row['processed'];
|
||||
$data[ $cid ]['merchant'] = [ $processed, $total ];
|
||||
}
|
||||
|
||||
$done = ( $merchant_cursor_client_id > 0 && $merchant_client_id <= $merchant_cursor_client_id ) ? 1 : 0;
|
||||
$data[ $merchant_client_id ]['merchant'] = [ $done, 1 ];
|
||||
// Klienci bez zadnych produktow z offer_id - oznacz jako 1/1
|
||||
$seen_merchant_ids = array_column( $merchant_progress_rows, 'client_id' );
|
||||
foreach ( $merchant_clients_ids_int as $cid )
|
||||
{
|
||||
if ( !in_array( $cid, $seen_merchant_ids ) )
|
||||
{
|
||||
$data[ $cid ]['merchant'] = [ 1, 1 ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$facebook_yesterday = date( 'Y-m-d', strtotime( '-1 day' ) );
|
||||
|
||||
@@ -211,6 +211,16 @@ class Cron
|
||||
TRIM(COALESCE(p.product_url, '')) = ''
|
||||
OR LOWER(TRIM(p.product_url)) IN ('0', '-', 'null')
|
||||
)
|
||||
AND (
|
||||
COALESCE(p.merchant_url_not_found, 0) = 0
|
||||
OR (
|
||||
COALESCE(p.merchant_url_not_found, 0) = 1
|
||||
AND (
|
||||
p.merchant_url_last_check IS NULL
|
||||
OR p.merchant_url_last_check < DATE_SUB(NOW(), INTERVAL 7 DAY)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
ORDER BY c.id ASC
|
||||
LIMIT 1"
|
||||
@@ -720,13 +730,19 @@ class Cron
|
||||
return [];
|
||||
}
|
||||
|
||||
$retry_after_days = 7;
|
||||
$sql = 'SELECT p.id AS product_id, p.offer_id '
|
||||
. 'FROM products p '
|
||||
. 'WHERE p.client_id = ' . $client_id . ' '
|
||||
. 'AND TRIM( COALESCE( p.offer_id, \'\' ) ) <> \'\' '
|
||||
. 'AND p.product_url IS NULL '
|
||||
. 'AND COALESCE( p.merchant_url_not_found, 0 ) = 0 '
|
||||
. 'ORDER BY p.id ASC '
|
||||
. 'AND ( TRIM( COALESCE( p.product_url, \'\' ) ) = \'\' OR LOWER( TRIM( p.product_url ) ) IN ( \'0\', \'-\', \'null\' ) ) '
|
||||
. 'AND ( '
|
||||
. 'COALESCE( p.merchant_url_not_found, 0 ) = 0 '
|
||||
. 'OR ( COALESCE( p.merchant_url_not_found, 0 ) = 1 '
|
||||
. 'AND ( p.merchant_url_last_check IS NULL '
|
||||
. 'OR p.merchant_url_last_check < DATE_SUB( NOW(), INTERVAL ' . $retry_after_days . ' DAY ) ) ) '
|
||||
. ') '
|
||||
. 'ORDER BY COALESCE( p.merchant_url_not_found, 0 ) ASC, p.id ASC '
|
||||
. 'LIMIT ' . $limit;
|
||||
|
||||
$rows = $mdb -> query( $sql ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
@@ -867,7 +883,7 @@ class Cron
|
||||
FROM products
|
||||
WHERE client_id = :client_id
|
||||
AND TRIM( COALESCE( offer_id, '' ) ) <> ''
|
||||
AND product_url IS NULL
|
||||
AND ( TRIM( COALESCE( product_url, '' ) ) = '' OR LOWER( TRIM( product_url ) ) IN ( '0', '-', 'null' ) )
|
||||
AND COALESCE( merchant_url_not_found, 0 ) = 1",
|
||||
[ ':client_id' => $client_id ]
|
||||
) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
|
||||
Reference in New Issue
Block a user