Merge pull request #1040 from shreesh-webkul/gli-1018

Updated: QloApps cleaner | Added hook for data cleaning in other module and fixed incorrect data being deleted.
This commit is contained in:
Rohit Jain
2024-08-22 19:51:08 +05:30
committed by GitHub
7 changed files with 125 additions and 24 deletions

View File

@@ -50,6 +50,28 @@ class QloCleaner extends Module
$this->secure_key = Tools::encrypt($this->name);
}
public function install()
{
if (!parent::install()
|| !$this->registerHook('actionAdminControllerSetMedia')
) {
return false;
}
return true;
}
public function hookActionAdminControllerSetMedia()
{
if (Tools::getValue('controller') == 'AdminModules'
&& Tools::getValue('configure') == $this->name
) {
Media::addJsDef(array(
'confirm_txt' => $this->l('Are you sure, you want to perform the following action?')
));
$this->context->controller->addJS($this->_path.'views/js/qlocleaner_config.js');
}
}
public function getContent()
{
$html = '<h2>'.$this->l('Be really careful with this tool - There is no possible rollback!').'</h2>';
@@ -61,6 +83,7 @@ class QloCleaner extends Module
} else {
$conf = $this->l('Nothing that need to be fixed please run database cleaning to clean your database');
}
Hook::exec('actionCleanData', array('method' => 'checkAndFix'));
$html .= $this->displayConfirmation($conf);
} elseif (Tools::isSubmit('submitCleanAndOptimize')) {
$logs = self::cleanAndOptimize();
@@ -70,12 +93,15 @@ class QloCleaner extends Module
} else {
$conf = $this->l('Nothing that need to be cleaned');
}
Hook::exec('actionCleanData', array('method' => 'cleanAndOptimize'));
$html .= $this->displayConfirmation($conf);
} elseif (Tools::getValue('submitTruncateCatalog') && Tools::getValue('checkTruncateCatalog')) {
self::truncate('catalog');
Hook::exec('actionCleanData', array('method' => 'catalog'));
$html .= $this->displayConfirmation($this->l('Catalog truncated successfuly, please run functional Integrity constraints to clean the database.'));
} elseif (Tools::getValue('submitTruncateSales') && Tools::getValue('checkTruncateSales')) {
self::truncate('sales');
Hook::exec('actionCleanData', array('method' => 'sales'));
$html .= $this->displayConfirmation($this->l('Orders and customers truncated successfuly, please run functional Integrity constraints to clean the database'));
}
@@ -244,6 +270,11 @@ class QloCleaner extends Module
}
}
Image::deleteAllImages(_PS_HOTEL_IMG_DIR_);
if (!file_exists(_PS_HOTEL_IMG_DIR_)) {
mkdir(_PS_HOTEL_IMG_DIR_);
}
// Delete qlo modules's images
QcCleanerHelper::deleteFolderImages(
_PS_MODULE_DIR_.'wkabouthotelblock/views/img/hotel_interior/'
@@ -314,21 +345,6 @@ class QloCleaner extends Module
}
}
// Delete Qlo tables
$query = 'DELETE FROM `'._DB_PREFIX_.'htl_order_refund_rules`';
if (Db::getInstance()->Execute($query)) {
if ($affected_rows = Db::getInstance()->Affected_Rows()) {
$logs[$query] = $affected_rows;
}
}
$query = 'DELETE FROM `'._DB_PREFIX_.'htl_order_refund_rules_lang`';
if (Db::getInstance()->Execute($query)) {
if ($affected_rows = Db::getInstance()->Affected_Rows()) {
$logs[$query] = $affected_rows;
}
}
$parents = Db::getInstance()->ExecuteS('SELECT DISTINCT id_parent FROM '._DB_PREFIX_.'tab');
foreach ($parents as $parent) {
$children = Db::getInstance()->ExecuteS('SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE id_parent = '.(int)$parent['id_parent'].' ORDER BY IF(class_name IN ("AdminHome", "AdminDashboard"), 1, 2), position ASC');
@@ -753,12 +769,7 @@ class QloCleaner extends Module
'customization_field',
'customization_field_lang',
'customized_data',
'feature',
'feature_lang',
'feature_product',
'feature_shop',
'feature_value',
'feature_value_lang',
'pack',
'search_index',
'search_word',
@@ -778,8 +789,6 @@ class QloCleaner extends Module
'htl_branch_info_lang',
'htl_image',
'htl_branch_features',
'htl_features',
'htl_features_lang',
'htl_advance_payment',
'htl_branch_refund_rules',
'htl_order_restrict_date',
@@ -845,6 +854,8 @@ class QloCleaner extends Module
'htl_room_type_service_product_order_detail',
'htl_room_type_service_product_cart_detail',
'htl_hotel_service_product_cart_detail',
'htl_order_refund_rules',
'htl_order_refund_rules_lang',
);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,24 @@
/**
* Since 2010 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through this link for complete license : https://store.webkul.com/license.html
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information.
*
* @author Webkul IN <support@webkul.com>
* @copyright Since 2010 Webkul IN
* @license https://store.webkul.com/license.html
*/
$(document).ready(function () {
$('#module_form').on('submit', function() {
return confirm(confirm_txt);
})
});

View File

@@ -134,6 +134,20 @@ class QhrHotelReviewDb
);
}
public static function truncateUserData()
{
$userTables = array('qhr_hotel_review',
'qhr_review_category_rating',
'qhr_review_usefulness',
'qhr_review_report',
'qhr_review_reply'
);
foreach ($userTables as $table) {
DB::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.bqSQL($table).'`');
}
QhrHotelReview::cleanImagesDirectory();
}
public static function getModuleDefaultConfig()
{
return array(

View File

@@ -72,6 +72,7 @@ class QloHotelReview extends Module
'displayBookingAction',
'displayBackOfficeHeader',
'displayAdminAfterHeader',
'actionCleanData',
)
);
}
@@ -279,6 +280,13 @@ class QloHotelReview extends Module
return $this->display(__FILE__, 'product-tab-content.tpl');
}
public function hookActionCleanData($params)
{
if ($params['method'] == 'catalog' || $params['method'] == 'sales') {
QhrHotelReviewDb::truncateUserData();
}
}
public function installModuleTabs()
{
$tabs = array(

View File

@@ -56,4 +56,11 @@ class WkHotelRoomDb
`'._DB_PREFIX_.'htl_room_block_data`;
');
}
public static function truncateTables()
{
return DB::getInstance()->execute(
'TRUNCATE TABLE `'._DB_PREFIX_.'htl_room_block_data`;
');
}
}

View File

@@ -141,6 +141,13 @@ class WkHotelRoom extends Module
}
}
public function hookActionCleanData($params)
{
if ($params['method'] == 'catalog') {
WkHotelRoomDb::truncateTables();
}
}
public function callInstallTab()
{
//Controllers which are to be used in this modules but we have not to create tab for those controllers...
@@ -198,7 +205,8 @@ class WkHotelRoom extends Module
'actionProductDelete',
'displayFooterExploreSectionHook',
'actionProductSave',
'actionObjectLanguageAddAfter'
'actionObjectLanguageAddAfter',
'actionCleanData',
)
);
}
@@ -220,7 +228,7 @@ class WkHotelRoom extends Module
}
return true;
}
public function deleteConfigKeys()
{
$configVars = array(