Course Reset does not delete forum posts

Course Reset does not delete forum posts

by Italo Marques -
Number of replies: 3

Good day everyone.

I've ran into a strange problem today. Upon performing a normal Course Reset I realized that forum posts simply won't be deleted if more than one option of the "Delete posts from" select box is selected:

If only one option is selected or the "Delete All Posts"checkbox is selected then it works. Moodle versions are 1.9.7 and 2.6.10 by the way. How do I fix that?

Thanks in advance.

Average of ratings: -
In reply to Italo Marques

Re: Course Reset does not delete forum posts

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hello,

The problem you describe sounds like it could be MDL-43709, which was fixed in Moodle 2.8.8 and 2.9.2. I hope you are able to upgrade your sites very soon.

Average of ratings: Useful (1)
In reply to Helen Foster

Re: Course Reset does not delete forum posts

by Italo Marques -

Hello Helen. Thank you for the reply.

It is indeed the same issue, unfortunately I can not update the sites at the moment so I was forced to fiddle with the forum_reset_userdata function in mod/forum/lib.php for the 1.9.7 site, making this:

} else if (!empty($data->reset_forum_types)){
        $removeposts = true;
        $typesql     = "";
        $types       = array();
        $forum_types_all = forum_get_forum_types_all();
        foreach ($data->reset_forum_types as $type) {
            if (!array_key_exists($type, $forum_types_all)) {
                continue;
            }
            $typesql .= " AND f.type='$type'";
            $types[] = $forum_types_all[$type];
        }
        $typesstr = get_string('resetforums', 'forum').': '.implode(', ', $types);
    }

Into this:

} else if (!empty($data->reset_forum_types)){
        $removeposts = true;
        $typesql     = "";
        $types       = array();
        $sqltypes    = array();
        $forum_types_all = forum_get_forum_types_all();
        foreach ($data->reset_forum_types as $type) {
            if (!array_key_exists($type, $forum_types_all)) {
                continue;
            }
            $types[] = $forum_types_all[$type];
            $sqltypes[] = $type;
        }
        if (!empty($sqltypes)) {
            $typesql = " AND f.type IN ('" . implode("','",$sqltypes) ."')";
        }
        $typesstr = get_string('resetforums', 'forum').': '.implode(', ', $types);
    }

It apparently worked. Well...thanks for the Moodle Tracker link. =)

In reply to Italo Marques

Re: Course Reset does not delete forum posts [Solved]

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Glad to hear that you managed to solve the problem. Thanks for sharing your solution.