mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-56225 mod_forum: Remove unnecessary attributes from update
This commit is contained in:
parent
2c814d2c5e
commit
6528ec3505
@ -260,9 +260,6 @@ class mod_forum_post_form extends moodleform {
|
||||
$mform->addElement('hidden', 'parent');
|
||||
$mform->setType('parent', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'userid');
|
||||
$mform->setType('userid', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'groupid');
|
||||
$mform->setType('groupid', PARAM_INT);
|
||||
|
||||
|
@ -4405,25 +4405,40 @@ function forum_add_new_post($post, $mform, $unused = null) {
|
||||
/**
|
||||
* Update a post.
|
||||
*
|
||||
* @param stdClass $post The post to update
|
||||
* @param stdClass $newpost The post to update
|
||||
* @param mixed $mform The submitted form
|
||||
* @param string $unused
|
||||
* @return bool
|
||||
*/
|
||||
function forum_update_post($post, $mform, $unused = null) {
|
||||
global $DB;
|
||||
function forum_update_post($newpost, $mform, $unused = null) {
|
||||
global $DB, $USER;
|
||||
|
||||
$post = $DB->get_record('forum_posts', array('id' => $newpost->id));
|
||||
$discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion));
|
||||
$forum = $DB->get_record('forum', array('id' => $discussion->forum));
|
||||
$cm = get_coursemodule_from_instance('forum', $forum->id);
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
// Allowed modifiable fields.
|
||||
$modifiablefields = [
|
||||
'subject',
|
||||
'message',
|
||||
'messageformat',
|
||||
'messagetrust',
|
||||
'timestart',
|
||||
'timeend',
|
||||
'pinned',
|
||||
];
|
||||
foreach ($modifiablefields as $field) {
|
||||
if (isset($newpost->{$field})) {
|
||||
$post->{$field} = $newpost->{$field};
|
||||
}
|
||||
}
|
||||
$post->modified = time();
|
||||
|
||||
$DB->update_record('forum_posts', $post);
|
||||
|
||||
$discussion->timemodified = $post->modified; // last modified tracking
|
||||
$discussion->usermodified = $post->userid; // last modified tracking
|
||||
// Last post modified tracking.
|
||||
$discussion->timemodified = $post->modified;
|
||||
$discussion->usermodified = $USER->id;
|
||||
|
||||
if (!$post->parent) { // Post is a discussion starter - update discussion title and times too
|
||||
$discussion->name = $post->subject;
|
||||
@ -4434,16 +4449,15 @@ function forum_update_post($post, $mform, $unused = null) {
|
||||
$discussion->pinned = $post->pinned;
|
||||
}
|
||||
}
|
||||
$post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id,
|
||||
$post->message = file_save_draft_area_files($newpost->itemid, $context->id, 'mod_forum', 'post', $post->id,
|
||||
mod_forum_post_form::editor_options($context, $post->id), $post->message);
|
||||
$DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id));
|
||||
|
||||
$DB->update_record('forum_posts', $post);
|
||||
$DB->update_record('forum_discussions', $discussion);
|
||||
|
||||
forum_add_attachment($post, $forum, $cm, $mform);
|
||||
|
||||
if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
|
||||
forum_tp_mark_post_read($post->userid, $post, $post->forum);
|
||||
forum_tp_mark_post_read($USER->id, $post, $post->forum);
|
||||
}
|
||||
|
||||
// Let Moodle know that assessable content is uploaded (eg for plagiarism detection)
|
||||
|
Loading…
x
Reference in New Issue
Block a user