bebeboutik/modules/philea_magistor/cron_auto_sync.php
Marion Muszynski 5686b5395c bug fixes
2016-11-03 17:20:09 +01:00

52 lines
1.3 KiB
PHP

<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../config/config.inc.php';
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
set_time_limit(600);
$auto_sync_sales = Db::getInstance()->executeS('
SELECT DISTINCT pmas.`id_sale`
FROM `'._DB_PREFIX_.'philea_auto_sync` pmas
LEFT JOIN `'._DB_PREFIX_.'philea_sync` pms
ON pms.`id_sale` = pmas.`id_sale`
LEFT JOIN `'._DB_PREFIX_.'privatesale` p
ON p.`id_sale` = pmas.`id_sale`
WHERE pms.`status` >= 2
AND pmas.active = 1
AND p.date_start <= NOW()
AND p.date_end >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
');
if ($auto_sync_sales && count($auto_sync_sales))
{
foreach ($auto_sync_sales as $sale) {
$id_sale = (int) $sale['id_sale'];
if (Db::getInstance()->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `id_sale` = ' . (int) $id_sale . '
AND `status` = 3
')){
continue;
}
// Db::getInstance()->execute('
// INSERT INTO `'._DB_PREFIX_.'philea_sync`
// VALUES (
// DEFAULT,
// '.(int) $id_sale.',
// 3,
// NOW()
// )
// ');
$sql = '
UPDATE `'._DB_PREFIX_.'philea_auto_sync`
SET `last_sent` = NOW()
WHERE `id_sale` = ' . (int) $id_sale . '
LIMIT 1';
Db::getInstance()->execute($sql);
system('cd '.dirname(__FILE__).'/script && php send_commande.php '.(int) $id_sale);
sleep(10);
}
}