From 0663a6415d6c9cc47ff12824a02eeaa7cbc4d7ed Mon Sep 17 00:00:00 2001 From: RaphaelL Date: Mon, 9 Oct 2023 09:26:56 +0200 Subject: [PATCH] Fix trad + bump v1.0.1 --- classes/cartCleaner.php | 11 +++++------ classes/customerCleaner.php | 2 +- classes/miscCleaner.php | 4 ++-- classes/orderCleaner.php | 25 ++++++++++++------------- classes/productCleaner.php | 6 +++--- config.xml | 2 +- prestaclean.php | 2 +- translations/fr.php | 7 ++++++- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/classes/cartCleaner.php b/classes/cartCleaner.php index d23243e..e237b7b 100644 --- a/classes/cartCleaner.php +++ b/classes/cartCleaner.php @@ -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; @@ -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); } /** @@ -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'); diff --git a/classes/customerCleaner.php b/classes/customerCleaner.php index 0b284f0..33ec3f6 100644 --- a/classes/customerCleaner.php +++ b/classes/customerCleaner.php @@ -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); } } diff --git a/classes/miscCleaner.php b/classes/miscCleaner.php index 4a0b41a..79e704f 100644 --- a/classes/miscCleaner.php +++ b/classes/miscCleaner.php @@ -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; } @@ -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) { diff --git a/classes/orderCleaner.php b/classes/orderCleaner.php index ea42fbb..e0102d5 100644 --- a/classes/orderCleaner.php +++ b/classes/orderCleaner.php @@ -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; @@ -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); } /*********************************************************************************************************************************************** @@ -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)); } diff --git a/classes/productCleaner.php b/classes/productCleaner.php index faa671e..30b3e97 100644 --- a/classes/productCleaner.php +++ b/classes/productCleaner.php @@ -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); @@ -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); } /*********************************************************************************************************************************************** diff --git a/config.xml b/config.xml index c70fc8b..df673d2 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ prestaclean - + diff --git a/prestaclean.php b/prestaclean.php index a2531c5..5e327f8 100644 --- a/prestaclean.php +++ b/prestaclean.php @@ -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; diff --git a/translations/fr.php b/translations/fr.php index 6c38e8c..af4f112 100644 --- a/translations/fr.php +++ b/translations/fr.php @@ -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'; @@ -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.';