first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+135
View File
@@ -0,0 +1,135 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides support for the conversion of moodle1 backup to the moodle2 format
*
* @package mod_forum
* @copyright 2011 Mark Nielsen <mark@moodlerooms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Forum conversion handler
*/
class moodle1_mod_forum_handler extends moodle1_mod_handler {
/** @var moodle1_file_manager */
protected $fileman = null;
/** @var int cmid */
protected $moduleid = null;
/**
* Declare the paths in moodle.xml we are able to convert
*
* The method returns list of {@link convert_path} instances.
* For each path returned, the corresponding conversion method must be
* defined.
*
* Note that the paths /MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM do not
* actually exist in the file. The last element with the module name was
* appended by the moodle1_converter class.
*
* @return array of {@link convert_path} instances
*/
public function get_paths() {
return array(
new convert_path('forum', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM',
array(
'renamefields' => array(
'format' => 'messageformat',
),
'newfields' => array(
'completiondiscussions' => 0,
'completionreplies' => 0,
'completionpost' => 0,
'maxattachments' => 1,
'introformat' => 0,
),
)
),
);
}
/**
* Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM data
*/
public function process_forum($data) {
global $CFG;
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_forum');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// Convert the introformat if necessary.
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// start writing forum.xml
$this->open_xml_writer("activities/forum_{$this->moduleid}/forum.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
'modulename' => 'forum', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('forum', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field <> 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
$this->xmlwriter->begin_tag('discussions');
return $data;
}
/**
* This is executed when we reach the closing </MOD> tag of our 'forum' path
*/
public function on_forum_end() {
// finish writing forum.xml
$this->xmlwriter->end_tag('discussions');
$this->xmlwriter->end_tag('forum');
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml
$this->open_xml_writer("activities/forum_{$this->moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($this->fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
}
}
@@ -0,0 +1,87 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines backup_forum_activity_task class
*
* @package mod_forum
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/forum/backup/moodle2/backup_forum_stepslib.php');
require_once($CFG->dirroot . '/mod/forum/backup/moodle2/backup_forum_settingslib.php');
/**
* Provides the steps to perform one complete backup of the Forum instance
*/
class backup_forum_activity_task extends backup_activity_task {
/**
* No specific settings for this activity
*/
protected function define_my_settings() {
}
/**
* Defines a backup step to store the instance data in the forum.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_forum_activity_structure_step('forum structure', 'forum.xml'));
}
/**
* Encodes URLs to the index.php, view.php and discuss.php scripts
*
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
* @return string the content with the URLs encoded
*/
public static function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot,"/");
// Link to the list of forums
$search="/(".$base."\/mod\/forum\/index.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@FORUMINDEX*$2@$', $content);
// Link to forum view by moduleid
$search="/(".$base."\/mod\/forum\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@FORUMVIEWBYID*$2@$', $content);
// Link to forum view by forumid
$search="/(".$base."\/mod\/forum\/view.php\?f\=)([0-9]+)/";
$content= preg_replace($search, '$@FORUMVIEWBYF*$2@$', $content);
// Link to forum discussion with parent syntax
$search = "/(".$base."\/mod\/forum\/discuss.php\?d\=)([0-9]+)(?:\&amp;|\&)parent\=([0-9]+)/";
$content= preg_replace($search, '$@FORUMDISCUSSIONVIEWPARENT*$2*$3@$', $content);
// Link to forum discussion with relative syntax
$search="/(".$base."\/mod\/forum\/discuss.php\?d\=)([0-9]+)\#([0-9]+)/";
$content= preg_replace($search, '$@FORUMDISCUSSIONVIEWINSIDE*$2*$3@$', $content);
// Link to forum discussion by discussionid
$search="/(".$base."\/mod\/forum\/discuss.php\?d\=)([0-9]+)/";
$content= preg_replace($search, '$@FORUMDISCUSSIONVIEW*$2@$', $content);
return $content;
}
}
@@ -0,0 +1,27 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_forum
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// This activity has not particular settings but the inherited from the generic
// backup_activity_task so here there isn't any class definition, like the ones
// existing in /backup/moodle2/backup_settingslib.php (activities section)
@@ -0,0 +1,223 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_forum
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the backup steps that will be used by the backup_forum_activity_task
*/
/**
* Define the complete forum structure for backup, with file and id annotations
*/
class backup_forum_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() {
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated
$forum = new backup_nested_element('forum', array('id'), array(
'type', 'name', 'intro', 'introformat', 'duedate', 'cutoffdate',
'assessed', 'assesstimestart', 'assesstimefinish', 'scale',
'maxbytes', 'maxattachments', 'forcesubscribe', 'trackingtype',
'rsstype', 'rssarticles', 'timemodified', 'warnafter',
'blockafter', 'blockperiod', 'completiondiscussions', 'completionreplies',
'completionposts', 'displaywordcount', 'lockdiscussionafter', 'grade_forum'));
$discussions = new backup_nested_element('discussions');
$discussion = new backup_nested_element('discussion', array('id'), array(
'name', 'firstpost', 'userid', 'groupid',
'assessed', 'timemodified', 'usermodified', 'timestart',
'timeend', 'pinned', 'timelocked'));
$posts = new backup_nested_element('posts');
$post = new backup_nested_element('post', array('id'), array(
'parent', 'userid', 'created', 'modified',
'mailed', 'subject', 'message', 'messageformat',
'messagetrust', 'attachment', 'totalscore', 'mailnow', 'privatereplyto'));
$tags = new backup_nested_element('poststags');
$tag = new backup_nested_element('tag', array('id'), array('itemid', 'rawname'));
$ratings = new backup_nested_element('ratings');
$rating = new backup_nested_element('rating', array('id'), array(
'component', 'ratingarea', 'scaleid', 'value', 'userid', 'timecreated', 'timemodified'));
$discussionsubs = new backup_nested_element('discussion_subs');
$discussionsub = new backup_nested_element('discussion_sub', array('id'), array(
'userid',
'preference',
));
$subscriptions = new backup_nested_element('subscriptions');
$subscription = new backup_nested_element('subscription', array('id'), array(
'userid'));
$digests = new backup_nested_element('digests');
$digest = new backup_nested_element('digest', array('id'), array(
'userid', 'maildigest'));
$readposts = new backup_nested_element('readposts');
$read = new backup_nested_element('read', array('id'), array(
'userid', 'discussionid', 'postid', 'firstread',
'lastread'));
$trackedprefs = new backup_nested_element('trackedprefs');
$track = new backup_nested_element('track', array('id'), array(
'userid'));
$grades = new backup_nested_element('grades');
$grade = new backup_nested_element('grade', ['id'], [
'forum',
'itemnumber',
'userid',
'grade',
'timecreated',
'timemodified',
]);
// Build the tree
$forum->add_child($discussions);
$discussions->add_child($discussion);
$forum->add_child($subscriptions);
$subscriptions->add_child($subscription);
$forum->add_child($digests);
$digests->add_child($digest);
$forum->add_child($readposts);
$readposts->add_child($read);
$forum->add_child($trackedprefs);
$trackedprefs->add_child($track);
$forum->add_child($tags);
$tags->add_child($tag);
$forum->add_child($grades);
$grades->add_child($grade);
$discussion->add_child($posts);
$posts->add_child($post);
$post->add_child($ratings);
$ratings->add_child($rating);
$discussion->add_child($discussionsubs);
$discussionsubs->add_child($discussionsub);
// Define sources
$forum->set_source_table('forum', array('id' => backup::VAR_ACTIVITYID));
// All these source definitions only happen if we are including user info
if ($userinfo) {
$discussion->set_source_sql('
SELECT *
FROM {forum_discussions}
WHERE forum = ?',
array(backup::VAR_PARENTID));
// Need posts ordered by id so parents are always before childs on restore
$post->set_source_table('forum_posts', array('discussion' => backup::VAR_PARENTID), 'id ASC');
$discussionsub->set_source_table('forum_discussion_subs', array('discussion' => backup::VAR_PARENTID));
$subscription->set_source_table('forum_subscriptions', array('forum' => backup::VAR_PARENTID));
$digest->set_source_table('forum_digests', array('forum' => backup::VAR_PARENTID));
$read->set_source_table('forum_read', array('forumid' => backup::VAR_PARENTID));
$track->set_source_table('forum_track_prefs', array('forumid' => backup::VAR_PARENTID));
$rating->set_source_table('rating', array('contextid' => backup::VAR_CONTEXTID,
'component' => backup_helper::is_sqlparam('mod_forum'),
'ratingarea' => backup_helper::is_sqlparam('post'),
'itemid' => backup::VAR_PARENTID));
$rating->set_source_alias('rating', 'value');
if (core_tag_tag::is_enabled('mod_forum', 'forum_posts')) {
// Backup all tags for all forum posts in this forum.
$tag->set_source_sql('SELECT t.id, ti.itemid, t.rawname
FROM {tag} t
JOIN {tag_instance} ti ON ti.tagid = t.id
WHERE ti.itemtype = ?
AND ti.component = ?
AND ti.contextid = ?', array(
backup_helper::is_sqlparam('forum_posts'),
backup_helper::is_sqlparam('mod_forum'),
backup::VAR_CONTEXTID));
}
$grade->set_source_table('forum_grades', array('forum' => backup::VAR_PARENTID));
}
// Define id annotations
$forum->annotate_ids('scale', 'scale');
$discussion->annotate_ids('group', 'groupid');
$post->annotate_ids('user', 'userid');
$discussionsub->annotate_ids('user', 'userid');
$rating->annotate_ids('scale', 'scaleid');
$rating->annotate_ids('user', 'userid');
$subscription->annotate_ids('user', 'userid');
$digest->annotate_ids('user', 'userid');
$read->annotate_ids('user', 'userid');
$track->annotate_ids('user', 'userid');
$grade->annotate_ids('userid', 'userid');
$grade->annotate_ids('forum', 'forum');
// Define file annotations
$forum->annotate_files('mod_forum', 'intro', null); // This file area hasn't itemid
$post->annotate_files('mod_forum', 'post', 'id');
$post->annotate_files('mod_forum', 'attachment', 'id');
// Return the root element (forum), wrapped into standard activity structure
return $this->prepare_activity_structure($forum);
}
}
@@ -0,0 +1,143 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_forum
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/forum/backup/moodle2/restore_forum_stepslib.php'); // Because it exists (must)
/**
* forum restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_forum_activity_task extends restore_activity_task {
/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// Choice only has one structure step
$this->add_step(new restore_forum_activity_structure_step('forum_structure', 'forum.xml'));
}
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('forum', array('intro'), 'forum');
$contents[] = new restore_decode_content('forum_posts', array('message'), 'forum_post');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
// List of forums in course
$rules[] = new restore_decode_rule('FORUMINDEX', '/mod/forum/index.php?id=$1', 'course');
// Forum by cm->id and forum->id
$rules[] = new restore_decode_rule('FORUMVIEWBYID', '/mod/forum/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('FORUMVIEWBYF', '/mod/forum/view.php?f=$1', 'forum');
// Link to forum discussion
$rules[] = new restore_decode_rule('FORUMDISCUSSIONVIEW', '/mod/forum/discuss.php?d=$1', 'forum_discussion');
// Link to discussion with parent and with anchor posts
$rules[] = new restore_decode_rule('FORUMDISCUSSIONVIEWPARENT', '/mod/forum/discuss.php?d=$1&parent=$2',
array('forum_discussion', 'forum_post'));
$rules[] = new restore_decode_rule('FORUMDISCUSSIONVIEWINSIDE', '/mod/forum/discuss.php?d=$1#$2',
array('forum_discussion', 'forum_post'));
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* forum logs. It must return one array
* of {@link restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('forum', 'add', 'view.php?id={course_module}', '{forum}');
$rules[] = new restore_log_rule('forum', 'update', 'view.php?id={course_module}', '{forum}');
$rules[] = new restore_log_rule('forum', 'view', 'view.php?id={course_module}', '{forum}');
$rules[] = new restore_log_rule('forum', 'view forum', 'view.php?id={course_module}', '{forum}');
$rules[] = new restore_log_rule('forum', 'mark read', 'view.php?f={forum}', '{forum}');
$rules[] = new restore_log_rule('forum', 'start tracking', 'view.php?f={forum}', '{forum}');
$rules[] = new restore_log_rule('forum', 'stop tracking', 'view.php?f={forum}', '{forum}');
$rules[] = new restore_log_rule('forum', 'subscribe', 'view.php?f={forum}', '{forum}');
$rules[] = new restore_log_rule('forum', 'unsubscribe', 'view.php?f={forum}', '{forum}');
$rules[] = new restore_log_rule('forum', 'subscriber', 'subscribers.php?id={forum}', '{forum}');
$rules[] = new restore_log_rule('forum', 'subscribers', 'subscribers.php?id={forum}', '{forum}');
$rules[] = new restore_log_rule('forum', 'view subscribers', 'subscribers.php?id={forum}', '{forum}');
$rules[] = new restore_log_rule('forum', 'add discussion', 'discuss.php?d={forum_discussion}', '{forum_discussion}');
$rules[] = new restore_log_rule('forum', 'view discussion', 'discuss.php?d={forum_discussion}', '{forum_discussion}');
$rules[] = new restore_log_rule('forum', 'move discussion', 'discuss.php?d={forum_discussion}', '{forum_discussion}');
$rules[] = new restore_log_rule('forum', 'delete discussi', 'view.php?id={course_module}', '{forum}',
null, 'delete discussion');
$rules[] = new restore_log_rule('forum', 'delete discussion', 'view.php?id={course_module}', '{forum}');
$rules[] = new restore_log_rule('forum', 'add post', 'discuss.php?d={forum_discussion}&parent={forum_post}', '{forum_post}');
$rules[] = new restore_log_rule('forum', 'update post', 'discuss.php?d={forum_discussion}#p{forum_post}&parent={forum_post}', '{forum_post}');
$rules[] = new restore_log_rule('forum', 'update post', 'discuss.php?d={forum_discussion}&parent={forum_post}', '{forum_post}');
$rules[] = new restore_log_rule('forum', 'prune post', 'discuss.php?d={forum_discussion}', '{forum_post}');
$rules[] = new restore_log_rule('forum', 'delete post', 'discuss.php?d={forum_discussion}', '[post]');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* course logs. It must return one array
* of {@link restore_log_rule} objects
*
* Note this rules are applied when restoring course logs
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules[] = new restore_log_rule('forum', 'view forums', 'index.php?id={course}', null);
$rules[] = new restore_log_rule('forum', 'subscribeall', 'index.php?id={course}', '{course}');
$rules[] = new restore_log_rule('forum', 'unsubscribeall', 'index.php?id={course}', '{course}');
$rules[] = new restore_log_rule('forum', 'user report', 'user.php?course={course}&id={user}&mode=[mode]', '{user}');
$rules[] = new restore_log_rule('forum', 'search', 'search.php?id={course}&search=[searchenc]', '[search]');
return $rules;
}
}
@@ -0,0 +1,307 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_forum
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the restore steps that will be used by the restore_forum_activity_task
*/
/**
* Structure step to restore one forum activity
*/
class restore_forum_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$userinfo = $this->get_setting_value('userinfo');
$paths[] = new restore_path_element('forum', '/activity/forum');
if ($userinfo) {
$paths[] = new restore_path_element('forum_discussion', '/activity/forum/discussions/discussion');
$paths[] = new restore_path_element('forum_post', '/activity/forum/discussions/discussion/posts/post');
$paths[] = new restore_path_element('forum_tag', '/activity/forum/poststags/tag');
$paths[] = new restore_path_element('forum_discussion_sub', '/activity/forum/discussions/discussion/discussion_subs/discussion_sub');
$paths[] = new restore_path_element('forum_rating', '/activity/forum/discussions/discussion/posts/post/ratings/rating');
$paths[] = new restore_path_element('forum_subscription', '/activity/forum/subscriptions/subscription');
$paths[] = new restore_path_element('forum_digest', '/activity/forum/digests/digest');
$paths[] = new restore_path_element('forum_read', '/activity/forum/readposts/read');
$paths[] = new restore_path_element('forum_track', '/activity/forum/trackedprefs/track');
$paths[] = new restore_path_element('forum_grade', '/activity/forum/grades/grade');
}
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_forum($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
if (!isset($data->duedate)) {
$data->duedate = 0;
}
$data->duedate = $this->apply_date_offset($data->duedate);
if (!isset($data->cutoffdate)) {
$data->cutoffdate = 0;
}
$data->cutoffdate = $this->apply_date_offset($data->cutoffdate);
$data->assesstimestart = $this->apply_date_offset($data->assesstimestart);
$data->assesstimefinish = $this->apply_date_offset($data->assesstimefinish);
if ($data->scale < 0) { // scale found, get mapping
$data->scale = -($this->get_mappingid('scale', abs($data->scale)));
}
$newitemid = $DB->insert_record('forum', $data);
$this->apply_activity_instance($newitemid);
// Add current enrolled user subscriptions if necessary.
$data->id = $newitemid;
$ctx = context_module::instance($this->task->get_moduleid());
forum_instance_created($ctx, $data);
}
protected function process_forum_discussion($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
$data->forum = $this->get_new_parentid('forum');
$data->timestart = $this->apply_date_offset($data->timestart);
$data->timeend = $this->apply_date_offset($data->timeend);
$data->userid = $this->get_mappingid('user', $data->userid);
$data->groupid = $this->get_mappingid('group', $data->groupid);
$data->usermodified = $this->get_mappingid('user', $data->usermodified);
$newitemid = $DB->insert_record('forum_discussions', $data);
$this->set_mapping('forum_discussion', $oldid, $newitemid);
}
protected function process_forum_post($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->discussion = $this->get_new_parentid('forum_discussion');
$data->userid = $this->get_mappingid('user', $data->userid);
// If post has parent, map it (it has been already restored)
if (!empty($data->parent)) {
$data->parent = $this->get_mappingid('forum_post', $data->parent);
}
\mod_forum\local\entities\post::add_message_counts($data);
$newitemid = $DB->insert_record('forum_posts', $data);
$this->set_mapping('forum_post', $oldid, $newitemid, true);
// If !post->parent, it's the 1st post. Set it in discussion
if (empty($data->parent)) {
$DB->set_field('forum_discussions', 'firstpost', $newitemid, array('id' => $data->discussion));
}
}
protected function process_forum_tag($data) {
$data = (object)$data;
if (!core_tag_tag::is_enabled('mod_forum', 'forum_posts')) { // Tags disabled in server, nothing to process.
return;
}
$tag = $data->rawname;
if (!$itemid = $this->get_mappingid('forum_post', $data->itemid)) {
// Some orphaned tag, we could not find the restored post for it - ignore.
return;
}
$context = context_module::instance($this->task->get_moduleid());
core_tag_tag::add_item_tag('mod_forum', 'forum_posts', $itemid, $context, $tag);
}
protected function process_forum_rating($data) {
global $DB;
$data = (object)$data;
// Cannot use ratings API, cause, it's missing the ability to specify times (modified/created)
$data->contextid = $this->task->get_contextid();
$data->itemid = $this->get_new_parentid('forum_post');
if ($data->scaleid < 0) { // scale found, get mapping
$data->scaleid = -($this->get_mappingid('scale', abs($data->scaleid)));
}
$data->rating = $data->value;
$data->userid = $this->get_mappingid('user', $data->userid);
// We need to check that component and ratingarea are both set here.
if (empty($data->component)) {
$data->component = 'mod_forum';
}
if (empty($data->ratingarea)) {
$data->ratingarea = 'post';
}
$newitemid = $DB->insert_record('rating', $data);
}
protected function process_forum_subscription($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->forum = $this->get_new_parentid('forum');
$data->userid = $this->get_mappingid('user', $data->userid);
// Create only a new subscription if it does not already exist (see MDL-59854).
if ($subscription = $DB->get_record('forum_subscriptions',
array('forum' => $data->forum, 'userid' => $data->userid))) {
$this->set_mapping('forum_subscription', $oldid, $subscription->id, true);
} else {
$newitemid = $DB->insert_record('forum_subscriptions', $data);
$this->set_mapping('forum_subscription', $oldid, $newitemid, true);
}
}
protected function process_forum_discussion_sub($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->discussion = $this->get_new_parentid('forum_discussion');
$data->forum = $this->get_new_parentid('forum');
$data->userid = $this->get_mappingid('user', $data->userid);
$newitemid = $DB->insert_record('forum_discussion_subs', $data);
$this->set_mapping('forum_discussion_sub', $oldid, $newitemid, true);
}
protected function process_forum_digest($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->forum = $this->get_new_parentid('forum');
$data->userid = $this->get_mappingid('user', $data->userid);
$newitemid = $DB->insert_record('forum_digests', $data);
}
protected function process_forum_grade($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->forum = $this->get_new_parentid('forum');
$data->userid = $this->get_mappingid('user', $data->userid);
// We want to ensure the current user has an ID that we can associate to a grade.
if ($data->userid != 0) {
$newitemid = $DB->insert_record('forum_grades', $data);
// Note - the old contextid is required in order to be able to restore files stored in
// sub plugin file areas attached to the gradeid.
$this->set_mapping('grade', $oldid, $newitemid, false, null, $this->task->get_old_contextid());
$this->set_mapping(restore_gradingform_plugin::itemid_mapping('forum'), $oldid, $newitemid);
}
}
protected function process_forum_read($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->forumid = $this->get_new_parentid('forum');
$data->discussionid = $this->get_mappingid('forum_discussion', $data->discussionid);
$data->postid = $this->get_mappingid('forum_post', $data->postid);
$data->userid = $this->get_mappingid('user', $data->userid);
$newitemid = $DB->insert_record('forum_read', $data);
}
protected function process_forum_track($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->forumid = $this->get_new_parentid('forum');
$data->userid = $this->get_mappingid('user', $data->userid);
$newitemid = $DB->insert_record('forum_track_prefs', $data);
}
protected function after_execute() {
// Add forum related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_forum', 'intro', null);
// Add post related files, matching by itemname = 'forum_post'
$this->add_related_files('mod_forum', 'post', 'forum_post');
$this->add_related_files('mod_forum', 'attachment', 'forum_post');
}
protected function after_restore() {
global $DB;
// If the forum is of type 'single' and no discussion has been ignited
// (non-userinfo backup/restore) create the discussion here, using forum
// information as base for the initial post.
$forumid = $this->task->get_activityid();
$forumrec = $DB->get_record('forum', array('id' => $forumid));
if ($forumrec->type == 'single' && !$DB->record_exists('forum_discussions', array('forum' => $forumid))) {
// Create single discussion/lead post from forum data
$sd = new stdClass();
$sd->course = $forumrec->course;
$sd->forum = $forumrec->id;
$sd->name = $forumrec->name;
$sd->assessed = $forumrec->assessed;
$sd->message = $forumrec->intro;
$sd->messageformat = $forumrec->introformat;
$sd->messagetrust = true;
$sd->mailnow = false;
$sdid = forum_add_discussion($sd, null, null, $this->task->get_userid());
// Mark the post as mailed
$DB->set_field ('forum_posts','mailed', '1', array('discussion' => $sdid));
// Copy all the files from mod_foum/intro to mod_forum/post
$fs = get_file_storage();
$files = $fs->get_area_files($this->task->get_contextid(), 'mod_forum', 'intro');
foreach ($files as $file) {
$newfilerecord = new stdClass();
$newfilerecord->filearea = 'post';
$newfilerecord->itemid = $DB->get_field('forum_discussions', 'firstpost', array('id' => $sdid));
$fs->create_file_from_storedfile($newfilerecord, $file);
}
}
}
}