Add button to recalculate the document count of categories

This commit is contained in:
Kijin Sung 2024-12-16 21:52:26 +09:00
parent 818fd54b00
commit 03de7d6392
7 changed files with 76 additions and 4 deletions

View file

@ -49,6 +49,7 @@
<action name="procDocumentAdminInsertExtraVar" type="controller" permission="manager:config:*" check_var="module_srl" ruleset="insertExtraVar" />
<action name="procDocumentAdminDeleteExtraVar" type="controller" permission="manager:config:*" check_var="module_srl" />
<action name="procDocumentAdminMoveExtraVar" type="controller" permission="manager:config:*" check_var="module_srl" />
<action name="procDocumentAdminRecalculateCategoryCounts" type="controller" />
</actions>
<eventHandlers>
<eventHandler after="module.deleteModule" class="controller" method="triggerDeleteModuleDocuments" />

View file

@ -731,6 +731,44 @@ class DocumentAdminController extends Document
$output = $oDocumentController->deleteDocument($oDocument->get('document_srl'), true, true, $oDocument);
return $output;
}
/**
* Recalculate category document counts
*/
public function procDocumentAdminRecalculateCategoryCounts()
{
// Get the document count for each category.
$oDB = DB::getInstance();
$output = executeQueryArray('document.getCategoryDocumentCounts', []);
$module_srl_list = [];
// Update the document count of each category.
$oDB->beginTransaction();
foreach ($output->data ?: [] as $row)
{
$module_srl_list[$row->module_srl] = true;
$output = executeQuery('document.updateCategoryCount', [
'category_srl' => $row->category_srl,
'document_count' => $row->count,
]);
if (!$output->toBool())
{
$oDB->rollback();
return $output;
}
}
$oDB->commit();
// Refresh category cache files for affected modules.
$oDocumentController = DocumentController::getInstance();
foreach ($module_srl_list as $module_srl => $unused)
{
$oDocumentController->makeCategoryFile($module_srl);
}
$this->setError(-1);
$this->setMessage('success_updated');
}
}
/* End of file document.admin.controller.php */
/* Location: ./modules/document/document.admin.controller.php */

View file

@ -134,3 +134,6 @@ $lang->allow_declare_from_same_ip = 'Allow reporting from same IP';
$lang->allow_declare_cancel = 'Allow report cancellation';
$lang->cmd_search_division = 'Search division';
$lang->about_search_division = 'Divide search results into sections in order to reduce time and server load. Setting this value to 0 will disable divisions entirely.<br />Disabling divisions or using large values may cause serious problems such as timeouts or server overload. Values between 5000 and 10000 are recommended.';
$lang->cmd_recalculate_category_counts = 'Recalculate per-category document counts';
$lang->about_recalculate_category_counts = 'If per-category document counts are displayed incorrectly after batch move or deletion, click the button above to refresh the statistics.<br />This may take a long time if you have a large number of posts.';
$lang->prevent_redeclare = 'Prevent the same user from reporting this post again.';

View file

@ -126,4 +126,6 @@ $lang->allow_declare_from_same_ip = '동일 IP 신고 허용';
$lang->allow_declare_cancel = '신고 취소 허용';
$lang->cmd_search_division = '검색 결과 분할';
$lang->about_search_division = '검색 소요시간과 서버 부하를 줄이기 위해 일정 갯수만큼 끊어서 검색합니다. 0으로 설정할 경우 분할하지 않습니다.<br />분할하지 않거나 지나치게 많은 게시물을 한 번에 검색하려고 하면 타임아웃, 서버 다운 등 심각한 부작용이 발생할 수 있으므로 5000~10000 내외를 권장합니다.';
$lang->cmd_recalculate_category_counts = '분류별 문서 수 다시 계산';
$lang->about_recalculate_category_counts = '게시물 일괄 이동 등으로 각 분류별 문서 수가 정확하게 표시되지 않는 경우, 위의 버튼을 클릭하여 갱신할 수 있습니다.<br />문서가 많은 사이트라면 오랜 시간이 걸릴 수 있으니 주의하시기 바랍니다.';
$lang->prevent_redeclare = '같은 사용자가 이 게시물을 다시 신고하는 것을 방지합니다.';

View file

@ -0,0 +1,17 @@
<query id="getCategoryDocumentCounts" action="select">
<tables>
<table name="documents" />
</tables>
<columns>
<column name="module_srl" />
<column name="category_srl" />
<column name="count(*)" alias="count" />
</columns>
<conditions>
<condition operation="notequal" column="category_srl" default="0" />
</conditions>
<groups>
<group column="module_srl" />
<group column="category_srl" />
</groups>
</query>

View file

@ -48,6 +48,13 @@
<p class="x_help-block">{$lang->about_search_division}</p>
</div>
</div>
<div class="x_control-group">
<label class="x_control-label">{$lang->cmd_recalculate_category_counts}</label>
<div class="x_controls">
<p><button type="button" class="recalculate_category_counts">{$lang->cmd_recalculate_category_counts}</button></p>
<p class="x_help-block">{$lang->about_recalculate_category_counts}</p>
</div>
</div>
<div class="btnArea x_clearfix">
<span class="x_pull-right" style="margin-left:10px;"><input class="btn" type="button" value="{$lang->cmd_delete_all_thumbnail}" onclick="doDeleteAllThumbnail()"/></span>
<span class="x_pull-right"><input class="x_btn x_btn-primary" type="submit" value="{$lang->cmd_save}" /></span>

View file

@ -21,7 +21,7 @@ function doManageDocument(type) {
/* 선택된 글의 삭제 또는 이동 후 */
function completeManageDocument(ret_obj) {
if(opener) {
if(opener) {
opener.window.location.href = opener.window.current_url.setQuery('document_srl', '');
}
alert(ret_obj['message']);
@ -106,7 +106,7 @@ function getDocumentList() {
var documentListTable = jQuery('#documentListTable');
var cartList = [];
documentListTable.find(':checkbox[name=cart]').each(function(){
if(this.checked) cartList.push(this.value);
if(this.checked) cartList.push(this.value);
});
var params = new Array();
@ -174,12 +174,16 @@ function completeGetModuleList(ret_obj, response_tags)
}
jQuery(document).ready(function($){
$('#module_list').bind('change', function(e){
$('#module_list').on('change', function(e){
makeMidList($('#module_list').val());
});
$('#mid_list').bind('change', function(e){
$('#mid_list').on('change', function(e){
doGetCategoryFromModule($('#mid_list').val());
});
$('.recalculate_category_counts').on('click', function(e) {
exec_json('document.procDocumentAdminRecalculateCategoryCounts', { });
e.preventDefault();
});
});
function makeMidList(moduleName)