bebeboutik/modules/philea_magistor/cron.php

115 lines
3.4 KiB
PHP
Raw Permalink Normal View History

<?php
2016-09-07 15:03:58 +02:00
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../config/config.inc.php';
if(isset($_SERVER['REMOTE_ADDR'])) {
2016-11-23 12:57:33 +01:00
exit;
}
2016-11-23 12:57:33 +01:00
2016-11-23 15:19:50 +01:00
// CHECKING RUNNING OF CRON_SALE_CACHE
$fileName = 'cron_sale_cache.php';
$output = shell_exec("ps -ax | grep $fileName | wc -l");
if($output > 2){
exit;
}
set_time_limit(600);
2017-10-17 16:22:24 +02:00
// Default behaviour (state 0 to 4)
if($row = Db::getInstance()->getRow('
2016-11-23 15:19:50 +01:00
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `status` = 0
ORDER BY `date_add` ASC
')) {
2016-11-23 15:19:50 +01:00
// CHECKING ASSOCIATED PRODUCTS
$associated_products = Db::getInstance()->getValue('
SELECT COUNT(`id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_sale` = '.(int) $row['id_sale'].'
');
if($associated_products > 0) {
2016-11-23 12:57:33 +01:00
// SEND ART01
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 1
WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1
');
system('cd '.dirname(__FILE__).'/script && php send_article.php '.(int) $row['id_sale']);
sleep(20);
2017-07-25 16:56:59 +02:00
// SEND REC01
2016-11-23 12:57:33 +01:00
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 2
WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1
');
2017-07-25 16:56:59 +02:00
system('cd '.dirname(__FILE__).'/script && php send_recep_orderform.php '.(int) $row['id_sale']);
2016-11-23 15:19:50 +01:00
}
}
if($row = Db::getInstance()->getRow('
2016-11-23 12:57:33 +01:00
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `status` = 3
ORDER BY `date_add` ASC
')) {
2016-11-23 12:57:33 +01:00
// SEND CDC02
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 4
WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1
');
system('cd '.dirname(__FILE__).'/script && php send_commande.php '.(int) $row['id_sale']);
2017-10-17 16:22:24 +02:00
}
// Particular behaviour (state 5 to 9)
if($row = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `status` = 5
ORDER BY `date_add` ASC
')) {
// CHECKING ASSOCIATED PRODUCTS
$associated_products = Db::getInstance()->getValue('
SELECT COUNT(`id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_sale` = '.(int) $row['id_sale'].'
');
if($associated_products > 0) {
// SEND ART01
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 6
WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1
');
system('cd '.dirname(__FILE__).'/script && php send_article_after.php '.(int) $row['id_sale']);
sleep(20);
// SEND REC01
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 7
WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1
');
system('cd '.dirname(__FILE__).'/script && php send_recep_orderform_after.php '.(int) $row['id_sale']);
}
}
if($row = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `status` = 8
ORDER BY `date_add` ASC
')) {
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 9
WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1
');
2017-11-30 11:46:34 +01:00
system('cd '.dirname(__FILE__).'/script && php send_commande_after.php '.(int) $row['id_sale'].' '.(int) $row['mode']);
}