Regen for a category
This commit is contained in:
parent
789b136720
commit
85c8d7d699
@ -1,28 +1,89 @@
|
||||
<?php
|
||||
ini_set('memory_limit', '4096M');
|
||||
ini_set('max_execution_time', 0);
|
||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
include dirname(__FILE__).'/www/config/config.inc.php';
|
||||
|
||||
$min_id_product = Db::getInstance()->getValue('
|
||||
SELECT MIN(`id_product`) FROM `'._DB_PREFIX_.'product` WHERE `date_add` > DATE_SUB(NOW(), INTERVAL 10 DAY)
|
||||
');
|
||||
Db::getInstance()->ExecuteS('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
|
||||
WHERE `id_product` >= '.$min_id_product.'
|
||||
');
|
||||
$longopts = array(
|
||||
'verbose',
|
||||
'dry-run',
|
||||
'debug',
|
||||
'category:',
|
||||
);
|
||||
$shortopts = "";
|
||||
$options = getopt($shortopts, $longopts);
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
|
||||
SELECT p.id_product, IFNULL(
|
||||
(
|
||||
SELECT s.id_sale
|
||||
FROM `'._DB_PREFIX_.'privatesale_category` s
|
||||
WHERE s.`id_category` = p.`id_category_default`
|
||||
LIMIT 1)
|
||||
, 0
|
||||
// Options
|
||||
$optVerbose = false;
|
||||
if (isset($options['verbose'])) {
|
||||
$optVerbose = true;
|
||||
}
|
||||
|
||||
$optTest = false;
|
||||
if (isset($options['dry-run'])) {
|
||||
$optTest = true;
|
||||
}
|
||||
|
||||
$optDebug = false;
|
||||
if (isset($options['debug'])) {
|
||||
$optDebug = true;
|
||||
}
|
||||
|
||||
$optAuto = false;
|
||||
if (count($options) > 0) {
|
||||
$category = false;
|
||||
if (isset($options['category'])) {
|
||||
$category = $options['category'];
|
||||
}
|
||||
if (empty($category)) {
|
||||
echo "No category selected\n";
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$optAuto = true;
|
||||
}
|
||||
|
||||
if ($optAuto === true) {
|
||||
$min_id_product = Db::getInstance()->getValue('
|
||||
SELECT MIN(`id_product`) FROM `'._DB_PREFIX_.'product` WHERE `date_add` > DATE_SUB(NOW(), INTERVAL 10 DAY)
|
||||
');
|
||||
Db::getInstance()->ExecuteS('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
|
||||
WHERE `id_product` >= '.$min_id_product.'
|
||||
');
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
|
||||
SELECT p.id_product, IFNULL(
|
||||
(
|
||||
SELECT s.id_sale
|
||||
FROM `'._DB_PREFIX_.'privatesale_category` s
|
||||
WHERE s.`id_category` = p.`id_category_default`
|
||||
LIMIT 1)
|
||||
, 0
|
||||
)
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_product` >= '.$min_id_product.'
|
||||
)
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_product` >= '.$min_id_product.'
|
||||
)
|
||||
');
|
||||
');
|
||||
}
|
||||
else {
|
||||
Db::getInstance()->ExecuteS('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_ps_cache` WHERE `id_product` IN
|
||||
(
|
||||
SELECT `id_product` FROM `'._DB_PREFIX_.'product` WHERE `id_category_default` = '.$category.'
|
||||
)
|
||||
');
|
||||
$sale = Db::getInstance()->getValue('
|
||||
SELECT s.id_sale FROM `'._DB_PREFIX_.'privatesale_category` s
|
||||
WHERE s.`id_category` = '.$category.'
|
||||
');
|
||||
if ($sale !== false) {
|
||||
Db::getInstance()->executeS('
|
||||
INSERT LOW_PRIORITY INTO `'._DB_PREFIX_.'product_ps_cache`
|
||||
(
|
||||
SELECT p.`id_product`, '.$sale.'
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
WHERE p.`id_category_default` = '.$category.'
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user