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
+309
View File
@@ -0,0 +1,309 @@
<?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
* Based off of a template @ http://docs.moodle.org/dev/Backup_1.9_conversion_for_developers
*
* @package mod_wiki
* @copyright 2011 Aparup Banerjee <aparup@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Wiki conversion handler
*/
class moodle1_mod_wiki_handler extends moodle1_mod_handler {
/** @var string initial content for creating first page from the optional 1.9 wiki file */
protected $initialcontent;
/** @var string */
protected $initialcontentfilename;
/** @var bool initial content page already exists */
protected $needinitpage = false;
/** @var array a data element transfer buffer, can be used for transfer of data between xml path levels. */
protected $databuf = array();
/** @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 path /MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI does 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(
'wiki', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI',
array(
'newfields' => array(
'introformat' => '0',
'defaultformat' => 'html', //1.9 migrations default to html
'forceformat' => '1',
'editbegin' => '0',
'editend' => '0',
'timecreated' => time(), //2.x time of creation since theres no 1.9 time of creation
),
'renamefields' => array(
'summary' => 'intro',
'format' => 'introformat',
'firstpagetitle' => 'pagename',
'wtype' => 'wikimode'
),
'dropfields' => array(
'pagename', 'scaleid', 'ewikiprinttitle', 'htmlmode', 'ewikiacceptbinary', 'disablecamelcase',
'setpageflags', 'strippages', 'removepages', 'revertchanges'
)
)
),
new convert_path(
'wiki_entries', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI/ENTRIES',
array(
'newfields' => array(
'synonyms' => '0',
'links' => 'collaborative',
),
'dropfields' => array(
'pagename' ,'timemodified'
)
)
),
new convert_path(
'wiki_entry', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI/ENTRIES/ENTRY'
),
new convert_path(
'wiki_pages', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI/ENTRIES/ENTRY/PAGES'
),
new convert_path(
'wiki_entry_page', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI/ENTRIES/ENTRY/PAGES/PAGE',
array(
'newfields' => array(
'cachedcontent' => '**reparse needed**',
'timerendered' => '0',
'readonly' => '0',
'tags' => ''
),
'renamefields' => array(
'pagename' => 'title',
'created' => 'timecreated',
'lastmodified' => 'timemodified',
'hits' => 'pageviews'
),
'dropfields' => array(
'version', 'flags', 'author', 'refs', //refs will be reparsed during rendering
'meta'
)
)
)
);
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI
* data available
*/
public function process_wiki($data) {
global $CFG; // We need to check a config setting.
if (!empty($data['initialcontent'])) {
//convert file in <INITIALCONTENT>filename</INITIALCONTENT> into a subwiki page if no entry created.
$temppath = $this->converter->get_tempdir_path();
$filename = clean_param($data['initialcontent'], PARAM_FILE);
$this->initialcontent = file_get_contents($temppath . '/course_files/' . $filename);
$this->initialcontentfilename = $filename;
$this->needinitpage = true;
}
unset($data['initialcontent']);
if ($data['wikimode'] !== 'group') {
$data['wikimode'] = 'individual';
//@todo need to create extra subwikis due to individual wikimode?
//this would then need to reference the users in the course that is being restored.(some parent class API needed)
} else {
$data['wikimode'] = 'collaborative';
}
if (empty($data['name'])) {
$data['name'] = 'Wiki';
}
// 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_wiki');
// 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;
}
// we now have all information needed to start writing into the file
$this->open_xml_writer("activities/wiki_{$this->moduleid}/wiki.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
'modulename' => 'wiki', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('wiki', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field <> 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
return $data;
}
public function on_wiki_entries_start() {
$this->xmlwriter->begin_tag('subwikis');
$this->needinitpage = false; //backup has entries, so the initial_content file has been stored as a page in 1.9.
}
public function on_wiki_entries_end() {
$this->xmlwriter->end_tag('subwikis');
}
public function process_wiki_entry($data) {
$this->xmlwriter->begin_tag('subwiki', array('id' => $data['id']));
unset($data['id']);
unset($data['pagename']);
unset($data['timemodified']);
foreach ($data as $field => $value) {
$this->xmlwriter->full_tag($field, $value);
}
}
public function on_wiki_entry_end() {
$this->xmlwriter->end_tag('subwiki');
}
public function on_wiki_pages_start() {
$this->xmlwriter->begin_tag('pages');
}
public function on_wiki_pages_end() {
$this->xmlwriter->end_tag('pages');
}
public function process_wiki_entry_page($data) {
// assimilate data to create later in extra virtual path page/versions/version/
$this->databuf['id'] = $this->converter->get_nextid();
$this->databuf['content'] = $data['content'];
unset($data['content']);
$this->databuf['contentformat'] = 'html';
$this->databuf['version'] = 0;
$this->databuf['timecreated'] = $data['timecreated']; //do not unset, is reused
$this->databuf['userid'] = $data['userid']; //do not unset, is reused
// process page data (user data and also the one that is from <initialcontent>
$this->xmlwriter->begin_tag('page', array('id' => $data['id']));
unset($data['id']); // we already write it as attribute, do not repeat it as child element
foreach ($data as $field => $value) {
$this->xmlwriter->full_tag($field, $value);
}
// process page content as a version.
$this->xmlwriter->begin_tag('versions');
$this->write_xml('version', $this->databuf, array('/version/id')); //version id from get_nextid()
$this->xmlwriter->end_tag('versions');
}
public function on_wiki_entry_page_end() {
$this->xmlwriter->end_tag('page');
}
/**
* This is executed when we reach the closing </MOD> tag of our 'wiki' path
*/
public function on_wiki_end() {
global $USER;
//check if the initial content needs to be created (and if a page is already there for it)
if ($this->initialcontentfilename && $this->needinitpage) {
//contruct (synthetic - not for cooking) a full path for creating entries/entry/pages/page
$data_entry = array(
'id' => $this->converter->get_nextid(), //creating the first entry
'groupid' => 0,
'userid' => 0,
'synonyms' => '',
'links' => ''
);
$data_page = array(
'id' => $this->converter->get_nextid(), //just creating the first page in the wiki
'title' => $this->initialcontentfilename,
'content' => $this->initialcontent,
'userid' => $USER->id,
'timecreated' => time(),
'timemodified' => 0,
'pageviews' => 0,
'cachedcontent' => '**reparse needed**',
'timerendered' => 0,
'readonly' => 0,
'tags' => ''
);
//create xml with constructed page data (from initial_content file).
$this->on_wiki_entries_start();
$this->process_wiki_entry($data_entry);
$this->on_wiki_pages_start();
$this->process_wiki_entry_page($data_page);
$this->on_wiki_entry_page_end();
$this->on_wiki_pages_end();
$this->on_wiki_entry_end();
$this->on_wiki_entries_end();
}
//close wiki.xml
$this->xmlwriter->end_tag('wiki');
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml
$this->open_xml_writer("activities/wiki_{$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,75 @@
<?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_wiki_activity_task class
*
* @package mod_wiki
* @category backup
* @copyright 2010 Jordi Piguillem <pigui0@hotmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/wiki/backup/moodle2/backup_wiki_stepslib.php');
require_once($CFG->dirroot . '/mod/wiki/backup/moodle2/backup_wiki_settingslib.php');
/**
* Provides all the settings and steps to perform one complete backup of the activity
*/
class backup_wiki_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 wiki.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_wiki_activity_structure_step('wiki_structure', 'wiki.xml'));
}
/**
* Encodes URLs to the index.php and view.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 wikis
$search = "/(" . $base . "\/mod\/wiki\/index.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@WIKIINDEX*$2@$', $content);
// Link to wiki view by moduleid
$search = "/(" . $base . "\/mod\/wiki\/view.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@WIKIVIEWBYID*$2@$', $content);
// Link to wiki view by pageid
$search = "/(" . $base . "\/mod\/wiki\/view.php\?pageid\=)([0-9]+)/";
$content = preg_replace($search, '$@WIKIPAGEBYID*$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_wiki
* @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,131 @@
<?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_wiki
* @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_wiki_activity_task
*/
/**
* Define the complete wiki structure for backup, with file and id annotations
*/
class backup_wiki_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
$wiki = new backup_nested_element('wiki', array('id'), array('name', 'intro', 'introformat', 'timecreated', 'timemodified', 'firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend'));
$subwikis = new backup_nested_element('subwikis');
$subwiki = new backup_nested_element('subwiki', array('id'), array('groupid', 'userid'));
$pages = new backup_nested_element('pages');
$page = new backup_nested_element('page', array('id'), array('title', 'cachedcontent', 'timecreated', 'timemodified', 'timerendered', 'userid', 'pageviews', 'readonly'));
$synonyms = new backup_nested_element('synonyms');
$synonym = new backup_nested_element('synonym', array('id'), array('pageid', 'pagesynonym'));
$links = new backup_nested_element('links');
$link = new backup_nested_element('link', array('id'), array('frompageid', 'topageid', 'tomissingpage'));
$versions = new backup_nested_element('versions');
$version = new backup_nested_element('version', array('id'), array('content', 'contentformat', 'version', 'timecreated', 'userid'));
$tags = new backup_nested_element('tags');
$tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));
// Build the tree
$wiki->add_child($subwikis);
$subwikis->add_child($subwiki);
$subwiki->add_child($pages);
$pages->add_child($page);
$subwiki->add_child($synonyms);
$synonyms->add_child($synonym);
$subwiki->add_child($links);
$links->add_child($link);
$page->add_child($versions);
$versions->add_child($version);
$page->add_child($tags);
$tags->add_child($tag);
// Define sources
$wiki->set_source_table('wiki', array('id' => backup::VAR_ACTIVITYID));
// All these source definitions only happen if we are including user info
if ($userinfo) {
$subwiki->set_source_sql('
SELECT *
FROM {wiki_subwikis}
WHERE wikiid = ?', array(backup::VAR_PARENTID));
$page->set_source_table('wiki_pages', array('subwikiid' => backup::VAR_PARENTID));
$synonym->set_source_table('wiki_synonyms', array('subwikiid' => backup::VAR_PARENTID));
$link->set_source_table('wiki_links', array('subwikiid' => backup::VAR_PARENTID));
$version->set_source_table('wiki_versions', array('pageid' => backup::VAR_PARENTID));
$tag->set_source_sql('SELECT t.id, t.name, t.rawname
FROM {tag} t
JOIN {tag_instance} ti ON ti.tagid = t.id
WHERE ti.itemtype = ?
AND ti.component = ?
AND ti.itemid = ?', array(
backup_helper::is_sqlparam('wiki_pages'),
backup_helper::is_sqlparam('mod_wiki'),
backup::VAR_PARENTID));
}
// Define id annotations
$subwiki->annotate_ids('group', 'groupid');
$subwiki->annotate_ids('user', 'userid');
$page->annotate_ids('user', 'userid');
$version->annotate_ids('user', 'userid');
// Define file annotations
$wiki->annotate_files('mod_wiki', 'intro', null); // This file area hasn't itemid
$subwiki->annotate_files('mod_wiki', 'attachments', 'id'); // This file area hasn't itemid
// Return the root element (wiki), wrapped into standard activity structure
return $this->prepare_activity_structure($wiki);
}
}
@@ -0,0 +1,120 @@
<?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_wiki
* @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/wiki/backup/moodle2/restore_wiki_stepslib.php'); // Because it exists (must)
/**
* wiki restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_wiki_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() {
// wiki only has one structure step
$this->add_step(new restore_wiki_activity_structure_step('wiki_structure', 'wiki.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('wiki', array('intro'), 'wiki');
$contents[] = new restore_decode_content('wiki_versions', array('content'), 'wiki_version');
$contents[] = new restore_decode_content('wiki_pages', array('cachedcontent'), 'wiki_page');
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();
$rules[] = new restore_decode_rule('WIKIINDEX', '/mod/wiki/index.php?id=$1', 'course');
$rules[] = new restore_decode_rule('WIKIVIEWBYID', '/mod/wiki/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('WIKIPAGEBYID', '/mod/wiki/view.php?pageid=$1', 'wiki_page');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* wiki 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('wiki', 'add', 'view.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'update', 'view.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'view', 'view.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'comments', 'comments.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'diff', 'diff.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'edit', 'edit.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'history', 'history.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'map', 'map.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('wiki', 'overridelocks', 'overridelocks.php?id={course_module}', '{wiki}');
/// TODO: Examine these 2 rules, because module is not "wiki", and it shouldn't happen
$rules[] = new restore_log_rule('restore', 'restore', 'view.php?id={course_module}', '{wiki}');
$rules[] = new restore_log_rule('createpage', 'createpage', 'view.php?id={course_module}', '{wiki}');
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('wiki', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,177 @@
<?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_wiki
* @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_wiki_activity_task
*/
/**
* Structure step to restore one wiki activity
*/
class restore_wiki_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('wiki', '/activity/wiki');
if ($userinfo) {
$paths[] = new restore_path_element('wiki_subwiki', '/activity/wiki/subwikis/subwiki');
$paths[] = new restore_path_element('wiki_page', '/activity/wiki/subwikis/subwiki/pages/page');
$paths[] = new restore_path_element('wiki_version', '/activity/wiki/subwikis/subwiki/pages/page/versions/version');
$paths[] = new restore_path_element('wiki_tag', '/activity/wiki/subwikis/subwiki/pages/page/tags/tag');
$paths[] = new restore_path_element('wiki_synonym', '/activity/wiki/subwikis/subwiki/synonyms/synonym');
$paths[] = new restore_path_element('wiki_link', '/activity/wiki/subwikis/subwiki/links/link');
}
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_wiki($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.
$data->editbegin = $this->apply_date_offset($data->editbegin);
$data->editend = $this->apply_date_offset($data->editend);
$data->defaultformat = clean_param($data->defaultformat, PARAM_ALPHA);
// insert the wiki record
$newitemid = $DB->insert_record('wiki', $data);
// immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}
protected function process_wiki_subwiki($data) {
global $DB;
$data = (object) $data;
$oldid = $data->id;
$data->wikiid = $this->get_new_parentid('wiki');
// If the groupid is not equal to zero, get the mapping for the group.
if ((int) $data->groupid !== 0) {
$data->groupid = $this->get_mappingid('group', $data->groupid);
}
// If the userid is not equal to zero, get the mapping for the user.
if ((int) $data->userid !== 0) {
$data->userid = $this->get_mappingid('user', $data->userid);
}
// If these values are not equal to false then a mapping was successfully made.
if ($data->groupid !== false && $data->userid !== false) {
$newitemid = $DB->insert_record('wiki_subwikis', $data);
} else {
$newitemid = false;
}
$this->set_mapping('wiki_subwiki', $oldid, $newitemid, true);
}
protected function process_wiki_page($data) {
global $DB;
$data = (object) $data;
$oldid = $data->id;
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
$data->userid = $this->get_mappingid('user', $data->userid);
// Check that we were able to get a parentid for this page.
if ($data->subwikiid !== false) {
$newitemid = $DB->insert_record('wiki_pages', $data);
} else {
$newitemid = false;
}
$this->set_mapping('wiki_page', $oldid, $newitemid, true);
}
protected function process_wiki_version($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->pageid = $this->get_new_parentid('wiki_page');
$data->userid = $this->get_mappingid('user', $data->userid);
$data->contentformat = clean_param($data->contentformat, PARAM_ALPHA);
$newitemid = $DB->insert_record('wiki_versions', $data);
$this->set_mapping('wiki_version', $oldid, $newitemid);
}
protected function process_wiki_synonym($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
$data->pageid = $this->get_mappingid('wiki_page', $data->pageid);
$newitemid = $DB->insert_record('wiki_synonyms', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_wiki_link($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
$data->frompageid = $this->get_mappingid('wiki_page', $data->frompageid);
$data->topageid = $this->get_mappingid('wiki_page', $data->topageid);
$newitemid = $DB->insert_record('wiki_links', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_wiki_tag($data) {
global $CFG, $DB;
$data = (object)$data;
$oldid = $data->id;
if (!core_tag_tag::is_enabled('mod_wiki', 'wiki_pages')) { // Tags disabled in server, nothing to process.
return;
}
$tag = $data->rawname;
$itemid = $this->get_new_parentid('wiki_page');
$wikiid = $this->get_new_parentid('wiki');
$context = context_module::instance($this->task->get_moduleid());
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $itemid, $context, $tag);
}
protected function after_execute() {
// Add wiki related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_wiki', 'intro', null);
$this->add_related_files('mod_wiki', 'attachments', 'wiki_subwiki');
}
}