bebeboutik/modules/philea_magistor/cron_auto_sync.php
2016-09-06 15:32:52 +02: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_magistor_auto_sync` pmas
LEFT JOIN `'._DB_PREFIX_.'philea_magistor_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_magistor_sync`
WHERE `id_sale` = ' . (int) $id_sale . '
AND `status` = 3
')){
continue;
}
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'philea_magistor_sync`
VALUES (
DEFAULT,
'.(int) $id_sale.',
3,
NOW()
)
');
$sql = '
UPDATE `'._DB_PREFIX_.'philea_magistor_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);
}
}