Clean up category handling code in DocumentController #2119

This commit is contained in:
Kijin Sung 2023-06-19 21:54:26 +09:00
parent e238947c9a
commit b8465cc022

View file

@ -608,11 +608,20 @@ class DocumentController extends Document
if($obj->category_srl)
{
$category_list = DocumentModel::getCategoryList($obj->module_srl);
if(count($category_list) > 0 && !$category_list[$obj->category_srl]->grant)
if (count($category_list) > 0)
{
if (isset($category_list[$obj->category_srl]))
{
if (!$category_list[$obj->category_srl]->grant)
{
return new BaseObject(-1, 'msg_not_permitted');
}
if(count($category_list) > 0 && !$category_list[$obj->category_srl]) $obj->category_srl = 0;
}
else
{
$obj->category_srl = 0;
}
}
}
// Set the read counts and update order.
@ -720,7 +729,10 @@ class DocumentController extends Document
}
// Update the category if the category_srl exists.
if($obj->category_srl) $this->updateCategoryCount($obj->module_srl, $obj->category_srl);
if($obj->category_srl)
{
$this->updateCategoryCount($obj->module_srl, $obj->category_srl);
}
// Call a trigger (after)
if($obj->update_log_setting === 'Y')
@ -887,13 +899,21 @@ class DocumentController extends Document
if ($source_obj->get('category_srl') != $obj->category_srl)
{
$category_list = DocumentModel::getCategoryList($obj->module_srl);
if(!$category_list[$obj->category_srl]) $obj->category_srl = 0;
if($obj->category_srl > 0 && !$category_list[$obj->category_srl]->grant)
if (count($category_list) > 0)
{
if (isset($category_list[$obj->category_srl]))
{
if (!$category_list[$obj->category_srl]->grant)
{
return new BaseObject(-1, 'msg_not_permitted');
}
}
else
{
$obj->category_srl = 0;
}
}
}
// Change the update order
$obj->update_order = getNextSequence() * -1;
@ -1041,8 +1061,14 @@ class DocumentController extends Document
// Update the category if the category_srl exists.
if($source_obj->get('category_srl') != $obj->category_srl || $source_obj->get('module_srl') == $logged_info->member_srl)
{
if($source_obj->get('category_srl') != $obj->category_srl) $this->updateCategoryCount($obj->module_srl, $source_obj->get('category_srl'));
if($obj->category_srl) $this->updateCategoryCount($obj->module_srl, $obj->category_srl);
if($source_obj->get('category_srl') != $obj->category_srl)
{
$this->updateCategoryCount($obj->module_srl, $source_obj->get('category_srl'));
}
if($obj->category_srl)
{
$this->updateCategoryCount($obj->module_srl, $obj->category_srl);
}
}
// Update log