Skip to content

Commit

Permalink
Закрытие задачи модерации комментариев при удалении субъекта
Browse files Browse the repository at this point in the history
close #1418
Сохранение нуля в полях "текст" и "строковое поле" + немного рефакторинга.
  • Loading branch information
fuzegit committed Jun 29, 2022
1 parent 2f048c3 commit e97b4b6
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 157 deletions.
3 changes: 2 additions & 1 deletion install/languages/en/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,8 @@ INSERT INTO `{#}events` (`id`, `event`, `listener`, `ordering`, `is_enabled`) VA
(214, 'render_widget_menu_menu', 'bootstrap4', 214, 1),
(215, 'engine_start', 'redirect', 215, 1),
(216, 'restore_user', 'comments', 216, 1),
(217, 'set_user_is_deleted', 'comments', 217, 1);
(217, 'set_user_is_deleted', 'comments', 217, 1),
(218, 'comments_after_delete_list', 'moderation', 218, 1);

DROP TABLE IF EXISTS `{#}groups`;
CREATE TABLE `{#}groups` (
Expand Down
3 changes: 2 additions & 1 deletion install/languages/ru/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,8 @@ INSERT INTO `{#}events` (`id`, `event`, `listener`, `ordering`, `is_enabled`) VA
(214, 'render_widget_menu_menu', 'bootstrap4', 214, 1),
(215, 'engine_start', 'redirect', 215, 1),
(216, 'restore_user', 'comments', 216, 1),
(217, 'set_user_is_deleted', 'comments', 217, 1);
(217, 'set_user_is_deleted', 'comments', 217, 1),
(218, 'comments_after_delete_list', 'moderation', 218, 1);

DROP TABLE IF EXISTS `{#}groups`;
CREATE TABLE `{#}groups` (
Expand Down
50 changes: 23 additions & 27 deletions system/controllers/comments/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ public function deleteComment($comment, $is_delete = false) {
continue;
}

@unlink(cmsConfig::get('upload_path') . $file['path']);

$files_model->filterEqual('path', $file['path']);

$files_model->deleteFiltered('uploaded_files');
$files_model->deleteFile($file);
}
}

Expand Down Expand Up @@ -168,42 +164,42 @@ public function deleteComments($target_controller, $target_subject, $target_id =

$this->unlockFilters();

if ($comments) {
if (!$comments) {

$ids = array_keys($comments);
$this->resetFilters();

$this->deleteFiltered('comments');
return false;
}

$this->filterIn('comment_id', $ids)->deleteFiltered('comments_rating');
$ids = array_keys($comments);

cmsCache::getInstance()->clean('comments.list');
$this->deleteFiltered('comments');

// Удаляем изображения
$files_model = cmsCore::getModel('files');
$this->filterIn('comment_id', $ids)->deleteFiltered('comments_rating');

foreach ($comments as $content_html) {
$paths = string_html_get_images_path($content_html);
if ($paths) {
foreach ($paths as $path) {

$file = $files_model->getFileByPath($path);
if (!$file) {
continue;
}
cmsCache::getInstance()->clean('comments.list');

@unlink(cmsConfig::get('upload_path') . $file['path']);
// Удаляем изображения
$files_model = cmsCore::getModel('files');

$files_model->filterEqual('path', $file['path']);
foreach ($comments as $content_html) {
$paths = string_html_get_images_path($content_html);
if ($paths) {
foreach ($paths as $path) {

$files_model->deleteFiltered('uploaded_files');
$file = $files_model->getFileByPath($path);
if (!$file) {
continue;
}

$files_model->deleteFile($file);
}
}

cmsEventsManager::hook('comments_after_delete_list', $ids);
}

return $comments ? true : false;
cmsEventsManager::hook('comments_after_delete_list', $ids);

return true;
}

public function setCommentsIsDeleted($target_controller, $target_subject, $target_id, $delete = 1) {
Expand Down
19 changes: 19 additions & 0 deletions system/controllers/moderation/hooks/comments_after_delete_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

class onModerationCommentsAfterDeleteList extends cmsAction {

public function run($ids){

foreach ($ids as $comment_id) {

$this->model->closeModeratorTask('comments', $comment_id, false, $this->cms_user->id);

if(!empty($this->options['clear_log_after_delete'])){
$this->model->logDeleteTarget('comments', 'comments', $comment_id);
}
}

return $ids;
}

}
152 changes: 73 additions & 79 deletions system/fields/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,106 +9,106 @@ class fieldHtml extends cmsFormField {
public $var_type = 'string';

public function getOptions(){
return array(
new fieldList('editor', array(
'title' => LANG_PARSER_HTML_EDITOR,
'default' => cmsConfig::get('default_editor'),
'generator' => function($item){
$items = [];
return [
new fieldList('editor', [
'title' => LANG_PARSER_HTML_EDITOR,
'default' => cmsConfig::get('default_editor'),
'generator' => function ($item) {
$items = [];
$editors = cmsCore::getWysiwygs();
foreach($editors as $editor){
foreach ($editors as $editor) {
$items[$editor] = ucfirst($editor);
}
$ps = cmsCore::getModel('wysiwygs')->getPresetsList();
if($ps){
if ($ps) {
foreach ($ps as $key => $value) {
$items[$key] = $value;
}
}
return $items;
}
)),
new fieldList('editor_presets', array(
'title' => LANG_PARSER_HTML_EDITOR_GR,
'is_multiple' => true,
'dynamic_list' => true,
'select_title' => LANG_SELECT,
'multiple_keys' => array(
'group_id' => 'field', 'preset_id' => 'field_select'
),
'generator' => function($item){
]),
new fieldList('editor_presets', [
'title' => LANG_PARSER_HTML_EDITOR_GR,
'is_multiple' => true,
'dynamic_list' => true,
'select_title' => LANG_SELECT,
'multiple_keys' => [
'group_id' => 'field', 'preset_id' => 'field_select'
],
'generator' => function ($item) {
$users_model = cmsCore::getModel('users');

$items = [];

$groups = $users_model->getGroups(false);

foreach($groups as $group){
foreach ($groups as $group) {
$items[$group['id']] = $group['title'];
}

return $items;
},
'values_generator' => function() {
$items = [];
'values_generator' => function () {
$items = [];
$editors = cmsCore::getWysiwygs();
foreach($editors as $editor){
foreach ($editors as $editor) {
$items[$editor] = ucfirst($editor);
}
$ps = cmsCore::getModel('wysiwygs')->getPresetsList();
if($ps){
if ($ps) {
foreach ($ps as $key => $value) {
$items[$key] = $value;
}
}
return $items;
}
)),
new fieldCheckbox('is_html_filter', array(
'title' => LANG_PARSER_HTML_FILTERING,
]),
new fieldCheckbox('is_html_filter', [
'title' => LANG_PARSER_HTML_FILTERING,
'extended_option' => true
)),
new fieldCheckbox('parse_patterns', array(
]),
new fieldCheckbox('parse_patterns', [
'title' => LANG_PARSER_PARSE_PATTERNS,
'hint' => LANG_PARSER_PARSE_PATTERNS_HINT
)),
new fieldCheckbox('build_redirect_link', array(
'title' => LANG_PARSER_BUILD_REDIRECT_LINK,
'hint' => LANG_PARSER_PARSE_PATTERNS_HINT
]),
new fieldCheckbox('build_redirect_link', [
'title' => LANG_PARSER_BUILD_REDIRECT_LINK,
'is_visible' => cmsController::enabled('redirect')
)),
new fieldNumber('teaser_len', array(
'title' => LANG_PARSER_HTML_TEASER_LEN,
'hint' => LANG_PARSER_HTML_TEASER_LEN_HINT,
]),
new fieldNumber('teaser_len', [
'title' => LANG_PARSER_HTML_TEASER_LEN,
'hint' => LANG_PARSER_HTML_TEASER_LEN_HINT,
'extended_option' => true
)),
new fieldString('teaser_postfix', array(
]),
new fieldString('teaser_postfix', [
'title' => LANG_PARSER_HTML_TEASER_POSTFIX,
'visible_depend' => array('options:teaser_len' => array('hide' => array(''))),
'default' => '',
'visible_depend' => ['options:teaser_len' => ['hide' => ['']]],
'default' => '',
'extended_option' => true
)),
new fieldList('teaser_type', array(
'title' => LANG_PARSER_HTML_TEASER_TYPE,
'items' => array(
]),
new fieldList('teaser_type', [
'title' => LANG_PARSER_HTML_TEASER_TYPE,
'items' => [
'' => LANG_PARSER_HTML_TEASER_TYPE_NULL,
's' => LANG_PARSER_HTML_TEASER_TYPE_S,
'w' => LANG_PARSER_HTML_TEASER_TYPE_W
),
'visible_depend' => array('options:teaser_len' => array('hide' => array(''))),
],
'visible_depend' => ['options:teaser_len' => ['hide' => ['']]],
'extended_option' => true
)),
new fieldCheckbox('show_show_more', array(
'title' => LANG_PARSER_SHOW_SHOW_MORE,
'default' => false,
'visible_depend' => array('options:teaser_len' => array('hide' => array(''))),
]),
new fieldCheckbox('show_show_more', [
'title' => LANG_PARSER_SHOW_SHOW_MORE,
'default' => false,
'visible_depend' => ['options:teaser_len' => ['hide' => ['']]],
'extended_option' => true
)),
new fieldCheckbox('in_fulltext_search', array(
'title' => LANG_PARSER_IN_FULLTEXT_SEARCH,
'hint' => LANG_PARSER_IN_FULLTEXT_SEARCH_HINT,
]),
new fieldCheckbox('in_fulltext_search', [
'title' => LANG_PARSER_IN_FULLTEXT_SEARCH,
'hint' => LANG_PARSER_IN_FULLTEXT_SEARCH_HINT,
'default' => false
))
);
])
];
}

public function getFilterInput($value) {
Expand Down Expand Up @@ -150,8 +150,8 @@ public function parse($value){
if ($this->getOption('is_html_filter')){
$value = cmsEventsManager::hook('html_filter', [
'text' => $value,
'is_auto_br' => $this->getOption('editor') == 'markitup',
'build_smiles' => $this->getOption('editor') == 'markitup', // пока что только так
'is_auto_br' => $this->getOption('editor') === 'markitup',
'build_smiles' => $this->getOption('editor') === 'markitup', // пока что только так
'build_redirect_link' => (bool)$this->getOption('build_redirect_link')
]);
$value = string_replace_svg_icons($value);
Expand Down Expand Up @@ -187,7 +187,7 @@ public function parseTeaser($value) {
$value = cmsEventsManager::hook('html_filter', [
'text' => $value,
'is_auto_br' => false,
'build_smiles' => $this->getOption('editor') == 'markitup', // пока что только так
'build_smiles' => $this->getOption('editor') === 'markitup', // пока что только так
'build_redirect_link' => (bool)$this->getOption('build_redirect_link')
]);
}
Expand All @@ -203,65 +203,59 @@ public function applyFilter($model, $value) {
return $model->filterLike($this->name, "%{$value}%");
}

public function afterStore($item, $model, $action){
public function afterStore($item, $model, $action) {

if($action == 'add' && !empty($item[$this->name])){
if ($action === 'add' && !empty($item[$this->name])) {

$paths = string_html_get_images_path($item[$this->name]);

if($paths){
foreach($paths as $path){
if ($paths) {
foreach ($paths as $path) {

$model->filterEqual('path', $path)->filterIsNull('target_id');
$model->updateFiltered('uploaded_files', ['target_id' => $item['id']], true);

}
}

}

return;
}

public function delete($value){
public function delete($value) {

if (is_empty_value($value)) {
return true;
}

$paths = string_html_get_images_path($value);

if($paths){
if ($paths) {

$files_model = cmsCore::getModel('files');

foreach($paths as $path){
foreach ($paths as $path) {

$file = $files_model->getFileByPath($path);
if(!$file){ continue; }

@unlink(cmsConfig::get('upload_path').$file['path']);

$files_model->filterEqual('path', $file['path']);

$files_model->deleteFiltered('uploaded_files');
if (!$file) {
continue;
}

$files_model->deleteFile($file);
}

}

return true;
}

public function getInput($value){
public function getInput($value) {

$this->data = cmsCore::getController('wysiwygs')->getEditorParams([
'editor' => $this->getOption('editor'),
'options' => $this->getOption('editor_options', []),
'presets' => $this->getOption('editor_presets', [])
]);

if(empty($this->data['options']['id'])){
if (empty($this->data['options']['id'])) {
$this->data['options']['id'] = $this->id;
}

Expand Down
Loading

0 comments on commit e97b4b6

Please sign in to comment.