From 7a6400f39dc8887f67c7fb4615e7572bdd404912 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 4 Sep 2025 21:47:28 +0900 Subject: [PATCH] Allow point reversion policies to be customized for each module --- modules/point/point.admin.controller.php | 17 +++++++++++++++-- modules/point/point.controller.php | 15 +++++++-------- modules/point/point.model.php | 6 +++--- modules/point/tpl/point_module_config.html | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/modules/point/point.admin.controller.php b/modules/point/point.admin.controller.php index 2176023f3..235f97067 100644 --- a/modules/point/point.admin.controller.php +++ b/modules/point/point.admin.controller.php @@ -257,7 +257,7 @@ class PointAdminController extends Point } $config = []; - $keys = [ + $numeric_keys = [ 'insert_document', 'insert_comment', 'upload_file', @@ -274,8 +274,13 @@ class PointAdminController extends Point 'voted_comment', 'blamed_comment' ]; + $boolean_keys = [ + 'insert_document_revert_on_delete', + 'insert_comment_revert_on_delete', + 'upload_file_revert_on_delete' + ]; - foreach ($keys as $key) + foreach ($numeric_keys as $key) { $value = trim(Context::get($key) ?? ''); if ($value !== '') @@ -283,6 +288,14 @@ class PointAdminController extends Point $config[$key] = (int)$value; } } + foreach ($boolean_keys as $key) + { + $value = trim(Context::get($key) ?? ''); + if ($value !== '') + { + $config[$key] = ($value === 'Y'); + } + } $oModuleController->insertModulePartConfig('point', $srl, $config); } diff --git a/modules/point/point.controller.php b/modules/point/point.controller.php index d900569e1..a40e1b30b 100644 --- a/modules/point/point.controller.php +++ b/modules/point/point.controller.php @@ -211,8 +211,8 @@ class PointController extends Point } // Return if disabled - $config = $this->getConfig(); - if ($config->insert_document_revert_on_delete === false) + $revert = PointModel::getModulePointConfig($module_srl, 'insert_document_revert_on_delete'); + if ($revert === false) { return; } @@ -319,8 +319,8 @@ class PointController extends Point } // Return if disabled - $config = $this->getConfig(); - if ($config->insert_comment_revert_on_delete === false) + $revert = PointModel::getModulePointConfig($module_srl, 'insert_comment_revert_on_delete'); + if ($revert === false) { return; } @@ -333,6 +333,7 @@ class PointController extends Point } // Abort if the document is older than a configured limit. + $config = $this->getConfig(); $time_limit = $config->insert_comment_limit ?: $config->no_point_date; if ($time_limit > 0 && ztime($oDocument->get('regdate')) < RX_TIME - ($time_limit * 86400)) { @@ -381,14 +382,12 @@ class PointController extends Point } // Return if disabled - $config = $this->getConfig(); - if ($config->upload_file_revert_on_delete === false) + $revert = PointModel::getModulePointConfig($module_srl, 'upload_file_revert_on_delete'); + if ($revert === false) { return; } - // Get the points of the member - // Subtract points for the file. $diff = PointModel::getModulePointConfig($module_srl, 'upload_file'); diff --git a/modules/point/point.model.php b/modules/point/point.model.php index a9cfb5599..ae81a9714 100644 --- a/modules/point/point.model.php +++ b/modules/point/point.model.php @@ -271,7 +271,7 @@ class PointModel extends Point * * @param int $module_srl * @param string $config_key - * @return int + * @return int|bool */ public static function getModulePointConfig($module_srl, $config_key) { @@ -306,10 +306,10 @@ class PointModel extends Point else { $default_config = self::getConfig(); - $point = $default_config->{$config_key}; + $point = $default_config->{$config_key} ?? 0; } - return intval($point); + return is_bool($point) ? $point : intval($point); } } /* End of file point.model.php */ diff --git a/modules/point/tpl/point_module_config.html b/modules/point/tpl/point_module_config.html index d35a7e4f1..e8e5f822a 100644 --- a/modules/point/tpl/point_module_config.html +++ b/modules/point/tpl/point_module_config.html @@ -11,18 +11,36 @@
{$module_config['point_name']} +   {$lang->cmd_point_revert_on_delete} +
{$module_config['point_name']} +   {$lang->cmd_point_revert_on_delete} +
{$module_config['point_name']} +   {$lang->cmd_point_revert_on_delete} +