Skip to content

Commit

Permalink
[MDL-22112]
Browse files Browse the repository at this point in the history
Formatting the code
  • Loading branch information
Jordi Piguillem committed May 14, 2010
1 parent 3e12336 commit ab6df97
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 59 deletions.
34 changes: 17 additions & 17 deletions mod/wiki/backup/moodle2/backup_wiki_activity_task.class.php
Original file line number Diff line number Diff line change
@@ -1,50 +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'));
$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;
global $CFG;

$base = preg_quote($CFG->wwwroot, "/");

$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);
$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);
$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);
$search = "/(" . $base . "\/mod\/wiki\/view.php\?pageid\=)([0-9]+)/";
$content = preg_replace($search, '$@WIKIPAGEBYID*$2@$', $content);

return $content;
}
}
71 changes: 29 additions & 42 deletions mod/wiki/backup/moodle2/backup_wiki_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* 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
*/
Expand All @@ -37,46 +37,34 @@ protected function define_structure() {
$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'));
$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'));
$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'));
$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'));
$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'));
$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'));

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


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

// Build the tree
$wiki->add_child($subwikis);
$wiki->add_child($subwikis);
$subwikis->add_child($subwiki);

$subwiki->add_child($pages);
Expand All @@ -90,45 +78,44 @@ protected function define_structure() {

$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));
$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('
if ($userinfo) {
$subwiki->set_source_sql('
SELECT *
FROM {wiki_subwikis}
WHERE wikiid = ?',
array(backup::VAR_PARENTID));
WHERE wikiid = ?', array(backup::VAR_PARENTID));

$page->set_source_table('wiki_pages', array('subwikiid' => 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));

$synonym->set_source_table('wiki_synonyms', array('subwikiid' => backup::VAR_PARENTID));
$link->set_source_table('wiki_links', 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));

$version->set_source_table('wiki_versions', array('pageid' => backup::VAR_PARENTID));

$comment->set_source_table('comments', array('itemid' => backup::VAR_PARENTID));
$comment->set_source_table('comments', array('itemid' => backup::VAR_PARENTID));
}

// Define id annotations
$subwiki->annotate_ids('group', 'groupid');
$subwiki->annotate_ids('group', 'groupid');

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

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

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

$comment->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
$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);
Expand Down

0 comments on commit ab6df97

Please sign in to comment.