MDL-66694 mod_forum: Word & char count update consistency fixes

Charcount logic is now consistent with wordcount in the post exporter.
Counts update now called in forum_udpate_instance since it is updating
the data.
This commit is contained in:
Michael Hawkins 2019-10-07 13:38:49 +08:00
parent 591dd68790
commit 3eb0a82fef
3 changed files with 8 additions and 3 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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);