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
+123
View File
@@ -0,0 +1,123 @@
<?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_page
* @copyright 2011 Andrew Davis <andrew@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Page conversion handler. This resource handler is called by moodle1_mod_resource_handler
*/
class moodle1_mod_page_handler extends moodle1_resource_successor_handler {
/** @var moodle1_file_manager instance */
protected $fileman = null;
/**
* Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
* Called by moodle1_mod_resource_handler::process_resource()
*/
public function process_legacy_resource(array $data, array $raw = null) {
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid, 'resource');
$moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
// convert the legacy data onto the new page record
$page = array();
$page['id'] = $data['id'];
$page['name'] = $data['name'];
$page['intro'] = $data['intro'];
$page['introformat'] = $data['introformat'];
$page['content'] = $data['alltext'];
if ($data['type'] === 'html') {
// legacy Resource of the type Web page
$page['contentformat'] = FORMAT_HTML;
} else {
// legacy Resource of the type Plain text page
$page['contentformat'] = (int)$data['reference'];
if ($page['contentformat'] < 0 or $page['contentformat'] > 4) {
$page['contentformat'] = FORMAT_MOODLE;
}
}
$page['legacyfiles'] = RESOURCELIB_LEGACYFILES_ACTIVE;
$page['legacyfileslast'] = null;
$page['revision'] = 1;
$page['timemodified'] = $data['timemodified'];
// populate display and displayoptions fields
$options = array('printintro' => 0);
if ($data['popup']) {
$page['display'] = RESOURCELIB_DISPLAY_POPUP;
$rawoptions = explode(',', $data['popup']);
foreach ($rawoptions as $rawoption) {
list($name, $value) = explode('=', trim($rawoption), 2);
if ($value > 0 and ($name == 'width' or $name == 'height')) {
$options['popup'.$name] = $value;
continue;
}
}
} else {
$page['display'] = RESOURCELIB_DISPLAY_OPEN;
}
$page['displayoptions'] = serialize($options);
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_page');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$page['intro'] = moodle1_converter::migrate_referenced_files($page['intro'], $this->fileman);
// convert course files embedded into the content
$this->fileman->filearea = 'content';
$this->fileman->itemid = 0;
$page['content'] = moodle1_converter::migrate_referenced_files($page['content'], $this->fileman);
// write page.xml
$this->open_xml_writer("activities/page_{$moduleid}/page.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
'modulename' => 'page', 'contextid' => $contextid));
$this->write_xml('page', $page, array('/page/id'));
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml for migrated resource file.
$this->open_xml_writer("activities/page_{$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,70 @@
<?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_page_activity_task class
*
* @package mod_page
* @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/page/backup/moodle2/backup_page_stepslib.php');
/**
* Provides the steps to perform one complete backup of the Page instance
*/
class backup_page_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 page.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_page_activity_structure_step('page_structure', 'page.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 pages
$search="/(".$base."\/mod\/page\/index.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@PAGEINDEX*$2@$', $content);
// Link to page view by moduleid
$search="/(".$base."\/mod\/page\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@PAGEVIEWBYID*$2@$', $content);
return $content;
}
}
@@ -0,0 +1,63 @@
<?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_page
* @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;
/**
* Define all the backup steps that will be used by the backup_page_activity_task
*/
/**
* Define the complete page structure for backup, with file and id annotations
*/
class backup_page_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
$page = new backup_nested_element('page', array('id'), array(
'name', 'intro', 'introformat', 'content', 'contentformat',
'legacyfiles', 'legacyfileslast', 'display', 'displayoptions',
'revision', 'timemodified'));
// Build the tree
// (love this)
// Define sources
$page->set_source_table('page', array('id' => backup::VAR_ACTIVITYID));
// Define id annotations
// (none)
// Define file annotations
$page->annotate_files('mod_page', 'intro', null); // This file areas haven't itemid
$page->annotate_files('mod_page', 'content', null); // This file areas haven't itemid
// Return the root element (page), wrapped into standard activity structure
return $this->prepare_activity_structure($page);
}
}
@@ -0,0 +1,109 @@
<?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_page
* @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/page/backup/moodle2/restore_page_stepslib.php'); // Because it exists (must)
/**
* page restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_page_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() {
// label only has one structure step
$this->add_step(new restore_page_activity_structure_step('page_structure', 'page.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('page', array('intro', 'content'), '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('PAGEVIEWBYID', '/mod/page/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('PAGEINDEX', '/mod/page/index.php?id=$1', 'course');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* page 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('page', 'add', 'view.php?id={course_module}', '{page}');
$rules[] = new restore_log_rule('page', 'update', 'view.php?id={course_module}', '{page}');
$rules[] = new restore_log_rule('page', 'view', 'view.php?id={course_module}', '{page}');
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('page', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,64 @@
<?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_page
* @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
*/
/**
* Define all the restore steps that will be used by the restore_page_activity_task
*/
/**
* Structure step to restore one page activity
*/
class restore_page_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$paths[] = new restore_path_element('page', '/activity/page');
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_page($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.
// insert the page record
$newitemid = $DB->insert_record('page', $data);
// immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}
protected function after_execute() {
// Add page related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_page', 'intro', null);
$this->add_related_files('mod_page', 'content', null);
}
}