Skip to content

Commit

Permalink
Merge pull request #4 from SpiriitLabs/dev
Browse files Browse the repository at this point in the history
Fix trad + bump v1.0.1
  • Loading branch information
RaphaelSpiriit authored Oct 9, 2023
2 parents 1058f78 + 0663a64 commit c716bd9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
11 changes: 5 additions & 6 deletions classes/cartCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ public function processDelete($id_carts)
foreach ($tables as $table) {
$res &= $this->db->delete(bqSQL($table), 'id_cart IN (' . pSQL($carts_list) . ')');
if ($affected_rows = $this->db->Affected_Rows()) {
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . bqSQL($table));
$this->output[$table] = (int) $affected_rows;
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . bqSQL($table));
}
$this->output[$table] = (int) $this->db->numRows();
}

return $res;
Expand Down Expand Up @@ -170,7 +169,7 @@ public function createDummyCarts($nb = 50)
}
}

Context::getContext()->controller->confirmations[] = $this->module->l(sprintf('%d cart(s) successfully created.', $nb), 'cartCleaner');
Context::getContext()->controller->confirmations[] = sprintf($this->module->l('%d cart(s) successfully created.', 'cartCleaner'), $nb);
}

/**
Expand All @@ -179,12 +178,12 @@ public function createDummyCarts($nb = 50)
public function cleanOrphans()
{
$res = true;
$this->output[$this->module->l('Orphans cleaned')] = 0;
$this->output[$this->module->l('Orphans cleaned', 'cartCleaner')] = 0;

$res &= Db::getInstance()->delete('cart_product', 'id_cart NOT IN (SELECT id_cart FROM ' . _DB_PREFIX_ . 'cart)');
$this->output[$this->module->l('Orphans cleaned')] += (int) $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'cartCleaner')] += (int) $this->db->numRows();
$res &= Db::getInstance()->delete('cart', 'id_cart NOT IN (SELECT DISTINCT(id_cart) FROM ' . _DB_PREFIX_ . 'cart_product)');
$this->output[$this->module->l('Orphans cleaned')] += (int) $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'cartCleaner')] += (int) $this->db->numRows();

$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'cart_product');
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'cart');
Expand Down
2 changes: 1 addition & 1 deletion classes/customerCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ public function createDummyCustomers($nb = 50)
$address->save();
}

Context::getContext()->controller->confirmations[] = $this->module->l(sprintf('%d customer(s) successfully created.', $nb), 'customerCleaner');
Context::getContext()->controller->confirmations[] = sprintf($this->module->l('%d customer(s) successfully created.', 'customerCleaner'), $nb);
}
}
4 changes: 2 additions & 2 deletions classes/miscCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function cleanEmails($date_from = null, $date_to = null)

if ($deleteQuery) {
$this->context->controller->confirmations[] = $this->module->l('Success!', 'miscCleaner');
$this->context->controller->confirmations[] = sprintf($this->module->l('%s mail(s) deleted.'), $nbDeleted);
$this->context->controller->confirmations[] = sprintf($this->module->l('%s mail(s) deleted.', 'miscCleaner'), $nbDeleted);

return;
}
Expand Down Expand Up @@ -548,7 +548,7 @@ private function clearAllCachesAndTmp()
Tools::deleteDirectory(_PS_TMP_IMG_DIR_, false);
file_put_contents(_PS_TMP_IMG_DIR_ . 'index.php', $index);
}

Context::getContext()->smarty->clearAllCache();

if ($nb_files > 1) {
Expand Down
25 changes: 12 additions & 13 deletions classes/orderCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ public function processDelete($id_orders)
}

$res &= $this->db->delete(bqSQL($table), 'id_order IN (' . pSQL($orders_list) . ')');
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . bqSQL($table));

$this->output[$table] = $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . bqSQL($table));
}

return $res;
Expand Down Expand Up @@ -236,7 +235,7 @@ public function createDummyOrders($nb = 50)
$history->save();
}

Context::getContext()->controller->confirmations[] = sprintf('%d order(s) successfully created.', $nb);
Context::getContext()->controller->confirmations[] = sprintf($this->module->l('%d order(s) successfully created.', 'orderCleaner'), $nb);
}

/***********************************************************************************************************************************************
Expand All @@ -250,43 +249,43 @@ public function cleanOrphans()
{
$tables = self::getOrdersRelatedTables();
$res = true;
$this->output[$this->module->l('Orphans cleaned')] = 0;
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] = 0;
foreach ($tables as $table) {
if ($table == 'orders') {
$res &= Db::getInstance()->delete('order_payment', 'order_reference NOT IN (SELECT reference FROM ' . _DB_PREFIX_ . bqSQL($table) . ')');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'order_payment');
$res &= Db::getInstance()->delete('cart_product', 'id_cart NOT IN (SELECT id_cart FROM ' . _DB_PREFIX_ . 'cart)');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'cart_product');
continue;
} elseif ($table == 'order_detail') {
$res &= Db::getInstance()->delete('order_detail_tax', 'id_order_detail NOT IN (SELECT id_order_detail FROM ' . _DB_PREFIX_ . bqSQL($table) . ')');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'order_detail_tax');
} elseif ($table == 'order_invoice') {
$res &= Db::getInstance()->delete('order_invoice_payment', 'id_order_invoice NOT IN (SELECT id_order_invoice FROM ' . _DB_PREFIX_ . bqSQL($table) . ')');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'order_invoice_payment');
$res &= Db::getInstance()->delete('order_invoice_tax', 'id_order_invoice NOT IN (SELECT id_order_invoice FROM ' . _DB_PREFIX_ . bqSQL($table) . ')');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'order_invoice_tax');
} elseif ($table == 'order_return') {
$res &= Db::getInstance()->delete('order_return_detail', 'id_order_return NOT IN (SELECT id_order_return FROM ' . _DB_PREFIX_ . bqSQL($table) . ')');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'order_return_detail');
} elseif ($table == 'order_slip') {
$res &= Db::getInstance()->delete('order_slip_detail', 'id_order_slip NOT IN (SELECT id_order_slip FROM ' . _DB_PREFIX_ . bqSQL($table) . ')');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'order_slip_detail');
} elseif ($table == 'message') {
$res &= Db::getInstance()->delete('message_readed', 'id_message NOT IN (SELECT id_message FROM ' . _DB_PREFIX_ . bqSQL($table) . ')');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . 'message_readed');
}

$res &= Db::getInstance()->delete(bqSQL($table), 'id_order NOT IN (SELECT id_order FROM ' . _DB_PREFIX_ . 'orders)');
$this->output[$this->module->l('Orphans cleaned')] += $this->db->numRows();
$this->output[$this->module->l('Orphans cleaned', 'orderCleaner')] += $this->db->numRows();
$this->db->execute('ANALYZE TABLE ' . _DB_PREFIX_ . bqSQL($table));
}

Expand Down
6 changes: 3 additions & 3 deletions classes/productCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function createDummyProducts($nb = 50)
{
for ($i = 1; $i <= $nb; ++$i) {
$rand_str = substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyz', 5)), 0, 5);
$name = sprintf('Product generated %d', rand(100, 99999));
$name = sprintf($this->module->l('Product generated %d', 'productCleaner'), rand(100, 99999));

$product = new Product();
$product->name = $this->createMultiLangField($name);
Expand All @@ -164,13 +164,13 @@ public function createDummyProducts($nb = 50)

$categories = array_column(Category::getSimpleCategoriesWithParentInfos($this->lang->id), 'id_category');
$default_category = $categories[array_rand($categories)];
$categories = [Configuration::get('PS_HOME_CATEGORY'), $default_category];
$categories = [$default_category];// Can add more id's of categories id needed
$product->addToCategories($categories);
$product->id_category_default = $default_category;
$product->update();
}

Context::getContext()->controller->confirmations[] = sprintf('%d product(s) successfully created.', $nb);
Context::getContext()->controller->confirmations[] = sprintf($this->module->l('%d product(s) successfully created.', 'productCleaner'), $nb);
}

/***********************************************************************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>prestaclean</name>
<displayName><![CDATA[Prestashop Cleaner and Maintenance toolkit]]></displayName>
<version><![CDATA[1.0.0]]></version>
<version><![CDATA[1.0.1]]></version>
<description><![CDATA[Keep your Prestashop database and files clean, get out of old logs, clean up unwanted orders and more]]></description>
<author><![CDATA[Spiriit]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion prestaclean.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()
{
$this->name = 'prestaclean';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->version = '1.0.1';
$this->author = 'Spiriit';
$this->need_instance = 0;
$this->bootstrap = true;
Expand Down
7 changes: 6 additions & 1 deletion translations/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

global $_MODULE;
$_MODULE = array();
$_MODULE['<{prestaclean}prestashop>prestaclean_0014be3e27e16d35e1440eb29471127e'] = 'Nettoyeur Prestashop & Maintenance';
$_MODULE['<{prestaclean}prestashop>prestaclean_0014be3e27e16d35e1440eb29471127e'] = 'Nettoyeur Prestashop et Maintenance';
$_MODULE['<{prestaclean}prestashop>prestaclean_29f9adc8233ddc879efe39e25d4bac3d'] = 'Gardez votre base de données PrestaShop saine, supprimez les logs et nettoyez vos commandes produits et plus encore';
$_MODULE['<{prestaclean}prestashop>prestaclean_7b65e9c0a50646a6268d973d14175a35'] = 'Je comprend que cette action est irréversible, continuer ?';
$_MODULE['<{prestaclean}prestashop>prestaclean_979f268037f916ddd4701b72865726b2'] = 'Commandes supprimés avec succès';
Expand All @@ -11,21 +11,26 @@
$_MODULE['<{prestaclean}prestashop>productcleaner_402e7a087747cb56c718bde84651f96a'] = 'Succès!';
$_MODULE['<{prestaclean}prestashop>productcleaner_67c7fcdf5aec50e7fe016943ec2aefa1'] = '%s produit(s) supprimé(s)';
$_MODULE['<{prestaclean}prestashop>productcleaner_7e524ff51296689fdf2f3a9bb966b67c'] = 'Une erreur s\'est produite pendant la suppression';
$_MODULE['<{prestaclean}prestashop>productcleaner_7f298b04ab392872b5f132e199a994b8'] = 'Produit généré num %d';
$_MODULE['<{prestaclean}prestashop>productcleaner_181ba1a9e1a38f1a83277046cdbbc2bc'] = '%d produit(s) créés avec succès.';
$_MODULE['<{prestaclean}prestashop>cartcleaner_94888232d4efddc42e39814bbfcf63fb'] = 'Rien a supprimer';
$_MODULE['<{prestaclean}prestashop>cartcleaner_402e7a087747cb56c718bde84651f96a'] = 'Succès';
$_MODULE['<{prestaclean}prestashop>cartcleaner_7194367ccfba55352c9bbad19c538c4a'] = '%s: %d.';
$_MODULE['<{prestaclean}prestashop>cartcleaner_7e524ff51296689fdf2f3a9bb966b67c'] = 'Une erreur s\'est produite pendant le processus';
$_MODULE['<{prestaclean}prestashop>cartcleaner_82fa59aff897e76fdeb5568417b1443e'] = 'Pas assez de données de base pour créer des paniers fictifs(clients, adresses, transporteurs)';
$_MODULE['<{prestaclean}prestashop>cartcleaner_f89ca3ec5e8a5f47ea13319c4b9edc04'] = '%d panier(s) supprimés avec succès.';
$_MODULE['<{prestaclean}prestashop>cartcleaner_e1c99270974d8dbbe03069eecda6f70d'] = 'Données orphelines nettoyés';
$_MODULE['<{prestaclean}prestashop>customercleaner_94888232d4efddc42e39814bbfcf63fb'] = 'Rien a supprimer';
$_MODULE['<{prestaclean}prestashop>customercleaner_402e7a087747cb56c718bde84651f96a'] = 'Succès!';
$_MODULE['<{prestaclean}prestashop>customercleaner_fa4173f2ac8d6aaf560406fd3f4a7b27'] = '%s client(s) supprimé(s)';
$_MODULE['<{prestaclean}prestashop>customercleaner_7e524ff51296689fdf2f3a9bb966b67c'] = 'Une erreur s\'est produite pendant le processus';
$_MODULE['<{prestaclean}prestashop>customercleaner_ad8b2d7d8ce2f4a7da2e575a4b34ba15'] = '%d client(s) créés avec succès.';
$_MODULE['<{prestaclean}prestashop>ordercleaner_94888232d4efddc42e39814bbfcf63fb'] = 'Rien a supprimer';
$_MODULE['<{prestaclean}prestashop>ordercleaner_402e7a087747cb56c718bde84651f96a'] = 'Succès!';
$_MODULE['<{prestaclean}prestashop>ordercleaner_7194367ccfba55352c9bbad19c538c4a'] = '%s: %d.';
$_MODULE['<{prestaclean}prestashop>ordercleaner_7e524ff51296689fdf2f3a9bb966b67c'] = 'Une erreur s\'est produite pendant le processus';
$_MODULE['<{prestaclean}prestashop>ordercleaner_3e82cc6a41a49e2e3b499ca4a101ff70'] = 'Pas assez de données de base pour créer des commandes fictives(clients, adresses, transporteurs, status de commandes)';
$_MODULE['<{prestaclean}prestashop>ordercleaner_2c4950fee01916da7d6d516b853cc2d5'] = '%d commande(s) créés avec succès.';
$_MODULE['<{prestaclean}prestashop>ordercleaner_e1c99270974d8dbbe03069eecda6f70d'] = 'Données orphelines nettoyés';
$_MODULE['<{prestaclean}prestashop>misccleaner_402e7a087747cb56c718bde84651f96a'] = 'Succès!';
$_MODULE['<{prestaclean}prestashop>misccleaner_9cfa52679494dd160e5696e9db24d100'] = '%s email(s) supprimés.';
Expand Down

0 comments on commit c716bd9

Please sign in to comment.