83 lines
2.9 KiB
PHP
83 lines
2.9 KiB
PHP
<?php
|
|
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
|
$_SERVER['SERVER_PORT'] = 80;
|
|
|
|
include dirname(__FILE__).'/www/config/config.inc.php';
|
|
include dirname(__FILE__).'/www/images.inc.php';
|
|
include dirname(__FILE__).'/www/modules/privatesales/Sale.php';
|
|
|
|
$id_sale = 5383;
|
|
$id_cat = 8721860;
|
|
$sale = new Sale($id_sale);
|
|
$products = $sale->getProducts();
|
|
|
|
//echo "<pre>";var_dump($products);echo "</pre>";die();
|
|
|
|
$productsImages = Db::getInstance()->ExecuteS('
|
|
SELECT `id_image`, `id_product`
|
|
FROM `'._DB_PREFIX_.'image`
|
|
WHERE `id_product` IN ('.implode(',',$products).')
|
|
ORDER BY `id_image` ASC');
|
|
|
|
|
|
$dir = _PS_PROD_IMG_DIR_;
|
|
$type = ImageType::getImagesTypes('products');
|
|
/*$type = array();
|
|
$type[] = array('name' => 'thickbox');
|
|
$type[] = array('name' => 'small');
|
|
$type[] = array('name' => 'medium');
|
|
$type[] = array('name' => 'large');
|
|
$type[] = array('name' => 'home');*/
|
|
//echo "<pre>";var_dump($productsImages,$type);echo "</pre>";die();
|
|
$start_time = time();
|
|
$max_execution_time = 7200;
|
|
foreach ($productsImages AS $k => $image)
|
|
{
|
|
// delete old rezise image
|
|
if (!is_dir($dir)) {
|
|
continue;
|
|
}
|
|
$toDel = scandir($dir);
|
|
foreach ($toDel AS $d) {
|
|
foreach ($type AS $imageType) {
|
|
if (preg_match('/^[0-9]+\-[0-9]+\-'.$imageType['name'].'\.jpg$/', $d) OR preg_match('/^([[:lower:]]{2})\-default\-(.*)\.jpg$/', $d)) {
|
|
if (file_exists($dir.$d)) {
|
|
unlink($dir.$d);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$imageObj = new Image($image['id_image']);
|
|
$imageObj->id_product = $image['id_product'];
|
|
if (file_exists($dir.$imageObj->getImgFolder()))
|
|
{
|
|
$toDel = scandir($dir.$imageObj->getImgFolder());
|
|
foreach ($toDel AS $d) {
|
|
foreach ($type AS $imageType) {
|
|
if (preg_match('/^[0-9]+\-'.$imageType['name'].'\.jpg$/', $d)) {
|
|
if (file_exists($dir.$imageObj->getImgFolder().$d)) {
|
|
unlink($dir.$imageObj->getImgFolder().$d);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// regenerate new
|
|
if (file_exists($dir.$imageObj->getExistingImgPath().'.jpg')) {
|
|
foreach ($type AS $k => $imageType)
|
|
{
|
|
if (!file_exists($dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg')) {
|
|
if (!imageResize($dir.$imageObj->getExistingImgPath().'.jpg', $dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])))
|
|
$errors = true;
|
|
}
|
|
if (time() - $start_time > $max_execution_time - 4) { // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
|
|
return 'timeout';
|
|
}
|
|
}
|
|
}
|
|
if((int) $image['id_product'] % 100 == 0) {
|
|
echo $image['id_product']."\n";
|
|
}
|
|
} |