diff --git a/mod/forum/classes/local/entities/post.php b/mod/forum/classes/local/entities/post.php index accf789dd8b..a398f508ebf 100644 --- a/mod/forum/classes/local/entities/post.php +++ b/mod/forum/classes/local/entities/post.php @@ -348,7 +348,7 @@ class post { * @param \stdClass $record A record ready to be inserted / updated in DB. * @return \stdClass The same record with 'wordcount' and 'charcount' attributes. */ - public static function add_message_counts(\stdClass $record): \stdClass { + public static function add_message_counts(\stdClass $record) : \stdClass { if (!empty($record->message)) { $record->wordcount = count_words($record->message); $record->charcount = count_letters($record->message); diff --git a/mod/forum/classes/local/exporters/post.php b/mod/forum/classes/local/exporters/post.php index c10749dae50..8faf0f90046 100644 --- a/mod/forum/classes/local/exporters/post.php +++ b/mod/forum/classes/local/exporters/post.php @@ -419,6 +419,10 @@ class post extends exporter { $showwordcount = $forum->should_display_word_count(); if ($showwordcount) { $wordcount = $post->get_wordcount() ?? count_words($message); + $charcount = $post->get_charcount() ?? count_letters($message); + } else { + $wordcount = null; + $charcount = null; } return [ @@ -436,8 +440,8 @@ class post extends exporter { 'isdeleted' => $isdeleted, 'isprivatereply' => $isprivatereply, 'haswordcount' => $showwordcount, - 'wordcount' => $showwordcount ? $wordcount : null, - 'charcount' => $post->get_charcount(), + 'wordcount' => $wordcount, + 'charcount' => $charcount, 'capabilities' => [ 'view' => $canview, 'edit' => $canedit, diff --git a/mod/forum/lib.php b/mod/forum/lib.php index d7d62bfd824..acdab29f332 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -240,6 +240,7 @@ function forum_update_instance($forum, $mform) { $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, $options, $post->message); } + \mod_forum\local\entities\post::add_message_counts($post); $DB->update_record('forum_posts', $post); $discussion->name = $forum->name; $DB->update_record('forum_discussions', $discussion);