// Small improvement on pscleaner
This commit is contained in:
1 parent
b5748e8a46
commit
d441725ccd
1 file changed
+8
-10
@@ -49,7 +49,7 @@ class PSCleaner extends Module
|
|||||||
{
|
{
|
||||||
$html = '<h2>'.$this->l('Be really careful with this tool - There is no possible rollback!').'</h2>';
|
$html = '<h2>'.$this->l('Be really careful with this tool - There is no possible rollback!').'</h2>';
|
||||||
if (Tools::isSubmit('submitCheckAndFix'))
|
if (Tools::isSubmit('submitCheckAndFix'))
|
||||||
$html .= (count($logs = self::checkAndFix()) ? print_r($logs, true) : $this->l('Nothing that need to be cleaned')).'<br /><br />';
|
$html .= $this->displayConfirmation((count($logs = self::checkAndFix()) ? '<pre>'.print_r($logs, true).'</pre>' : $this->l('Nothing that need to be cleaned')).'<br /><br />');
|
||||||
if (Tools::isSubmit('submitTruncateCatalog'))
|
if (Tools::isSubmit('submitTruncateCatalog'))
|
||||||
{
|
{
|
||||||
self::truncate('catalog');
|
self::truncate('catalog');
|
||||||
@@ -291,7 +291,7 @@ class PSCleaner extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
// _lang table cleaning
|
// _lang table cleaning
|
||||||
$tables = Db::getInstance()->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'%_\\_lang"');
|
$tables = Db::getInstance()->executeS('SHOW TABLES LIKE "'.preg_replace('/([%_])/', '\\$1', _DB_PREFIX_).'%_\\_lang"');
|
||||||
foreach ($tables as $table)
|
foreach ($tables as $table)
|
||||||
{
|
{
|
||||||
$table_lang = current($table);
|
$table_lang = current($table);
|
||||||
@@ -310,7 +310,7 @@ class PSCleaner extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
// _shop table cleaning
|
// _shop table cleaning
|
||||||
$tables = Db::getInstance()->executeS('SHOW TABLES LIKE "'._DB_PREFIX_.'%_\\_shop"');
|
$tables = Db::getInstance()->executeS('SHOW TABLES LIKE "'.preg_replace('/([%_])/', '\\$1', _DB_PREFIX_).'%_\\_shop"');
|
||||||
foreach ($tables as $table)
|
foreach ($tables as $table)
|
||||||
{
|
{
|
||||||
$table_shop = current($table);
|
$table_shop = current($table);
|
||||||
@@ -348,9 +348,9 @@ class PSCleaner extends Module
|
|||||||
case 'catalog':
|
case 'catalog':
|
||||||
$id_home = Configuration::get('PS_HOME_CATEGORY');
|
$id_home = Configuration::get('PS_HOME_CATEGORY');
|
||||||
$id_root = Configuration::get('PS_ROOT_CATEGORY');
|
$id_root = Configuration::get('PS_ROOT_CATEGORY');
|
||||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category` WHERE id_category NOT IN ('.(int)$id_home.', '.(int)$id_root.')');
|
$db->execute('DELETE FROM `'._DB_PREFIX_.'category` WHERE id_category NOT IN ('.(int)$id_home.', '.(int)$id_root.')');
|
||||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_lang` WHERE id_category NOT IN ('.(int)$id_home.', '.(int)$id_root.')');
|
$db->execute('DELETE FROM `'._DB_PREFIX_.'category_lang` WHERE id_category NOT IN ('.(int)$id_home.', '.(int)$id_root.')');
|
||||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_shop` WHERE id_category NOT IN ('.(int)$id_home.', '.(int)$id_root.')');
|
$db->execute('DELETE FROM `'._DB_PREFIX_.'category_shop` WHERE id_category NOT IN ('.(int)$id_home.', '.(int)$id_root.')');
|
||||||
foreach (scandir(_PS_CAT_IMG_DIR_) as $dir)
|
foreach (scandir(_PS_CAT_IMG_DIR_) as $dir)
|
||||||
if (preg_match('/^[0-9]+(\-(.*))?\.jpg$/', $dir))
|
if (preg_match('/^[0-9]+(\-(.*))?\.jpg$/', $dir))
|
||||||
unlink(_PS_CAT_IMG_DIR_.$dir);
|
unlink(_PS_CAT_IMG_DIR_.$dir);
|
||||||
@@ -494,9 +494,10 @@ class PSCleaner extends Module
|
|||||||
$this->clearAllCaches();
|
$this->clearAllCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not called yet
|
||||||
public static function cleanAndOptimize()
|
public static function cleanAndOptimize()
|
||||||
{
|
{
|
||||||
// Clean (carts...)
|
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'cart` WHERE id_cart NOT IN (SELECT id_cart FROM `'._DB_PREFIX_.'cart`) AND date_add < "'.pSQL(date('Y-m-d', strtotime('-1 month'))).'"');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function bulle($array)
|
protected static function bulle($array)
|
||||||
@@ -508,16 +509,13 @@ class PSCleaner extends Module
|
|||||||
$sorted = true;
|
$sorted = true;
|
||||||
for ($i = 0; $i < $size - 1; ++$i)
|
for ($i = 0; $i < $size - 1; ++$i)
|
||||||
for ($j = $i + 1; $j < $size; ++$j)
|
for ($j = $i + 1; $j < $size; ++$j)
|
||||||
{
|
|
||||||
if ($array[$i][2] == $array[$j][0])
|
if ($array[$i][2] == $array[$j][0])
|
||||||
{
|
{
|
||||||
// var_dump(array($array[$i], $array[$j]));
|
|
||||||
$tmp = $array[$i];
|
$tmp = $array[$i];
|
||||||
$array[$i] = $array[$j];
|
$array[$i] = $array[$j];
|
||||||
$array[$j] = $tmp;
|
$array[$j] = $tmp;
|
||||||
$sorted = false;
|
$sorted = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user