Skip to content

Commit

Permalink
[MDL-22112]
Browse files Browse the repository at this point in the history
Marc's Patch

Moodle 2 Backups
  • Loading branch information
Jordi Piguillem committed May 12, 2010
1 parent bbfa9be commit ebe93f7
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 5 deletions.
50 changes: 50 additions & 0 deletions mod/wiki/backup/moodle2/backup_wiki_activity_task.class.php
@@ -0,0 +1,50 @@
<?php

require_once($CFG->dirroot . '/mod/wiki/backup/moodle2/backup_wiki_stepslib.php'); // Because it exists (must)
require_once($CFG->dirroot . '/mod/wiki/backup/moodle2/backup_wiki_settingslib.php'); // Because it exists (optional)

/**
* wiki backup task that provides all the settings and steps to perform one
* complete backup of the activity
*/
class backup_wiki_activity_task extends backup_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 backup_wiki_activity_structure_step('wiki_structure', 'wiki.xml'));
}

/**
* Code the transformations to perform in the activity in
* order to get transportable (encoded) links
*/
static public 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;
}
}
27 changes: 27 additions & 0 deletions mod/wiki/backup/moodle2/backup_wiki_settingslib.php
@@ -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 moodlecore
* @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)
137 changes: 137 additions & 0 deletions mod/wiki/backup/moodle2/backup_wiki_stepslib.php
@@ -0,0 +1,137 @@
<?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 moodlecore
* @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', 'redonly'));

$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'));

$comments = new backup_nested_element('comments');

$comment = new backup_nested_element('comment', array('id'), array(
'contextid', 'commentarea', 'content', 'format',
'userid', 'timecreated'));

// 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($comments);
$comments->add_child($comment);

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

$comment->set_source_table('comments', array('itemid' => 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');

$comment->annotate_ids('user', 'userid');

// Define file annotations
$wiki->annotate_files(array('wiki_intro'), null); // This file area hasn't itemid

// Return the root element (wiki), wrapped into standard activity structure
return $this->prepare_activity_structure($wiki);
}

}
12 changes: 7 additions & 5 deletions mod/wiki/lib.php
Expand Up @@ -200,6 +200,8 @@ function wiki_supports($feature) {
return true;
case FEATURE_RATE:
return false;
case FEATURE_BACKUP_MOODLE2:
return true;

default:
return null;
Expand All @@ -224,11 +226,11 @@ function wiki_print_recent_activity($course, $viewfullnames, $timestart) {
global $CFG, $DB, $OUTPUT;

if (!$pages = $DB->get_records_sql("SELECT p.*, w.id as wikiid, sw.groupid
FROM {wiki_pages} p
JOIN {wiki_subwikis} sw ON sw.id = p.subwikiid
JOIN {wiki} w ON w.id = sw.wikiid
WHERE p.timemodified > ? AND w.course = ?
ORDER BY p.timemodified ASC", array($timestart, $course->id))) {
FROM {wiki_pages} p
JOIN {wiki_subwikis} sw ON sw.id = p.subwikiid
JOIN {wiki} w ON w.id = sw.wikiid
WHERE p.timemodified > ? AND w.course = ?
ORDER BY p.timemodified ASC", array($timestart, $course->id))) {
return false;
}
$modinfo =& get_fast_modinfo($course);
Expand Down

0 comments on commit ebe93f7

Please sign in to comment.