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
+172
View File
@@ -0,0 +1,172 @@
<?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_data
* @copyright 2011 Aparup Banerjee <aparup@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Database conversion handler
*/
class moodle1_mod_data_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 path /MOODLE_BACKUP/COURSE/MODULES/MOD/DATA 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('data', '/MOODLE_BACKUP/COURSE/MODULES/MOD/DATA',
array(
'newfields' => array(
'introformat' => 0,
'assesstimestart' => 0,
'assesstimefinish' => 0,
)
)
),
new convert_path('data_field', '/MOODLE_BACKUP/COURSE/MODULES/MOD/DATA/FIELDS/FIELD')
);
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/DATA
* data available
*/
public function process_data($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);
// replay the upgrade step 2007101512
if (!array_key_exists('asearchtemplate', $data)) {
$data['asearchtemplate'] = null;
}
// replay the upgrade step 2007101513
if (is_null($data['notification'])) {
$data['notification'] = 0;
}
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_data');
// 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);
// @todo: user data - upgrade content to new file storage
// add 'export' tag to list and single template.
$pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/';
$replacement = '##delete##$1##approve##$1##export##';
$data['listtemplate'] = preg_replace($pattern, $replacement, $data['listtemplate']);
$data['singletemplate'] = preg_replace($pattern, $replacement, $data['singletemplate']);
//@todo: user data - move data comments to comments table
//@todo: user data - move data ratings to ratings table
// start writing data.xml
$this->open_xml_writer("activities/data_{$this->moduleid}/data.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
'modulename' => 'data', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('data', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field <> 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
$this->xmlwriter->begin_tag('fields');
return $data;
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/DATA/FIELDS/FIELD
* data available
*/
public function process_data_field($data) {
// process database fields
$this->write_xml('field', $data, array('/field/id'));
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/DATA/RECORDS/RECORD
* data available
*/
public function process_data_record($data) {
//@todo process user data, and define the convert path in get_paths() above.
//$this->write_xml('record', $data, array('/record/id'));
}
/**
* This is executed when we reach the closing </MOD> tag of our 'data' path
*/
public function on_data_end() {
// finish writing data.xml
$this->xmlwriter->end_tag('fields');
$this->xmlwriter->end_tag('data');
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml
$this->open_xml_writer("activities/data_{$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,78 @@
<?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_data_activity_task
*
* @package mod_data
* @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/data/backup/moodle2/backup_data_stepslib.php');
/**
* Provides the steps to perform one complete backup of the Database instance
*/
class backup_data_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 data.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_data_activity_structure_step('data_structure', 'data.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 datas
$search="/(".$base."\/mod\/data\/index.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@DATAINDEX*$2@$', $content);
// Link to data view by moduleid
$search="/(".$base."\/mod\/data\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@DATAVIEWBYID*$2@$', $content);
/// Link to database view by databaseid
$search="/(".$base."\/mod\/data\/view.php\?d\=)([0-9]+)/";
$content= preg_replace($search,'$@DATAVIEWBYD*$2@$', $content);
/// Link to one "record" of the database
$search="/(".$base."\/mod\/data\/view.php\?d\=)([0-9]+)\&(amp;)rid\=([0-9]+)/";
$content= preg_replace($search,'$@DATAVIEWRECORD*$2*$4@$', $content);
return $content;
}
}
@@ -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_data
* @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_data_activity_task
*/
/**
* Define the complete data structure for backup, with file and id annotations
*/
class backup_data_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
$data = new backup_nested_element('data', array('id'), array(
'name', 'intro', 'introformat', 'comments',
'timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto',
'requiredentries', 'requiredentriestoview', 'maxentries', 'rssarticles',
'singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate',
'jstemplate', 'asearchtemplate', 'approval', 'manageapproved', 'scale',
'assessed', 'assesstimestart', 'assesstimefinish', 'defaultsort',
'defaultsortdir', 'editany', 'notification', 'timemodified', 'config', 'completionentries'));
$tags = new backup_nested_element('recordstags');
$tag = new backup_nested_element('tag', array('id'), array('itemid', 'rawname'));
$fields = new backup_nested_element('fields');
$field = new backup_nested_element('field', array('id'), array(
'type', 'name', 'description', 'required', 'param1', 'param2',
'param3', 'param4', 'param5', 'param6',
'param7', 'param8', 'param9', 'param10'));
$records = new backup_nested_element('records');
$record = new backup_nested_element('record', array('id'), array(
'userid', 'groupid', 'timecreated', 'timemodified',
'approved'));
$contents = new backup_nested_element('contents');
$content = new backup_nested_element('content', array('id'), array(
'fieldid', 'content', 'content1', 'content2',
'content3', 'content4'));
$ratings = new backup_nested_element('ratings');
$rating = new backup_nested_element('rating', array('id'), array(
'component', 'ratingarea', 'scaleid', 'value', 'userid', 'timecreated', 'timemodified'));
// Build the tree
$data->add_child($fields);
$fields->add_child($field);
$data->add_child($records);
$records->add_child($record);
$record->add_child($contents);
$contents->add_child($content);
$record->add_child($ratings);
$ratings->add_child($rating);
$data->add_child($tags);
$tags->add_child($tag);
// Define sources
$data->set_source_table('data', array('id' => backup::VAR_ACTIVITYID));
$field->set_source_sql('
SELECT *
FROM {data_fields}
WHERE dataid = ?',
array(backup::VAR_PARENTID));
// All the rest of elements only happen if we are including user info
if ($userinfo) {
$record->set_source_table('data_records', array('dataid' => backup::VAR_PARENTID));
$content->set_source_table('data_content', array('recordid' => backup::VAR_PARENTID));
$rating->set_source_table('rating', array('contextid' => backup::VAR_CONTEXTID,
'itemid' => backup::VAR_PARENTID,
'component' => backup_helper::is_sqlparam('mod_data'),
'ratingarea' => backup_helper::is_sqlparam('entry')));
$rating->set_source_alias('rating', 'value');
if (core_tag_tag::is_enabled('mod_data', 'data_records')) {
$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('data_records'),
backup_helper::is_sqlparam('mod_data'),
backup::VAR_CONTEXTID));
}
}
// Define id annotations
$data->annotate_ids('scale', 'scale');
$record->annotate_ids('user', 'userid');
$record->annotate_ids('group', 'groupid');
$rating->annotate_ids('scale', 'scaleid');
$rating->annotate_ids('user', 'userid');
// Define file annotations
$data->annotate_files('mod_data', 'intro', null); // This file area hasn't itemid
$content->annotate_files('mod_data', 'content', 'id'); // By content->id
// Return the root element (data), wrapped into standard activity structure
return $this->prepare_activity_structure($data);
}
}
@@ -0,0 +1,138 @@
<?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_data
* @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/data/backup/moodle2/restore_data_stepslib.php'); // Because it exists (must)
/**
* data restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_data_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() {
// Data only has one structure step
$this->add_step(new restore_data_activity_structure_step('data_structure', 'data.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('data', array(
'intro', 'singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
'addtemplate', 'rsstemplate', 'rsstitletemplate', 'asearchtemplate'), 'data');
$contents[] = new restore_decode_content('data_fields', array(
'description', 'param1', 'param2', 'param3',
'param4', 'param5', 'param6', 'param7',
'param8', 'param9', 'param10'), 'data_field');
$contents[] = new restore_decode_content('data_content', array(
'content', 'content1', 'content2', 'content3', 'content4'));
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('DATAVIEWBYID', '/mod/data/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('DATAVIEWBYD', '/mod/data/view.php?d=$1', 'data');
$rules[] = new restore_decode_rule('DATAINDEX', '/mod/data/index.php?id=$1', 'course');
$rules[] = new restore_decode_rule('DATAVIEWRECORD', '/mod/data/view.php?d=$1&amp;rid=$2', array('data', 'data_record'));
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* data 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('data', 'add', 'view.php?d={data}&rid={data_record}', '{data}');
$rules[] = new restore_log_rule('data', 'update', 'view.php?d={data}&rid={data_record}', '{data}');
$rules[] = new restore_log_rule('data', 'view', 'view.php?id={course_module}', '{data}');
$rules[] = new restore_log_rule('data', 'record delete', 'view.php?id={course_module}', '{data}');
$rules[] = new restore_log_rule('data', 'fields add', 'field.php?d={data}&mode=display&fid={data_field}', '{data_field}');
$rules[] = new restore_log_rule('data', 'fields update', 'field.php?d={data}&mode=display&fid={data_field}', '{data_field}');
$rules[] = new restore_log_rule('data', 'fields delete', 'field.php?d={data}', '[name]');
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('data', 'view all', 'index.php?id={course}', null);
return $rules;
}
/**
* Given a commment area, return the itemname that contains the itemid mappings.
*
* @param string $commentarea Comment area name e.g. database_entry.
* @return string name of the mapping used to determine the itemid.
*/
public function get_comment_mapping_itemname($commentarea) {
if ($commentarea == 'database_entry') {
$itemname = 'data_record';
} else {
$itemname = parent::get_comment_mapping_itemname($commentarea);
}
return $itemname;
}
}
@@ -0,0 +1,186 @@
<?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_data
* @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_data_activity_task
*/
/**
* Structure step to restore one data activity
*/
class restore_data_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('data', '/activity/data');
$paths[] = new restore_path_element('data_field', '/activity/data/fields/field');
if ($userinfo) {
$paths[] = new restore_path_element('data_record', '/activity/data/records/record');
$paths[] = new restore_path_element('data_content', '/activity/data/records/record/contents/content');
$paths[] = new restore_path_element('data_rating', '/activity/data/records/record/ratings/rating');
$paths[] = new restore_path_element('data_record_tag', '/activity/data/recordstags/tag');
}
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_data($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->timeavailablefrom = $this->apply_date_offset($data->timeavailablefrom);
$data->timeavailableto = $this->apply_date_offset($data->timeavailableto);
$data->timeviewfrom = $this->apply_date_offset($data->timeviewfrom);
$data->timeviewto = $this->apply_date_offset($data->timeviewto);
$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)));
}
// Some old backups can arrive with data->notification = null (MDL-24470)
// convert them to proper column default (zero)
if (is_null($data->notification)) {
$data->notification = 0;
}
// insert the data record
$newitemid = $DB->insert_record('data', $data);
$this->apply_activity_instance($newitemid);
}
protected function process_data_field($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->dataid = $this->get_new_parentid('data');
$data->type = clean_param($data->type, PARAM_ALPHA);
// insert the data_fields record
$newitemid = $DB->insert_record('data_fields', $data);
$this->set_mapping('data_field', $oldid, $newitemid, false); // no files associated
}
protected function process_data_record($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->userid = $this->get_mappingid('user', $data->userid);
$data->groupid = $this->get_mappingid('group', $data->groupid);
$data->dataid = $this->get_new_parentid('data');
// insert the data_records record
$newitemid = $DB->insert_record('data_records', $data);
$this->set_mapping('data_record', $oldid, $newitemid, false); // no files associated
}
protected function process_data_content($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->fieldid = $this->get_mappingid('data_field', $data->fieldid);
$data->recordid = $this->get_new_parentid('data_record');
// insert the data_content record
$newitemid = $DB->insert_record('data_content', $data);
$this->set_mapping('data_content', $oldid, $newitemid, true); // files by this itemname
}
/**
* Add tags to restored records.
*
* @param stdClass $data Tag
*/
protected function process_data_record_tag($data) {
$data = (object)$data;
if (!core_tag_tag::is_enabled('mod_data', 'data_records')) { // Tags disabled in server, nothing to process.
return;
}
if (!$itemid = $this->get_mappingid('data_record', $data->itemid)) {
// Some orphaned tag, we could not find the data record for it - ignore.
return;
}
$tag = $data->rawname;
$context = context_module::instance($this->task->get_moduleid());
core_tag_tag::add_item_tag('mod_data', 'data_records', $itemid, $context, $tag);
}
protected function process_data_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('data_record');
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_data';
}
if (empty($data->ratingarea)) {
$data->ratingarea = 'entry';
}
$newitemid = $DB->insert_record('rating', $data);
}
protected function after_execute() {
global $DB;
// Add data related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_data', 'intro', null);
// Add content related files, matching by itemname (data_content)
$this->add_related_files('mod_data', 'content', 'data_content');
// Adjust the data->defaultsort field
if ($defaultsort = $DB->get_field('data', 'defaultsort', array('id' => $this->get_new_parentid('data')))) {
if ($defaultsort = $this->get_mappingid('data_field', $defaultsort)) {
$DB->set_field('data', 'defaultsort', $defaultsort, array('id' => $this->get_new_parentid('data')));
}
}
}
}