MDL-30610 remove outdated mod upgrade code
This commit is contained in:
@@ -25,137 +25,6 @@ function xmldb_assignment_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2007101511) {
|
||||
// change grade typo to text if no grades MDL-13920
|
||||
require_once $CFG->dirroot.'/mod/assignment/lib.php';
|
||||
assignment_upgrade_grades();
|
||||
upgrade_mod_savepoint(true, 2007101511, 'assignment');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008081900) {
|
||||
|
||||
/////////////////////////////////////
|
||||
/// new file storage upgrade code ///
|
||||
/////////////////////////////////////
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$sqlfrom = "FROM {assignment_submissions} s
|
||||
JOIN {assignment} a ON a.id = s.assignment
|
||||
JOIN {modules} m ON m.name = 'assignment'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = a.id)";
|
||||
|
||||
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
|
||||
|
||||
$rs = $DB->get_recordset_sql("SELECT s.id, s.userid, s.teacher, s.assignment, a.course, cm.id AS cmid $sqlfrom ORDER BY a.course, s.assignment");
|
||||
|
||||
if ($rs->valid()) {
|
||||
$pbar = new progress_bar('migrateassignmentfiles', 500, true);
|
||||
$i = 0;
|
||||
foreach ($rs as $submission) {
|
||||
$i++;
|
||||
upgrade_set_timeout(180); // set up timeout, may also abort execution
|
||||
$pbar->update($i, $count, "Migrating assignment submissions - $i/$count.");
|
||||
|
||||
$basepath = "$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->userid/";
|
||||
if (!file_exists($basepath)) {
|
||||
//no files
|
||||
continue;
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_MODULE, $submission->cmid);
|
||||
|
||||
// migrate submitted files first
|
||||
$path = $basepath;
|
||||
$items = new DirectoryIterator($path);
|
||||
foreach ($items as $item) {
|
||||
if (!$item->isFile()) {
|
||||
continue;
|
||||
}
|
||||
if (!$item->isReadable()) {
|
||||
echo $OUTPUT->notification(" File not readable, skipping: ".$path.$item->getFilename());
|
||||
continue;
|
||||
}
|
||||
$filename = clean_param($item->getFilename(), PARAM_FILE);
|
||||
if ($filename === '') {
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, 'mod_assignment', 'submission', $submission->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_assignment', 'filearea'=>'submission', 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$submission->userid);
|
||||
if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
|
||||
unlink($path.$item->getFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($items); //release file handles
|
||||
|
||||
// migrate teacher response files for "upload" subtype, unfortunately we do not
|
||||
$path = $basepath.'responses/';
|
||||
if (file_exists($path)) {
|
||||
$items = new DirectoryIterator($path);
|
||||
foreach ($items as $item) {
|
||||
if (!$item->isFile()) {
|
||||
continue;
|
||||
}
|
||||
$filename = clean_param($item->getFilename(), PARAM_FILE);
|
||||
if ($filename === '') {
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, 'mod_assignment', 'response', $submission->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_assignment', 'filearea'=>'response', 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename,
|
||||
'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime());
|
||||
if ($submission->teacher) {
|
||||
$file_record['userid'] = $submission->teacher;
|
||||
}
|
||||
if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) {
|
||||
unlink($path.$item->getFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($items); //release file handles
|
||||
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->userid/responses");
|
||||
}
|
||||
|
||||
// remove dirs if empty
|
||||
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->userid");
|
||||
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment");
|
||||
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment");
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008081900, 'assignment');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042000) {
|
||||
|
||||
/// Rename field description on table assignment to intro
|
||||
$table = new xmldb_table('assignment');
|
||||
$field = new xmldb_field('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name');
|
||||
|
||||
/// Launch rename field description
|
||||
$dbman->rename_field($table, $field, 'intro');
|
||||
|
||||
/// assignment savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042000, 'assignment');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042001) {
|
||||
|
||||
/// Rename field format on table assignment to introformat
|
||||
$table = new xmldb_table('assignment');
|
||||
$field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Launch rename field format
|
||||
$dbman->rename_field($table, $field, 'introformat');
|
||||
|
||||
/// assignment savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042001, 'assignment');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -25,83 +25,6 @@ function xmldb_chat_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2010050100) {
|
||||
|
||||
/// Changing precision of field ip on table chat_users to (45)
|
||||
$table = new xmldb_table('chat_users');
|
||||
$field = new xmldb_field('ip', XMLDB_TYPE_CHAR, '45', null, XMLDB_NOTNULL, null, null, 'version');
|
||||
|
||||
/// Launch change of precision for field ip
|
||||
$dbman->change_field_precision($table, $field);
|
||||
|
||||
/// chat savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010050100, 'chat');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010050101) {
|
||||
|
||||
/// Define field introformat to be added to chat
|
||||
$table = new xmldb_table('chat');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Launch add field introformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('chat', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
|
||||
foreach ($rs as $ch) {
|
||||
$ch->intro = text_to_html($ch->intro, false, false, true);
|
||||
$ch->introformat = FORMAT_HTML;
|
||||
$DB->update_record('chat', $ch);
|
||||
upgrade_set_timeout();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/// chat savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010050101, 'chat');
|
||||
}
|
||||
|
||||
/// Creating chat_messages_current to hold latest chat messages
|
||||
if ($oldversion < 2010050102) {
|
||||
|
||||
/// Define table chat_messages_current to be created
|
||||
$table = new xmldb_table('chat_messages_current');
|
||||
|
||||
/// Adding fields to table chat_messages_current
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('chatid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('system', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('message', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('timestamp', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
/// Adding keys to table chat_messages_current
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('chatid', XMLDB_KEY_FOREIGN, array('chatid'), 'chat', array('id'));
|
||||
|
||||
/// Adding indexes to table chat_messages_current
|
||||
$table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
|
||||
$table->add_index('groupid', XMLDB_INDEX_NOTUNIQUE, array('groupid'));
|
||||
$table->add_index('timestamp-chatid', XMLDB_INDEX_NOTUNIQUE, array('timestamp', 'chatid'));
|
||||
|
||||
/// create table for chat_messages_current
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
/// chat savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010050102, 'chat');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -25,51 +25,6 @@ function xmldb_choice_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2009042000) {
|
||||
|
||||
/// Rename field text on table choice to text
|
||||
$table = new xmldb_table('choice');
|
||||
$field = new xmldb_field('text', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name');
|
||||
|
||||
/// Launch rename field text
|
||||
$dbman->rename_field($table, $field, 'intro');
|
||||
|
||||
/// choice savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042000, 'choice');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042001) {
|
||||
|
||||
/// Rename field format on table choice to format
|
||||
$table = new xmldb_table('choice');
|
||||
$field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Launch rename field format
|
||||
$dbman->rename_field($table, $field, 'introformat');
|
||||
|
||||
/// choice savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042001, 'choice');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010101300) {
|
||||
|
||||
// Define field completionsubmit to be added to choice
|
||||
$table = new xmldb_table('choice');
|
||||
$field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'timemodified');
|
||||
|
||||
// Conditionally launch add field completionsubmit
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// choice savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010101300, 'choice');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -25,321 +25,6 @@ function xmldb_data_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2007101512) {
|
||||
/// Launch add field asearchtemplate again if does not exists yet - reported on several sites
|
||||
|
||||
$table = new xmldb_table('data');
|
||||
$field = new xmldb_field('asearchtemplate', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'jstemplate');
|
||||
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2007101512, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2007101513) {
|
||||
// Upgrade all the data->notification currently being
|
||||
// NULL to 0
|
||||
$sql = "UPDATE {data} SET notification=0 WHERE notification IS NULL";
|
||||
$DB->execute($sql);
|
||||
|
||||
$table = new xmldb_table('data');
|
||||
$field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'editany');
|
||||
// First step, Set NOT NULL
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
// Second step, Set default to 0
|
||||
$dbman->change_field_default($table, $field);
|
||||
upgrade_mod_savepoint(true, 2007101513, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008081400) {
|
||||
$pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/';
|
||||
$replacement = '##delete##$1##approve##$1##export##';
|
||||
$rs = $DB->get_recordset('data');
|
||||
foreach ($rs as $data) {
|
||||
$data->listtemplate = preg_replace($pattern, $replacement, $data->listtemplate);
|
||||
$data->singletemplate = preg_replace($pattern, $replacement, $data->singletemplate);
|
||||
$DB->update_record('data', $data);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008081400, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008091400) {
|
||||
|
||||
/////////////////////////////////////
|
||||
/// new file storage upgrade code ///
|
||||
/////////////////////////////////////
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$empty = $DB->sql_empty(); // silly oracle empty string handling workaround
|
||||
|
||||
$sqlfrom = "FROM {data_content} c
|
||||
JOIN {data_fields} f ON f.id = c.fieldid
|
||||
JOIN {data_records} r ON r.id = c.recordid
|
||||
JOIN {data} d ON d.id = r.dataid
|
||||
JOIN {modules} m ON m.name = 'data'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = d.id)
|
||||
WHERE ".$DB->sql_compare_text('c.content', 2)." <> '$empty' AND c.content IS NOT NULL
|
||||
AND (f.type = 'file' OR f.type = 'picture')";
|
||||
|
||||
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
|
||||
|
||||
$rs = $DB->get_recordset_sql("SELECT c.id, f.type, r.dataid, c.recordid, f.id AS fieldid, r.userid, c.content, c.content1, d.course, r.userid, cm.id AS cmid $sqlfrom ORDER BY d.course, d.id");
|
||||
|
||||
if ($rs->valid()) {
|
||||
$pbar = new progress_bar('migratedatafiles', 500, true);
|
||||
|
||||
$i = 0;
|
||||
foreach ($rs as $content) {
|
||||
$i++;
|
||||
upgrade_set_timeout(60); // set up timeout, may also abort execution
|
||||
$pbar->update($i, $count, "Migrating data entries - $i/$count.");
|
||||
|
||||
$filepath = "$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid/$content->content";
|
||||
$context = get_context_instance(CONTEXT_MODULE, $content->cmid);
|
||||
|
||||
if (!file_exists($filepath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filearea = 'content';
|
||||
$oldfilename = $content->content;
|
||||
$filename = clean_param($oldfilename, PARAM_FILE);
|
||||
if ($filename === '') {
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, 'mod_data', $filearea, $content->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_data', 'filearea'=>$filearea, 'itemid'=>$content->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$content->userid);
|
||||
if ($fs->create_file_from_pathname($file_record, $filepath)) {
|
||||
unlink($filepath);
|
||||
if ($oldfilename !== $filename) {
|
||||
// update filename if needed
|
||||
$DB->set_field('data_content', 'content', $filename, array('id'=>$content->id));
|
||||
}
|
||||
if ($content->type == 'picture') {
|
||||
// migrate thumb
|
||||
$filepath = "$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid/thumb/$content->content";
|
||||
if (file_exists($filepath)) {
|
||||
if (!$fs->file_exists($context->id, 'mod_data', $filearea, $content->id, '/', 'thumb_'.$filename)) {
|
||||
$file_record['filename'] = 'thumb_'.$file_record['filename'];
|
||||
$fs->create_file_from_pathname($file_record, $filepath);
|
||||
}
|
||||
unlink($filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove dirs if empty
|
||||
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid/thumb");
|
||||
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid/$content->recordid");
|
||||
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid/$content->fieldid");
|
||||
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data/$content->dataid");
|
||||
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata/data");
|
||||
@rmdir("$CFG->dataroot/$content->course/$CFG->moddata");
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008091400, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008112700) {
|
||||
if (!get_config('data', 'requiredentriesfixflag')) {
|
||||
$databases = $DB->get_records_sql("SELECT d.*, c.fullname
|
||||
FROM {data} d, {course} c
|
||||
WHERE d.course = c.id
|
||||
AND (d.requiredentries > 0 OR d.requiredentriestoview > 0)
|
||||
ORDER BY c.fullname, d.name");
|
||||
if (!empty($databases)) {
|
||||
$a = new stdClass();
|
||||
$a->text = '';
|
||||
foreach($databases as $database) {
|
||||
$a->text .= $database->fullname." - " .$database->name. " (course id: ".$database->course." - database id: ".$database->id.")<br/>";
|
||||
}
|
||||
//TODO: MDL-17427 send this info to "upgrade log" which will be implemented in 2.0
|
||||
echo $OUTPUT->notification(get_string('requiredentrieschanged', 'admin', $a));
|
||||
}
|
||||
}
|
||||
unset_config('requiredentriesfixflag', 'data'); // remove old flag
|
||||
upgrade_mod_savepoint(true, 2008112700, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042000) {
|
||||
|
||||
/// Define field introformat to be added to data
|
||||
$table = new xmldb_table('data');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Launch add field introformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('data', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
|
||||
foreach ($rs as $d) {
|
||||
$d->intro = text_to_html($d->intro, false, false, true);
|
||||
$d->introformat = FORMAT_HTML;
|
||||
$DB->update_record('data', $d);
|
||||
upgrade_set_timeout();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/// data savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042000, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009111701) {
|
||||
upgrade_set_timeout(60*20);
|
||||
|
||||
/// Define table data_comments to be dropped
|
||||
$table = new xmldb_table('data_comments');
|
||||
|
||||
/// Conditionally launch drop table for data_comments
|
||||
if ($dbman->table_exists($table)) {
|
||||
$sql = "SELECT d.id AS dataid,
|
||||
d.course AS courseid,
|
||||
c.userid,
|
||||
r.id AS itemid,
|
||||
c.id AS commentid,
|
||||
c.content AS commentcontent,
|
||||
c.format AS format,
|
||||
c.created AS timecreated
|
||||
FROM {data_comments} c, {data_records} r, {data} d
|
||||
WHERE c.recordid=r.id AND r.dataid=d.id
|
||||
ORDER BY dataid, courseid";
|
||||
/// move data comments to comments table
|
||||
$lastdataid = null;
|
||||
$lastcourseid = null;
|
||||
$modcontext = null;
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach($rs as $res) {
|
||||
if ($res->dataid != $lastdataid || $res->courseid != $lastcourseid) {
|
||||
$cm = get_coursemodule_from_instance('data', $res->dataid, $res->courseid);
|
||||
if ($cm) {
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
}
|
||||
$lastdataid = $res->dataid;
|
||||
$lastcourseid = $res->courseid;
|
||||
}
|
||||
$cmt = new stdClass();
|
||||
$cmt->contextid = $modcontext->id;
|
||||
$cmt->commentarea = 'database_entry';
|
||||
$cmt->itemid = $res->itemid;
|
||||
$cmt->content = $res->commentcontent;
|
||||
$cmt->format = $res->format;
|
||||
$cmt->userid = $res->userid;
|
||||
$cmt->timecreated = $res->timecreated;
|
||||
// comments class will throw an exception if error occurs
|
||||
$cmt_id = $DB->insert_record('comments', $cmt);
|
||||
if (!empty($cmt_id)) {
|
||||
$DB->delete_records('data_comments', array('id'=>$res->commentid));
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
// the default exception handler will stop the script if error occurs before
|
||||
$dbman->drop_table($table);
|
||||
}
|
||||
|
||||
/// data savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009111701, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010031602) {
|
||||
//add assesstimestart and assesstimefinish columns to data
|
||||
$table = new xmldb_table('data');
|
||||
|
||||
$field = new xmldb_field('assesstimestart');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'assessed');
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('assesstimefinish');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'assesstimestart');
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2010031602, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010042800) {
|
||||
//migrate data ratings to the central rating table
|
||||
$table = new xmldb_table('data_ratings');
|
||||
if ($dbman->table_exists($table)) {
|
||||
//data ratings didnt store time created and modified so Im using the times from the record the rating was attached to
|
||||
$sql = "INSERT INTO {rating} (contextid, scaleid, itemid, rating, userid, timecreated, timemodified)
|
||||
|
||||
SELECT cxt.id, d.scale, r.recordid AS itemid, r.rating, r.userid, re.timecreated AS timecreated, re.timemodified AS timemodified
|
||||
FROM {data_ratings} r
|
||||
JOIN {data_records} re ON r.recordid=re.id
|
||||
JOIN {data} d ON d.id=re.dataid
|
||||
JOIN {course_modules} cm ON cm.instance=d.id
|
||||
JOIN {context} cxt ON cxt.instanceid=cm.id
|
||||
JOIN {modules} m ON m.id=cm.module
|
||||
WHERE m.name = :modname AND cxt.contextlevel = :contextlevel";
|
||||
$params['modname'] = 'data';
|
||||
$params['contextlevel'] = CONTEXT_MODULE;
|
||||
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
//now drop data_ratings
|
||||
$dbman->drop_table($table);
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2010042800, 'data');
|
||||
}
|
||||
|
||||
//rerun the upgrade see MDL-24470
|
||||
if ($oldversion < 2010100101) {
|
||||
// Upgrade all the data->notification currently being
|
||||
// NULL to 0
|
||||
$sql = "UPDATE {data} SET notification=0 WHERE notification IS NULL";
|
||||
$DB->execute($sql);
|
||||
|
||||
$table = new xmldb_table('data');
|
||||
$field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'editany');
|
||||
// First step, Set NOT NULL
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
// Second step, Set default to 0
|
||||
$dbman->change_field_default($table, $field);
|
||||
upgrade_mod_savepoint(true, 2010100101, 'data');
|
||||
}
|
||||
|
||||
if ($oldversion < 2011052300) {
|
||||
// rating.component and rating.ratingarea have now been added as mandatory fields.
|
||||
// Presently you can only rate data entries so component = 'mod_data' and ratingarea = 'entry'
|
||||
// for all ratings with a data context.
|
||||
// We want to update all ratings that belong to a data context and don't already have a
|
||||
// component set.
|
||||
// This could take a while reset upgrade timeout to 5 min
|
||||
upgrade_set_timeout(60 * 20);
|
||||
$sql = "UPDATE {rating}
|
||||
SET component = 'mod_data', ratingarea = 'entry'
|
||||
WHERE contextid IN (
|
||||
SELECT ctx.id
|
||||
FROM {context} ctx
|
||||
JOIN {course_modules} cm ON cm.id = ctx.instanceid
|
||||
JOIN {modules} m ON m.id = cm.module
|
||||
WHERE ctx.contextlevel = 70 AND
|
||||
m.name = 'data'
|
||||
) AND component = 'unknown'";
|
||||
$DB->execute($sql);
|
||||
|
||||
upgrade_mod_savepoint(true, 2011052300, 'data');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -39,330 +39,6 @@ function xmldb_feedback_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2007012310) {
|
||||
|
||||
//create a new table feedback_completedtmp and the field-definition
|
||||
$table = new xmldb_table('feedback_completedtmp');
|
||||
|
||||
$field = new xmldb_field('id');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, true, null, null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('feedback');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, false, '0', null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('userid');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, false, '0', null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('guestid');
|
||||
$field->set_attributes(XMLDB_TYPE_CHAR, '255', null, null, false, '', null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('timemodified');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, false, '0', null);
|
||||
$table->addField($field);
|
||||
|
||||
$key = new xmldb_key('PRIMARY');
|
||||
$key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->addKey($key);
|
||||
|
||||
$key = new xmldb_key('feedback');
|
||||
$key->set_attributes(XMLDB_KEY_FOREIGN, array('feedback'), 'feedback', 'id');
|
||||
$table->addKey($key);
|
||||
|
||||
$dbman->create_table($table);
|
||||
////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////
|
||||
//create a new table feedback_valuetmp and the field-definition
|
||||
$table = new xmldb_table('feedback_valuetmp');
|
||||
|
||||
$field = new xmldb_field('id');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, true, null, null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('course_id');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, false, '0', null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('item');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, false, '0', null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('completed');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, false, '0', null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('tmp_completed');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, false, '0', null);
|
||||
$table->addField($field);
|
||||
|
||||
$field = new xmldb_field('value');
|
||||
$field->set_attributes(XMLDB_TYPE_TEXT, null, null, null, false, '', null);
|
||||
$table->addField($field);
|
||||
|
||||
$key = new xmldb_key('PRIMARY');
|
||||
$key->set_attributes(XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->addKey($key);
|
||||
|
||||
$key = new xmldb_key('feedback');
|
||||
$key->set_attributes(XMLDB_KEY_FOREIGN, array('item'), 'feedback_item', 'id');
|
||||
$table->addKey($key);
|
||||
|
||||
$dbman->create_table($table);
|
||||
////////////////////////////////////////////////////////////
|
||||
upgrade_mod_savepoint(true, 2007012310, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2007050504) {
|
||||
|
||||
/// Define field random_response to be added to feedback_completed
|
||||
$table = new xmldb_table('feedback_completed');
|
||||
$field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10',
|
||||
XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
|
||||
/// Launch add field1
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// Define field anonymous_response to be added to feedback_completed
|
||||
$table = new xmldb_table('feedback_completed');
|
||||
$field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1',
|
||||
XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
|
||||
/// Launch add field2
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// Define field random_response to be added to feedback_completed
|
||||
$table = new xmldb_table('feedback_completedtmp');
|
||||
$field = new xmldb_field('random_response', XMLDB_TYPE_INTEGER, '10',
|
||||
XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '0', null);
|
||||
/// Launch add field1
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// Define field anonymous_response to be added to feedback_completed
|
||||
$table = new xmldb_table('feedback_completedtmp');
|
||||
$field = new xmldb_field('anonymous_response', XMLDB_TYPE_INTEGER, '1',
|
||||
XMLDB_UNSIGNED, XMLDB_NOTNULL, false, '1', null);
|
||||
/// Launch add field2
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
upgrade_mod_savepoint(true, 2007050504, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2007102600) {
|
||||
// public is a reserved word on Oracle
|
||||
|
||||
$table = new xmldb_table('feedback_template');
|
||||
$field = new xmldb_field('ispublic', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED,
|
||||
XMLDB_NOTNULL, false, '1', null);
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2007102600, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008042400) { //New version in version.php
|
||||
if ($all_nonanonymous_feedbacks = $DB->get_records('feedback', array('anonymous'=>2))) {
|
||||
$update_sql = 'UPDATE {feedback_completed}
|
||||
SET anonymous_response = 2
|
||||
WHERE feedback = ';
|
||||
foreach ($all_nonanonymous_feedbacks as $fb) {
|
||||
$DB->execute($update_sql.$fb->id);
|
||||
}
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2008042400, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008042401) { //New version in version.php
|
||||
$concat_radio = $DB->sql_concat("'r>>>>>'", 'presentation');
|
||||
$concat_check = $DB->sql_concat("'c>>>>>'", 'presentation');
|
||||
$concat_dropdown = $DB->sql_concat("'d>>>>>'", 'presentation');
|
||||
|
||||
$update_sql1 = "UPDATE {feedback_item}
|
||||
SET presentation = ".$concat_radio."
|
||||
WHERE typ IN('radio','radiorated')";
|
||||
|
||||
$update_sql2 = "UPDATE {feedback_item}
|
||||
SET presentation = ".$concat_dropdown."
|
||||
WHERE typ IN('dropdown','dropdownrated')";
|
||||
|
||||
$update_sql3 = "UPDATE {feedback_item}
|
||||
SET presentation = ".$concat_check."
|
||||
WHERE typ = 'check'";
|
||||
|
||||
$DB->execute($update_sql1);
|
||||
$DB->execute($update_sql2);
|
||||
$DB->execute($update_sql3);
|
||||
|
||||
$update_sql1 = "UPDATE {feedback_item}
|
||||
SET typ = 'multichoice'
|
||||
WHERE typ IN('radio','check','dropdown')";
|
||||
|
||||
$update_sql2 = "UPDATE {feedback_item}
|
||||
SET typ = 'multichoicerated'
|
||||
WHERE typ IN('radiorated','dropdownrated')";
|
||||
|
||||
$DB->execute($update_sql1);
|
||||
$DB->execute($update_sql2);
|
||||
|
||||
upgrade_mod_savepoint(true, 2008042401, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008042900) {
|
||||
/// Define field autonumbering to be added to feedback
|
||||
$table = new xmldb_table('feedback');
|
||||
$field = new xmldb_field('autonumbering', XMLDB_TYPE_INTEGER, '1',
|
||||
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'multiple_submit');
|
||||
/// Launch add field2
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
upgrade_mod_savepoint(true, 2008042900, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008050104) {
|
||||
/// Define field site_after_submit to be added to feedback
|
||||
$table = new xmldb_table('feedback');
|
||||
$field = new xmldb_field('site_after_submit', XMLDB_TYPE_CHAR, '255',
|
||||
null, null, false, '', 'autonumbering');
|
||||
/// Launch add field2
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
upgrade_mod_savepoint(true, 2008050104, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008050105) {
|
||||
//field count is not more needed
|
||||
$table = new xmldb_table('feedback_tracking');
|
||||
$field = new xmldb_field('count');
|
||||
$dbman->drop_field($table, $field);
|
||||
|
||||
upgrade_mod_savepoint(true, 2008050105, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008073002) {
|
||||
$update_sql = "UPDATE {feedback_item}
|
||||
SET presentation = '-|-'
|
||||
WHERE " . $DB->sql_compare_text('presentation') . " = '0|0' AND
|
||||
typ = 'numeric'";
|
||||
|
||||
$DB->execute($update_sql);
|
||||
|
||||
upgrade_mod_savepoint(true, 2008073002, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009031301) {
|
||||
/// Define field label to be added to feedback_item
|
||||
$table = new xmldb_table('feedback_item');
|
||||
$field = new xmldb_field('label', XMLDB_TYPE_CHAR, '255', null, null, false, '', 'name');
|
||||
/// Launch add field2
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
upgrade_mod_savepoint(true, 2009031301, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042000) {
|
||||
|
||||
/// Rename field summary on table feedback to intro
|
||||
$table = new xmldb_table('feedback');
|
||||
$field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null,
|
||||
XMLDB_NOTNULL, null, null, 'name');
|
||||
|
||||
/// Launch rename field summary
|
||||
$dbman->rename_field($table, $field, 'intro');
|
||||
|
||||
/// feedback savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042000, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042001) {
|
||||
|
||||
/// Define field introformat to be added to feedback
|
||||
$table = new xmldb_table('feedback');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4',
|
||||
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Launch add field introformat
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// feedback savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042001, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009112000) {
|
||||
/// Define field page_after_submitformat to be added to feedback
|
||||
$table = new xmldb_table('feedback');
|
||||
$field = new xmldb_field('page_after_submitformat', XMLDB_TYPE_INTEGER, '2',
|
||||
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'page_after_submit');
|
||||
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
// Launch add field page_after_submitformat
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// feedback savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009112000, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010051101) {
|
||||
/// Define field options to be added to feedback_item
|
||||
$table = new xmldb_table('feedback_item');
|
||||
$field = new xmldb_field('options', XMLDB_TYPE_CHAR, '255',
|
||||
null, null, false, '', 'required');
|
||||
/// Launch add field
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
upgrade_mod_savepoint(true, 2010051101, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010051600) {
|
||||
/// Define field options to be added to feedback_item
|
||||
$table = new xmldb_table('feedback_item');
|
||||
$field = new xmldb_field('dependitem', XMLDB_TYPE_INTEGER, '10',
|
||||
XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'required');
|
||||
/// Launch add field
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
upgrade_mod_savepoint(true, 2010051600, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010051601) {
|
||||
/// Define field options to be added to feedback_item
|
||||
$table = new xmldb_table('feedback_item');
|
||||
$field = new xmldb_field('dependvalue', XMLDB_TYPE_CHAR, '255',
|
||||
null, null, false, '', 'dependitem');
|
||||
/// Launch add field
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
upgrade_mod_savepoint(true, 2010051601, 'feedback');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010102300) {
|
||||
|
||||
// Define field completionsubmit to be added to feedback
|
||||
$table = new xmldb_table('feedback');
|
||||
$field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1',
|
||||
null, XMLDB_NOTNULL, null, '0', 'timemodified');
|
||||
|
||||
// Conditionally launch add field completionsubmit
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// feedback savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010102300, 'feedback');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -34,14 +34,4 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_folder_install() {
|
||||
global $CFG;
|
||||
|
||||
// Upgrade from old resource module type if needed
|
||||
require_once("$CFG->dirroot/mod/folder/db/upgradelib.php");
|
||||
folder_20_migrate();
|
||||
}
|
||||
|
||||
function xmldb_folder_install_recovery() {
|
||||
global $CFG;
|
||||
|
||||
require_once("$CFG->dirroot/mod/folder/db/upgradelib.php");
|
||||
folder_20_migrate();
|
||||
}
|
||||
@@ -51,8 +51,6 @@ function xmldb_folder_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Folder module upgrade related helper functions
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage folder
|
||||
* @copyright 2009 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Migrate folder module data from 1.9 resource_old table to new older table
|
||||
* @return void
|
||||
*/
|
||||
function folder_20_migrate() {
|
||||
global $CFG, $DB;
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
require_once("$CFG->dirroot/course/lib.php");
|
||||
|
||||
if (!file_exists("$CFG->dirroot/mod/resource/db/upgradelib.php")) {
|
||||
// bad luck, somebody deleted resource module
|
||||
return;
|
||||
}
|
||||
|
||||
require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
|
||||
|
||||
// create resource_old table and copy resource table there if needed
|
||||
if (!resource_20_prepare_migration()) {
|
||||
// no modules or fresh install
|
||||
return;
|
||||
}
|
||||
|
||||
$candidates = $DB->get_recordset('resource_old', array('type'=>'directory', 'migrated'=>0));
|
||||
|
||||
if (!$candidates->valid()) {
|
||||
$candidates->close(); // Not going to iterate (but exit), close rs
|
||||
return;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
upgrade_set_timeout();
|
||||
|
||||
$directory = '/'.trim($candidate->reference, '/').'/';
|
||||
$directory = str_replace('//', '/', $directory);
|
||||
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$intro = text_to_html($candidate->intro, false, false, true);
|
||||
$introformat = FORMAT_HTML;
|
||||
} else {
|
||||
$intro = $candidate->intro;
|
||||
$introformat = FORMAT_MOODLE;
|
||||
}
|
||||
|
||||
$folder = new stdClass();
|
||||
$folder->course = $candidate->course;
|
||||
$folder->name = $candidate->name;
|
||||
$folder->intro = $intro;
|
||||
$folder->introformat = $introformat;
|
||||
$folder->revision = 1;
|
||||
$folder->timemodified = time();
|
||||
|
||||
if (!$folder = resource_migrate_to_module('folder', $candidate, $folder)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// copy files in given directory, skip moddata and backups!
|
||||
$context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $candidate->course);
|
||||
$files = $fs->get_directory_files($coursecontext->id, 'course', 'legacy', 0, $directory, true, true);
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_folder', 'filearea'=>'content', 'itemid'=>0);
|
||||
foreach ($files as $file) {
|
||||
$path = $file->get_filepath();
|
||||
if (stripos($path, '/backupdata/') === 0 or stripos($path, '/moddata/') === 0) {
|
||||
// do not publish protected data!
|
||||
continue;
|
||||
}
|
||||
$relpath = substr($path, strlen($directory) - 1); // keep only subfolder paths
|
||||
$file_record['filepath'] = $relpath;
|
||||
$fs->create_file_from_storedfile($file_record, $file);
|
||||
}
|
||||
}
|
||||
|
||||
$candidates->close();
|
||||
|
||||
// clear all course modinfo caches
|
||||
rebuild_course_cache(0, true);
|
||||
}
|
||||
@@ -46,300 +46,6 @@ function xmldb_forum_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2007101511) {
|
||||
//MDL-13866 - send forum ratins to gradebook again
|
||||
require_once($CFG->dirroot.'/mod/forum/lib.php');
|
||||
forum_upgrade_grades();
|
||||
upgrade_mod_savepoint(true, 2007101511, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008072800) {
|
||||
/// Define field completiondiscussions to be added to forum
|
||||
$table = new xmldb_table('forum');
|
||||
$field = new xmldb_field('completiondiscussions');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'blockperiod');
|
||||
|
||||
/// Launch add field completiondiscussions
|
||||
if(!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('completionreplies');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiondiscussions');
|
||||
|
||||
/// Launch add field completionreplies
|
||||
if(!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
/// Define field completionposts to be added to forum
|
||||
$field = new xmldb_field('completionposts');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionreplies');
|
||||
|
||||
/// Launch add field completionposts
|
||||
if(!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2008072800, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008081900) {
|
||||
|
||||
/////////////////////////////////////
|
||||
/// new file storage upgrade code ///
|
||||
/////////////////////////////////////
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$empty = $DB->sql_empty(); // silly oracle empty string handling workaround
|
||||
|
||||
$sqlfrom = "FROM {forum_posts} p
|
||||
JOIN {forum_discussions} d ON d.id = p.discussion
|
||||
JOIN {forum} f ON f.id = d.forum
|
||||
JOIN {modules} m ON m.name = 'forum'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = f.id)
|
||||
WHERE p.attachment <> '$empty' AND p.attachment <> '1'";
|
||||
|
||||
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
|
||||
|
||||
$rs = $DB->get_recordset_sql("SELECT p.id, p.attachment, p.userid, d.forum, f.course, cm.id AS cmid $sqlfrom ORDER BY f.course, f.id, d.id");
|
||||
if ($rs->valid()) {
|
||||
|
||||
$pbar = new progress_bar('migrateforumfiles', 500, true);
|
||||
|
||||
$i = 0;
|
||||
foreach ($rs as $post) {
|
||||
$i++;
|
||||
upgrade_set_timeout(60); // set up timeout, may also abort execution
|
||||
$pbar->update($i, $count, "Migrating forum posts - $i/$count.");
|
||||
|
||||
$filepath = "$CFG->dataroot/$post->course/$CFG->moddata/forum/$post->forum/$post->id/$post->attachment";
|
||||
if (!is_readable($filepath)) {
|
||||
//file missing??
|
||||
echo $OUTPUT->notification("File not readable, skipping: ".$filepath);
|
||||
$post->attachment = '';
|
||||
$DB->update_record('forum_posts', $post);
|
||||
continue;
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_MODULE, $post->cmid);
|
||||
|
||||
$filearea = 'attachment';
|
||||
$filename = clean_param($post->attachment, PARAM_FILE);
|
||||
if ($filename === '') {
|
||||
echo $OUTPUT->notification("Unsupported post filename, skipping: ".$filepath);
|
||||
$post->attachment = '';
|
||||
$DB->update_record('forum_posts', $post);
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, 'mod_forum', $filearea, $post->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_forum', 'filearea'=>$filearea, 'itemid'=>$post->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$post->userid);
|
||||
if ($fs->create_file_from_pathname($file_record, $filepath)) {
|
||||
$post->attachment = '1';
|
||||
$DB->update_record('forum_posts', $post);
|
||||
unlink($filepath);
|
||||
}
|
||||
}
|
||||
|
||||
// remove dirs if empty
|
||||
@rmdir("$CFG->dataroot/$post->course/$CFG->moddata/forum/$post->forum/$post->id");
|
||||
@rmdir("$CFG->dataroot/$post->course/$CFG->moddata/forum/$post->forum");
|
||||
@rmdir("$CFG->dataroot/$post->course/$CFG->moddata/forum");
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008081900, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008090800) {
|
||||
|
||||
/// Define field maxattachments to be added to forum
|
||||
$table = new xmldb_table('forum');
|
||||
$field = new xmldb_field('maxattachments', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', 'maxbytes');
|
||||
|
||||
/// Conditionally launch add field maxattachments
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
/// forum savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090800, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042000) {
|
||||
|
||||
/// Rename field format on table forum_posts to messageformat
|
||||
$table = new xmldb_table('forum_posts');
|
||||
$field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'message');
|
||||
|
||||
/// Launch rename field format
|
||||
$dbman->rename_field($table, $field, 'messageformat');
|
||||
|
||||
/// forum savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042000, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042001) {
|
||||
|
||||
/// Define field messagetrust to be added to forum_posts
|
||||
$table = new xmldb_table('forum_posts');
|
||||
$field = new xmldb_field('messagetrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'messageformat');
|
||||
|
||||
/// Launch add field messagetrust
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// forum savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042001, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042002) {
|
||||
$trustmark = '#####TRUSTTEXT#####';
|
||||
$rs = $DB->get_recordset_sql("SELECT * FROM {forum_posts} WHERE message LIKE ?", array($trustmark.'%'));
|
||||
foreach ($rs as $post) {
|
||||
if (strpos($post->message, $trustmark) !== 0) {
|
||||
// probably lowercase in some DBs?
|
||||
continue;
|
||||
}
|
||||
$post->message = str_replace($trustmark, '', $post->message);
|
||||
$post->messagetrust = 1;
|
||||
$DB->update_record('forum_posts', $post);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
/// forum savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042002, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042003) {
|
||||
|
||||
/// Define field introformat to be added to forum
|
||||
$table = new xmldb_table('forum');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Launch add field introformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('forum', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
|
||||
foreach ($rs as $f) {
|
||||
$f->intro = text_to_html($f->intro, false, false, true);
|
||||
$f->introformat = FORMAT_HTML;
|
||||
$DB->update_record('forum', $f);
|
||||
upgrade_set_timeout();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/// forum savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042003, 'forum');
|
||||
}
|
||||
|
||||
/// Dropping all enums/check contraints from core. MDL-18577
|
||||
if ($oldversion < 2009042700) {
|
||||
|
||||
/// Changing list of values (enum) of field type on table forum to none
|
||||
$table = new xmldb_table('forum');
|
||||
$field = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'general', 'course');
|
||||
|
||||
/// Launch change of list of values for field type
|
||||
$dbman->drop_enum_from_field($table, $field);
|
||||
|
||||
/// forum savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042700, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009050400) {
|
||||
|
||||
/// Clean existing wrong rates. MDL-18227
|
||||
$DB->delete_records('forum_ratings', array('post' => 0));
|
||||
|
||||
/// forum savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009050400, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010042800) {
|
||||
//migrate forumratings to the central rating table
|
||||
$table = new xmldb_table('forum_ratings');
|
||||
if ($dbman->table_exists($table)) {
|
||||
//forum ratings only have a single time column so use it for both time created and modified
|
||||
$sql = "INSERT INTO {rating} (contextid, scaleid, itemid, rating, userid, timecreated, timemodified)
|
||||
|
||||
SELECT cxt.id, f.scale, r.post AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified
|
||||
FROM {forum_ratings} r
|
||||
JOIN {forum_posts} p ON p.id=r.post
|
||||
JOIN {forum_discussions} d ON d.id=p.discussion
|
||||
JOIN {forum} f ON f.id=d.forum
|
||||
JOIN {course_modules} cm ON cm.instance=f.id
|
||||
JOIN {context} cxt ON cxt.instanceid=cm.id
|
||||
JOIN {modules} m ON m.id=cm.module
|
||||
WHERE m.name = :modname AND cxt.contextlevel = :contextlevel";
|
||||
$params['modname'] = 'forum';
|
||||
$params['contextlevel'] = CONTEXT_MODULE;
|
||||
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
//now drop forum_ratings
|
||||
$dbman->drop_table($table);
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2010042800, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010070800) {
|
||||
|
||||
// Remove the forum digests message provider MDL-23145
|
||||
$DB->delete_records('message_providers', array('name' => 'digests','component'=>'mod_forum'));
|
||||
|
||||
// forum savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010070800, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010091900) {
|
||||
// rename files from borked upgrade in 2.0dev
|
||||
$fs = get_file_storage();
|
||||
$rs = $DB->get_recordset('files', array('component'=>'mod_form'));
|
||||
foreach ($rs as $oldrecord) {
|
||||
$file = $fs->get_file_instance($oldrecord);
|
||||
$newrecord = array('component'=>'mod_forum');
|
||||
if (!$fs->file_exists($oldrecord->contextid, 'mod_forum', $oldrecord->filearea, $oldrecord->itemid, $oldrecord->filepath, $oldrecord->filename)) {
|
||||
$fs->create_file_from_storedfile($newrecord, $file);
|
||||
}
|
||||
$file->delete();
|
||||
}
|
||||
$rs->close();
|
||||
upgrade_mod_savepoint(true, 2010091900, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2011052300) {
|
||||
// rating.component and rating.ratingarea have now been added as mandatory fields.
|
||||
// Presently you can only rate forum posts so component = 'mod_forum' and ratingarea = 'post'
|
||||
// for all ratings with a forum context.
|
||||
// We want to update all ratings that belong to a forum context and don't already have a
|
||||
// component set.
|
||||
// This could take a while reset upgrade timeout to 5 min
|
||||
upgrade_set_timeout(60 * 20);
|
||||
$sql = "UPDATE {rating}
|
||||
SET component = 'mod_forum', ratingarea = 'post'
|
||||
WHERE contextid IN (
|
||||
SELECT ctx.id
|
||||
FROM {context} ctx
|
||||
JOIN {course_modules} cm ON cm.id = ctx.instanceid
|
||||
JOIN {modules} m ON m.id = cm.module
|
||||
WHERE ctx.contextlevel = 70 AND
|
||||
m.name = 'forum'
|
||||
) AND component = 'unknown'";
|
||||
$DB->execute($sql);
|
||||
|
||||
upgrade_mod_savepoint(true, 2011052300, 'forum');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -25,332 +25,6 @@ function xmldb_glossary_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2008081900) {
|
||||
|
||||
/////////////////////////////////////
|
||||
/// new file storage upgrade code ///
|
||||
/////////////////////////////////////
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$empty = $DB->sql_empty(); // silly oracle empty string handling workaround
|
||||
|
||||
$sqlfrom = "FROM {glossary_entries} ge
|
||||
JOIN {glossary} g ON g.id = ge.glossaryid
|
||||
JOIN {modules} m ON m.name = 'glossary'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = g.id)
|
||||
WHERE ge.attachment <> '$empty' AND ge.attachment <> '1'";
|
||||
|
||||
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
|
||||
|
||||
$rs = $DB->get_recordset_sql("SELECT ge.id, ge.userid, ge.attachment, ge.glossaryid, ge.sourceglossaryid, g.course, cm.id AS cmid $sqlfrom ORDER BY g.course, g.id");
|
||||
if ($rs->valid()) {
|
||||
|
||||
$pbar = new progress_bar('migrateglossaryfiles', 500, true);
|
||||
|
||||
$i = 0;
|
||||
foreach ($rs as $entry) {
|
||||
$i++;
|
||||
upgrade_set_timeout(60); // set up timeout, may also abort execution
|
||||
$pbar->update($i, $count, "Migrating glossary entries - $i/$count.");
|
||||
|
||||
$filepath = "$CFG->dataroot/$entry->course/$CFG->moddata/glossary/$entry->glossaryid/$entry->id/$entry->attachment";
|
||||
if ($entry->sourceglossaryid and !is_readable($filepath)) {
|
||||
//eh - try the second possible location
|
||||
$filepath = "$CFG->dataroot/$entry->course/$CFG->moddata/glossary/$entry->sourceglossaryid/$entry->id/$entry->attachment";
|
||||
|
||||
}
|
||||
if (!is_readable($filepath)) {
|
||||
//file missing??
|
||||
echo $OUTPUT->notification("File not readable, skipping: $filepath");
|
||||
$entry->attachment = '';
|
||||
$DB->update_record('glossary_entries', $entry);
|
||||
continue;
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_MODULE, $entry->cmid);
|
||||
|
||||
$filearea = 'attachment';
|
||||
$filename = clean_param($entry->attachment, PARAM_FILE);
|
||||
if ($filename === '') {
|
||||
echo $OUTPUT->notification("Unsupported entry filename, skipping: ".$filepath);
|
||||
$entry->attachment = '';
|
||||
$DB->update_record('glossary_entries', $entry);
|
||||
continue;
|
||||
}
|
||||
if (!$fs->file_exists($context->id, 'mod_glossary', $filearea, $entry->id, '/', $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_glossary', 'filearea'=>$filearea, 'itemid'=>$entry->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$entry->userid);
|
||||
if ($fs->create_file_from_pathname($file_record, $filepath)) {
|
||||
$entry->attachment = '1';
|
||||
$DB->update_record('glossary_entries', $entry);
|
||||
unlink($filepath);
|
||||
}
|
||||
}
|
||||
|
||||
// remove dirs if empty
|
||||
@rmdir("$CFG->dataroot/$entry->course/$CFG->moddata/glossary/$entry->glossaryid/$entry->id");
|
||||
@rmdir("$CFG->dataroot/$entry->course/$CFG->moddata/glossary/$entry->glossaryid");
|
||||
@rmdir("$CFG->dataroot/$entry->course/$CFG->moddata/glossary");
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008081900, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042000) {
|
||||
|
||||
/// Rename field definitionformat on table glossary_entries to definitionformat
|
||||
$table = new xmldb_table('glossary_entries');
|
||||
$field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'definition');
|
||||
|
||||
/// Launch rename field definitionformat
|
||||
$dbman->rename_field($table, $field, 'definitionformat');
|
||||
|
||||
/// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042000, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042001) {
|
||||
|
||||
/// Define field definitiontrust to be added to glossary_entries
|
||||
$table = new xmldb_table('glossary_entries');
|
||||
$field = new xmldb_field('definitiontrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'definitionformat');
|
||||
|
||||
/// Launch add field definitiontrust
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042001, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042002) {
|
||||
|
||||
/// Rename field format on table glossary_comments to NEWNAMEGOESHERE
|
||||
$table = new xmldb_table('glossary_comments');
|
||||
$field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'entrycomment');
|
||||
|
||||
/// Launch rename field format
|
||||
$dbman->rename_field($table, $field, 'entrycommentformat');
|
||||
|
||||
/// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042002, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042003) {
|
||||
|
||||
/// Define field entrycommenttrust to be added to glossary_comments
|
||||
$table = new xmldb_table('glossary_comments');
|
||||
$field = new xmldb_field('entrycommenttrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'entrycommentformat');
|
||||
|
||||
/// Conditionally launch add field entrycommenttrust
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
/// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042003, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042004) {
|
||||
$trustmark = '#####TRUSTTEXT#####';
|
||||
$rs = $DB->get_recordset_sql("SELECT * FROM {glossary_entries} WHERE definition LIKE ?", array($trustmark.'%'));
|
||||
foreach ($rs as $entry) {
|
||||
if (strpos($entry->definition, $trustmark) !== 0) {
|
||||
// probably lowercase in some DBs
|
||||
continue;
|
||||
}
|
||||
$entry->definition = str_replace($trustmark, '', $entry->definition);
|
||||
$entry->definitiontrust = 1;
|
||||
$DB->update_record('glossary_entries', $entry);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
/// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042004, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042005) {
|
||||
$trustmark = '#####TRUSTTEXT#####';
|
||||
$rs = $DB->get_recordset_sql("SELECT * FROM {glossary_comments} WHERE entrycomment LIKE ?", array($trustmark.'%'));
|
||||
foreach ($rs as $comment) {
|
||||
if (strpos($comment->entrycomment, $trustmark) !== 0) {
|
||||
// probably lowercase in some DBs
|
||||
continue;
|
||||
}
|
||||
$comment->entrycomment = str_replace($trustmark, '', $comment->entrycomment);
|
||||
$comment->entrycommenttrust = 1;
|
||||
$DB->update_record('glossary_comments', $comment);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
/// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042005, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042006) {
|
||||
|
||||
/// Define field introformat to be added to glossary
|
||||
$table = new xmldb_table('glossary');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Conditionally launch add field introformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('glossary', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
|
||||
foreach ($rs as $g) {
|
||||
$g->intro = text_to_html($g->intro, false, false, true);
|
||||
$g->introformat = FORMAT_HTML;
|
||||
$DB->update_record('glossary', $g);
|
||||
upgrade_set_timeout();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042006, 'glossary');
|
||||
}
|
||||
if ($oldversion < 2009110800) {
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
upgrade_set_timeout(60*20);
|
||||
|
||||
/// Define table glossary_comments to be dropped
|
||||
$table = new xmldb_table('glossary_comments');
|
||||
|
||||
/// Conditionally launch drop table for glossary_comments
|
||||
if ($dbman->table_exists($table)) {
|
||||
$sql = "SELECT e.glossaryid AS glossaryid,
|
||||
g.course AS courseid,
|
||||
c.userid,
|
||||
e.id AS itemid,
|
||||
c.id AS old_id,
|
||||
c.entrycomment AS commentcontent,
|
||||
c.entrycommentformat AS format,
|
||||
c.entrycommenttrust AS trust,
|
||||
c.timemodified AS timemodified
|
||||
FROM {glossary_comments} c, {glossary_entries} e, {glossary} g
|
||||
WHERE c.entryid=e.id AND e.glossaryid=g.id
|
||||
ORDER BY glossaryid, courseid";
|
||||
$lastglossaryid = null;
|
||||
$lastcourseid = null;
|
||||
$modcontext = null;
|
||||
|
||||
/// move glossary comments to comments table
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach($rs as $res) {
|
||||
if ($res->glossaryid != $lastglossaryid || $res->courseid != $lastcourseid) {
|
||||
$cm = get_coursemodule_from_instance('glossary', $res->glossaryid, $res->courseid);
|
||||
if ($cm) {
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
}
|
||||
$lastglossaryid = $res->glossaryid;
|
||||
$lastcourseid = $res->courseid;
|
||||
}
|
||||
$cmt = new stdClass();
|
||||
$cmt->contextid = $modcontext->id;
|
||||
$cmt->commentarea = 'glossary_entry';
|
||||
$cmt->itemid = $res->itemid;
|
||||
$cmt->content = $res->commentcontent;
|
||||
$cmt->format = $res->format;
|
||||
$cmt->userid = $res->userid;
|
||||
$cmt->timecreated = $res->timemodified;
|
||||
$cmt_id = $DB->insert_record('comments', $cmt);
|
||||
if (!empty($cmt_id)) {
|
||||
$DB->delete_records('glossary_comments', array('id'=>$res->old_id));
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
$dbman->drop_table($table);
|
||||
}
|
||||
|
||||
/// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009110800, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010042800) {
|
||||
//migrate glossary_ratings to the central rating table
|
||||
$table = new xmldb_table('glossary_ratings');
|
||||
if ($dbman->table_exists($table)) {
|
||||
//glossary ratings only have a single time column so use it for both time created and modified
|
||||
$sql = "INSERT INTO {rating} (contextid, scaleid, itemid, rating, userid, timecreated, timemodified)
|
||||
|
||||
SELECT cxt.id, g.scale, r.entryid AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified
|
||||
FROM {glossary_ratings} r
|
||||
JOIN {glossary_entries} ge ON ge.id=r.entryid
|
||||
JOIN {glossary} g ON g.id=ge.glossaryid
|
||||
JOIN {course_modules} cm ON cm.instance=g.id
|
||||
JOIN {context} cxt ON cxt.instanceid=cm.id
|
||||
JOIN {modules} m ON m.id=cm.module
|
||||
WHERE m.name = :modname AND cxt.contextlevel = :contextlevel";
|
||||
|
||||
$params['modname'] = 'glossary';
|
||||
$params['contextlevel'] = CONTEXT_MODULE;
|
||||
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
//now drop glossary_ratings
|
||||
$dbman->drop_table($table);
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2010042800, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010111500) {
|
||||
// Delete orphaned glossary_entries not belonging to any glossary (MDL-25227)
|
||||
$sql = "DELETE FROM {glossary_entries}
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 'x' FROM {glossary} g
|
||||
WHERE g.id = glossaryid)";
|
||||
$DB->execute($sql);
|
||||
|
||||
upgrade_mod_savepoint(true, 2010111500, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010111501) {
|
||||
|
||||
// Define field completionentries to be added to glossary
|
||||
$table = new xmldb_table('glossary');
|
||||
$field = new xmldb_field('completionentries', XMLDB_TYPE_INTEGER, '9', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timemodified');
|
||||
|
||||
// Conditionally launch add field completionentries
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// glossary savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010111501, 'glossary');
|
||||
}
|
||||
|
||||
if ($oldversion < 2011052300) {
|
||||
// rating.component and rating.ratingarea have now been added as mandatory fields.
|
||||
// Presently you can only rate data entries so component = 'mod_glossary' and ratingarea = 'entry'
|
||||
// for all ratings with a glossary context.
|
||||
// We want to update all ratings that belong to a glossary context and don't already have a
|
||||
// component set.
|
||||
// This could take a while reset upgrade timeout to 5 min
|
||||
upgrade_set_timeout(60 * 20);
|
||||
$sql = "UPDATE {rating}
|
||||
SET component = 'mod_glossary', ratingarea = 'entry'
|
||||
WHERE contextid IN (
|
||||
SELECT ctx.id
|
||||
FROM {context} ctx
|
||||
JOIN {course_modules} cm ON cm.id = ctx.instanceid
|
||||
JOIN {modules} m ON m.id = cm.module
|
||||
WHERE ctx.contextlevel = 70 AND
|
||||
m.name = 'glossary'
|
||||
) AND component = 'unknown'";
|
||||
$DB->execute($sql);
|
||||
|
||||
upgrade_mod_savepoint(true, 2011052300, 'glossary');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -34,15 +34,4 @@ defined('MOODLE_INTERNAL') || die();
|
||||
function xmldb_imscp_install() {
|
||||
global $CFG;
|
||||
|
||||
// Upgrade from old resource module type if needed
|
||||
require_once("$CFG->dirroot/mod/imscp/db/upgradelib.php");
|
||||
imscp_20_migrate();
|
||||
}
|
||||
|
||||
function xmldb_imscp_install_recovery() {
|
||||
global $CFG;
|
||||
|
||||
// Upgrade from old resource module type if needed
|
||||
require_once("$CFG->dirroot/mod/imscp/db/upgradelib.php");
|
||||
imscp_20_migrate();
|
||||
}
|
||||
|
||||
@@ -31,8 +31,6 @@ function xmldb_imscp_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* IMS CP module upgrade related helper functions
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage imscp
|
||||
* @copyright 2009 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Migrate imscp module data from 1.9 resource_old table to new imscp table
|
||||
* @return void
|
||||
*/
|
||||
function imscp_20_migrate() {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
require_once("$CFG->dirroot/course/lib.php");
|
||||
require_once("$CFG->dirroot/mod/imscp/locallib.php");
|
||||
|
||||
if (!file_exists("$CFG->dirroot/mod/resource/db/upgradelib.php")) {
|
||||
// bad luck, somebody deleted resource module
|
||||
return;
|
||||
}
|
||||
|
||||
require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
|
||||
|
||||
// create resource_old table and copy resource table there if needed
|
||||
if (!resource_20_prepare_migration()) {
|
||||
// no modules or fresh install
|
||||
return;
|
||||
}
|
||||
|
||||
$candidates = $DB->get_recordset('resource_old', array('type'=>'ims', 'migrated'=>0));
|
||||
if (!$candidates->valid()) {
|
||||
$candidates->close(); // Not going to iterate (but exit), close rs
|
||||
return;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
upgrade_set_timeout(60);
|
||||
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$intro = text_to_html($candidate->intro, false, false, true);
|
||||
$introformat = FORMAT_HTML;
|
||||
} else {
|
||||
$intro = $candidate->intro;
|
||||
$introformat = FORMAT_MOODLE;
|
||||
}
|
||||
|
||||
$imscp = new stdClass();
|
||||
$imscp->course = $candidate->course;
|
||||
$imscp->name = $candidate->name;
|
||||
$imscp->intro = $intro;
|
||||
$imscp->introformat = $introformat;
|
||||
$imscp->revision = 1;
|
||||
$imscp->keepold = 1;
|
||||
$imscp->timemodified = time();
|
||||
|
||||
if (!$imscp = resource_migrate_to_module('imscp', $candidate, $imscp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
|
||||
$root = "$CFG->dataroot/$candidate->course/$CFG->moddata/resource/$candidate->oldid";
|
||||
|
||||
// migrate package backup file
|
||||
if ($candidate->reference) {
|
||||
$package = basename($candidate->reference);
|
||||
$fullpath = $root.'/'.$package;
|
||||
if (file_exists($fullpath)) {
|
||||
$file_record = array('contextid' => $context->id,
|
||||
'component' => 'mod_imscp',
|
||||
'filearea' => 'backup',
|
||||
'itemid' => 1,
|
||||
'filepath' => '/',
|
||||
'filename' => $package);
|
||||
$fs->create_file_from_pathname($file_record, $fullpath);
|
||||
}
|
||||
}
|
||||
|
||||
// migrate extracted package data
|
||||
$files = imsc_migrate_get_old_files($root, '');
|
||||
if (empty($files)) {
|
||||
// if ims package doesn't exist, continue loop
|
||||
echo $OUTPUT->notification("IMS package data cannot be found, failed migrating activity: \"$candidate->name\", please fix it manually");
|
||||
continue;
|
||||
}
|
||||
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_imscp', 'filearea'=>'content', 'itemid'=>1);
|
||||
$error = false;
|
||||
foreach ($files as $relname=>$fullpath) {
|
||||
$parts = explode('/', $relname);
|
||||
$file_record['filename'] = array_pop($parts);
|
||||
$parts[] = ''; // keep trailing slash
|
||||
$file_record['filepath'] = implode('/', $parts);
|
||||
|
||||
try {
|
||||
$fs->create_file_from_pathname($file_record, $fullpath);
|
||||
} catch (Exception $e) {
|
||||
//continue on error, we can not recover anyway
|
||||
$error = true;
|
||||
echo $OUTPUT->notification("IMSCP: failed migrating file: $relname");
|
||||
}
|
||||
}
|
||||
unset($files);
|
||||
|
||||
// parse manifest
|
||||
$structure = imscp_parse_structure($imscp, $context);
|
||||
$imscp->structure = is_array($structure) ? serialize($structure) : null;
|
||||
$DB->update_record('imscp', $imscp);
|
||||
|
||||
// remove old moddata dir only if no error and manifest ok
|
||||
if (!$error and is_array($structure)) {
|
||||
fulldelete($root);
|
||||
}
|
||||
}
|
||||
$candidates->close();
|
||||
|
||||
// clear all course modinfo caches
|
||||
rebuild_course_cache(0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private function returning all extracted IMS content package file
|
||||
*/
|
||||
function imsc_migrate_get_old_files($path, $relative) {
|
||||
global $OUTPUT;
|
||||
$result = array();
|
||||
if (!file_exists($path)) {
|
||||
echo $OUTPUT->notification("File path doesn't exist: $path <br/> Please fix it manually.");
|
||||
return array();
|
||||
}
|
||||
$items = new DirectoryIterator($path);
|
||||
foreach ($items as $item) {
|
||||
if ($item->isDot() or $item->isLink()) {
|
||||
// symbolic links could create infinite loops or cause unintended file migration, sorry
|
||||
continue;
|
||||
}
|
||||
$pathname = $item->getPathname();
|
||||
$relname = $relative.'/'.$item->getFilename();
|
||||
if ($item->isFile()) {
|
||||
$result[$relname] = $pathname;
|
||||
} else if ($item->isDir()) {
|
||||
$result = array_merge($result, imsc_migrate_get_old_files($pathname, $relname));
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
unset($items);
|
||||
return $result;
|
||||
}
|
||||
@@ -51,39 +51,6 @@ function xmldb_label_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2009042200) {
|
||||
|
||||
/// Rename field content on table label to intro
|
||||
$table = new xmldb_table('label');
|
||||
$field = new xmldb_field('content', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name');
|
||||
|
||||
/// Launch rename field content
|
||||
$dbman->rename_field($table, $field, 'intro');
|
||||
|
||||
/// label savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042200, 'label');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042201) {
|
||||
|
||||
/// Define field introformat to be added to label
|
||||
$table = new xmldb_table('label');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', 'intro');
|
||||
|
||||
/// Launch add field introformat
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
// all existing lables in 1.9 are in HTML format
|
||||
$DB->set_field('label', 'introformat', FORMAT_HTML, array());
|
||||
|
||||
/// label savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042201, 'label');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
+1
-235
@@ -50,247 +50,13 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @global moodle_database $DB
|
||||
* @global core_renderer $OUTPUT
|
||||
* @param int $oldversion
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
function xmldb_lesson_upgrade($oldversion) {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2007072201) {
|
||||
|
||||
$table = new xmldb_table('lesson');
|
||||
$field = new xmldb_field('usegrademax');
|
||||
$field2 = new xmldb_field('usemaxgrade');
|
||||
|
||||
/// Rename lesson->usegrademax to lesson->usemaxgrade. Some old sites can have it incorrect. MDL-13177
|
||||
if ($dbman->field_exists($table, $field) && !$dbman->field_exists($table, $field2)) {
|
||||
/// Set field specs
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, '0', 'ongoing');
|
||||
/// Launch rename field usegrademax to usemaxgrade
|
||||
$dbman->rename_field($table, $field, 'usemaxgrade');
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2007072201, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008112601) {
|
||||
//NOTE: this is a hack, we can not call module lib.php in the middle of upgrade, the necessary db structures/data may not exist yet!
|
||||
require_once($CFG->dirroot.'/mod/lesson/lib.php');
|
||||
|
||||
lesson_upgrade_grades();
|
||||
|
||||
upgrade_mod_savepoint(true, 2008112601, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009111600) {
|
||||
/**
|
||||
* Change the grade field within lesson_answers to an unsigned int and increment
|
||||
* the length by one to ensure that no values are changed (reduced)
|
||||
*/
|
||||
$table = new xmldb_table('lesson_answers');
|
||||
$field = new xmldb_field('grade');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '4', false, XMLDB_NOTNULL, null, '0', 'jumpto');
|
||||
$dbman->change_field_type($table, $field);
|
||||
upgrade_mod_savepoint(true, 2009111600, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009120800) {
|
||||
/**
|
||||
* Drop the lesson_default table, as of Moodle 2.0 it is no longer used
|
||||
* the module now has a settings.php instead
|
||||
*/
|
||||
$table = new xmldb_table('lesson_default');
|
||||
$dbman->drop_table($table);
|
||||
upgrade_mod_savepoint(true, 2009120800, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009120801) {
|
||||
|
||||
/// Define field contentsformat to be added to lesson_pages
|
||||
$table = new xmldb_table('lesson_pages');
|
||||
$field = new xmldb_field('contentsformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, FORMAT_MOODLE, 'contents');
|
||||
|
||||
/// Conditionally launch add field contentsformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in contents
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('lesson_pages', array('contentsformat'=>FORMAT_MOODLE), '', 'id,contents,contentsformat');
|
||||
foreach ($rs as $lp) {
|
||||
$lp->contents = text_to_html($lp->contents, false, false, true);
|
||||
$lp->contentsformat = FORMAT_HTML;
|
||||
$DB->update_record('lesson_pages', $lp);
|
||||
upgrade_set_timeout();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
/// lesson savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009120801, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010072000) {
|
||||
// Define field answerformat to be added to lesson_answers
|
||||
$table = new xmldb_table('lesson_answers');
|
||||
$field = new xmldb_field('answerformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'answer');
|
||||
|
||||
// Launch add field answerformat
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
// lesson savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010072000, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010072001) {
|
||||
// Define field responseformat to be added to lesson_answers
|
||||
$table = new xmldb_table('lesson_answers');
|
||||
$field = new xmldb_field('responseformat', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'response');
|
||||
|
||||
// Launch add field responseformat
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
// lesson savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010072001, 'lesson');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010072003) {
|
||||
$rs = $DB->get_recordset('lesson_answers', array());
|
||||
foreach ($rs as $answer) {
|
||||
$flags = intval($answer->flags);
|
||||
$update = false;
|
||||
if ($flags & 1) {
|
||||
$answer->answer = text_to_html($answer->answer, false, false, true);
|
||||
$answer->answerformat = FORMAT_HTML;
|
||||
$update = true;
|
||||
}
|
||||
if ($flags & 2) {
|
||||
$answer->response = text_to_html($answer->response, false, false, true);
|
||||
$answer->responseformat = FORMAT_HTML;
|
||||
$update = true;
|
||||
}
|
||||
if ($update) {
|
||||
$DB->update_record('lesson_answers', $answer);
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
upgrade_mod_savepoint(true, 2010072003, 'lesson');
|
||||
}
|
||||
|
||||
|
||||
if ($oldversion < 2010081200) {
|
||||
require_once("$CFG->dirroot/mod/lesson/db/upgradelib.php");
|
||||
|
||||
$sqlfrom = "FROM {lesson} l
|
||||
JOIN {modules} m ON m.name = 'lesson'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = l.id)";
|
||||
|
||||
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
|
||||
|
||||
if ($count > 0) {
|
||||
$rs = $DB->get_recordset_sql("SELECT l.id, l.mediafile, l.course, cm.id AS cmid $sqlfrom ORDER BY l.course, l.id");
|
||||
|
||||
$pbar = new progress_bar('migratelessonfiles', 500, true);
|
||||
$fs = get_file_storage();
|
||||
|
||||
$i = 0;
|
||||
foreach ($rs as $lesson) {
|
||||
$i++;
|
||||
upgrade_set_timeout(120); // set up timeout, may also abort execution
|
||||
$pbar->update($i, $count, "Migrating lesson files - $i/$count.");
|
||||
|
||||
// fix images incorrectly placed in moddata subfolders,
|
||||
// this was a really bad decision done by the ppt import developer
|
||||
if (file_exists("$CFG->dataroot/$lesson->course/moddata/lesson/")) {
|
||||
lesson_20_migrate_moddata_mixture($lesson->course, '/moddata/lesson/');
|
||||
@rmdir("$CFG->dataroot/$lesson->course/moddata/lesson/"); // remove dir if empty
|
||||
@rmdir("$CFG->dataroot/$lesson->course/moddata/"); // remove dir if empty
|
||||
}
|
||||
|
||||
// migrate media file only if local course file selected - this is not nice at all,
|
||||
// it should better be a real block, not a lesson specific hack
|
||||
if (strpos($lesson->mediafile, '://') !== false) {
|
||||
// some external URL
|
||||
|
||||
} else if ($lesson->mediafile) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $lesson->cmid);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $lesson->course);
|
||||
$filepathname = clean_param('/'.$lesson->mediafile, PARAM_PATH);
|
||||
$fullpath = "/$context->id/mod_lesson/mediafile/0$filepathname";
|
||||
|
||||
if ($file = $fs->get_file_by_hash(sha1($fullpath)) and !$file->is_directory()) {
|
||||
// already converted, just update filename
|
||||
$DB->set_field('lesson', 'mediafile', $filepathname, array('id'=>$lesson->id));
|
||||
} else {
|
||||
// let's copy file from current course legacy files if possible
|
||||
$fullpath = "/$coursecontext->id/course/legacy/0$filepathname";
|
||||
if ($file = $fs->get_file_by_hash(sha1($fullpath)) and !$file->is_directory()) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_lesson', 'filearea'=>'mediafile', 'itemid'=>0, 'filepath'=>$file->get_filepath(), 'filename'=>$file->get_filename(), 'sortorder'=>1);
|
||||
$fs->create_file_from_storedfile($file_record, $file);
|
||||
$DB->set_field('lesson', 'mediafile', $filepathname, array('id'=>$lesson->id));
|
||||
|
||||
} else {
|
||||
// bad luck, no such file exists
|
||||
$DB->set_field('lesson', 'mediafile', '', array('id'=>$lesson->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2010081200, 'lesson');
|
||||
}
|
||||
|
||||
|
||||
if ($oldversion < 2010121400) {
|
||||
// Fix matching question pages.
|
||||
// In Moodle 1.9 matching question pages stored the correct and incorrect
|
||||
// jumps on the third and forth answers, in Moodle 2.0 they are stored
|
||||
// in the first and second answers.
|
||||
// This upgrade block detects matching questions where this is the case
|
||||
// and fixed it by making firstjump = thirdjump && secondjump = forthjump.
|
||||
$pages = $DB->get_recordset('lesson_pages', array('qtype'=>'5'));
|
||||
foreach ($pages as $page) {
|
||||
$answers = $DB->get_records('lesson_answers', array('pageid'=>$page->id), 'id', 'id, jumpto', 0, 4);
|
||||
if (count($answers) < 4) {
|
||||
// If there are less then four answers the problem wont exist.
|
||||
// All Moodle 1.9 matching questions had a least 4 answers.
|
||||
continue;
|
||||
}
|
||||
$first = array_shift($answers);
|
||||
$second = array_shift($answers);
|
||||
$third = array_shift($answers);
|
||||
$forth = array_shift($answers);
|
||||
if ($first->jumpto !== '0' || $second->jumpto !== '0') {
|
||||
// If either are set to something other than the next page then
|
||||
// there is no problem.
|
||||
continue;
|
||||
}
|
||||
if ($third->jumpto !== '0') {
|
||||
$first->jumpto = $third->jumpto;
|
||||
$DB->update_record('lesson_answers', $first);
|
||||
$third->jumpto = '0';
|
||||
$DB->update_record('lesson_answers', $third);
|
||||
}
|
||||
if ($forth->jumpto !== '0') {
|
||||
$second->jumpto = $forth->jumpto;
|
||||
$DB->update_record('lesson_answers', $second);
|
||||
$forth->jumpto = '0';
|
||||
$DB->update_record('lesson_answers', $forth);
|
||||
}
|
||||
}
|
||||
// Close the record set
|
||||
$pages->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2010121400, 'lesson');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Resource module upgrade related helper functions
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage lesson
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Migrate lesson images incorrectly placed into moddata folder,
|
||||
* the images were stored in random directories ignoring all coding rules.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function lesson_20_migrate_moddata_mixture($courseid, $path) {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
|
||||
$fullpathname = "$CFG->dataroot/$courseid".$path;
|
||||
|
||||
if (!file_exists($fullpathname)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
$items = new DirectoryIterator($fullpathname);
|
||||
$fs = get_file_storage();
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->isDot()) {
|
||||
// skip
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item->isFile()) {
|
||||
if (!$item->isReadable()) {
|
||||
echo $OUTPUT->notification(" File not readable, skipping: ".$courseid.$path.$item->getFilename());
|
||||
continue;
|
||||
}
|
||||
|
||||
$filepath = clean_param($path, PARAM_PATH);
|
||||
$filename = clean_param($item->getFilename(), PARAM_FILE);
|
||||
|
||||
if ($filename === '') {
|
||||
//unsupported chars, sorry
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$fs->file_exists($context->id, 'course', 'legacy', '0', $filepath, $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'course', 'filearea'=>'legacy', 'itemid'=>0, 'filepath'=>$filepath, 'filename'=>$filename,
|
||||
'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime());
|
||||
$fs->create_file_from_pathname($file_record, $fullpathname.$item->getFilename());
|
||||
@unlink($fullpathname.$item->getFilename());
|
||||
}
|
||||
|
||||
} else {
|
||||
//migrate recursively all subdirectories
|
||||
lesson_20_migrate_moddata_mixture($courseid, $path.$item->getFilename().'/');
|
||||
}
|
||||
}
|
||||
|
||||
unset($item); //release file handles
|
||||
unset($items); //release file handles
|
||||
|
||||
// delete dir if empty
|
||||
@rmdir($fullpathname);
|
||||
}
|
||||
@@ -64,19 +64,6 @@ function xmldb_lti_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if ($oldversion < 2011111600){
|
||||
// Rename showdescription to showdescriptionlaunch to not conflict with setting from core Moodle
|
||||
// Rename showtitle as well to be consistent
|
||||
$table = new xmldb_table('lti');
|
||||
$field = new xmldb_field('showtitle', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'debuglaunch');
|
||||
|
||||
$dbman->rename_field($table, $field, 'showtitlelaunch');
|
||||
|
||||
$field = new xmldb_field('showdescription', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'showtitlelaunch');
|
||||
$dbman->rename_field($table, $field, 'showdescriptionlaunch');
|
||||
|
||||
upgrade_mod_savepoint(true, 2011111600, 'lti');
|
||||
}
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -34,17 +34,4 @@ defined('MOODLE_INTERNAL') || die;
|
||||
function xmldb_page_install() {
|
||||
global $CFG;
|
||||
|
||||
// Upgrade from old resource module type if needed
|
||||
require_once("$CFG->dirroot/mod/page/db/upgradelib.php");
|
||||
page_20_migrate();
|
||||
|
||||
}
|
||||
|
||||
function xmldb_page_install_recovery() {
|
||||
global $CFG;
|
||||
|
||||
// Upgrade from old resource module type if needed
|
||||
require_once("$CFG->dirroot/mod/page/db/upgradelib.php");
|
||||
page_20_migrate();
|
||||
|
||||
}
|
||||
|
||||
@@ -48,12 +48,9 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
function xmldb_page_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
require_once("$CFG->dirroot/mod/page/db/upgradelib.php");
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Folder module upgrade related helper functions
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage page
|
||||
* @copyright 2009 Petr Skoda (http://skodak.org)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Migrate page module data from 1.9 resource_old table to new page table
|
||||
* @return void
|
||||
*/
|
||||
function page_20_migrate() {
|
||||
global $CFG, $DB;
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
require_once("$CFG->libdir/resourcelib.php");
|
||||
require_once("$CFG->dirroot/course/lib.php");
|
||||
|
||||
if (!file_exists("$CFG->dirroot/mod/resource/db/upgradelib.php")) {
|
||||
// bad luck, somebody deleted resource module
|
||||
return;
|
||||
}
|
||||
|
||||
require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
|
||||
|
||||
// create resource_old table and copy resource table there if needed
|
||||
if (!resource_20_prepare_migration()) {
|
||||
// no modules or fresh install
|
||||
return;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$candidates = $DB->get_recordset('resource_old', array('type'=>'html', 'migrated'=>0));
|
||||
foreach ($candidates as $candidate) {
|
||||
page_20_migrate_candidate($candidate, $fs, FORMAT_HTML);
|
||||
}
|
||||
$candidates->close();
|
||||
|
||||
$candidates = $DB->get_recordset('resource_old', array('type'=>'text', 'migrated'=>0));
|
||||
foreach ($candidates as $candidate) {
|
||||
//there might be some rubbish instead of format int value
|
||||
$format = (int)$candidate->reference;
|
||||
if ($format < 0 or $format > 4) {
|
||||
$format = FORMAT_MOODLE;
|
||||
}
|
||||
page_20_migrate_candidate($candidate, $fs, $format);
|
||||
}
|
||||
$candidates->close();
|
||||
|
||||
// clear all course modinfo caches
|
||||
rebuild_course_cache(0, true);
|
||||
|
||||
}
|
||||
|
||||
function page_20_migrate_candidate($candidate, $fs, $format) {
|
||||
global $CFG, $DB;
|
||||
upgrade_set_timeout();
|
||||
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$intro = text_to_html($candidate->intro, false, false, true);
|
||||
$introformat = FORMAT_HTML;
|
||||
} else {
|
||||
$intro = $candidate->intro;
|
||||
$introformat = FORMAT_MOODLE;
|
||||
}
|
||||
|
||||
$page = new stdClass();
|
||||
$page->course = $candidate->course;
|
||||
$page->name = $candidate->name;
|
||||
$page->intro = $intro;
|
||||
$page->introformat = $introformat;
|
||||
$page->content = $candidate->alltext;
|
||||
$page->contentformat = $format;
|
||||
$page->revision = 1;
|
||||
$page->timemodified = time();
|
||||
|
||||
// convert links to old course files - let the automigration do the actual job
|
||||
$usedfiles = array("$CFG->wwwroot/file.php/$page->course/", "$CFG->wwwroot/file.php?file=/$page->course/");
|
||||
$page->content = str_ireplace($usedfiles, '@@PLUGINFILE@@/', $page->content);
|
||||
if (strpos($page->content, '@@PLUGINFILE@@/') === false) {
|
||||
$page->legacyfiles = RESOURCELIB_LEGACYFILES_NO;
|
||||
} else {
|
||||
$page->legacyfiles = RESOURCELIB_LEGACYFILES_ACTIVE;
|
||||
}
|
||||
|
||||
$options = array('printheading'=>0, 'printintro'=>0);
|
||||
if ($candidate->popup) {
|
||||
$page->display = RESOURCELIB_DISPLAY_POPUP;
|
||||
if ($candidate->popup) {
|
||||
$rawoptions = explode(',', $candidate->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);
|
||||
|
||||
$page = resource_migrate_to_module('page', $candidate, $page);
|
||||
|
||||
// now try to migrate files from site files
|
||||
// note: this can not work for html pages or files with other relatively linked files :-(
|
||||
$siteid = get_site()->id;
|
||||
if (preg_match_all("|$CFG->wwwroot/file.php(\?file=)?/$siteid(/[^\s'\"&\?#]+)|", $page->content, $matches)) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
|
||||
$sitecontext = get_context_instance(CONTEXT_COURSE, $siteid);
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_page', 'filearea'=>'content', 'itemid'=>0);
|
||||
$fs = get_file_storage();
|
||||
foreach ($matches[2] as $i=>$sitefile) {
|
||||
if (!$file = $fs->get_file_by_hash(sha1("/$sitecontext->id/course/legacy/0".$sitefile))) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$fs->create_file_from_storedfile($file_record, $file);
|
||||
$page->content = str_replace($matches[0][$i], '@@PLUGINFILE@@'.$sitefile, $page->content);
|
||||
} catch (Exception $x) {
|
||||
}
|
||||
}
|
||||
$DB->update_record('page', $page);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,94 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Upgrade helper code for the quiz module.
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage quiz
|
||||
* @copyright 2006 Eloy Lafuente (stronk7)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Upgrade states for an attempt to Moodle 1.5 model
|
||||
*
|
||||
* Any state that does not yet have its timestamp set to nonzero has not yet been
|
||||
* upgraded from Moodle 1.4. The reason these are still around is that for large
|
||||
* sites it would have taken too long to upgrade all states at once. This function
|
||||
* sets the timestamp field and creates an entry in the question_sessions table.
|
||||
* @param object $attempt The attempt whose states need upgrading
|
||||
*/
|
||||
function quiz_upgrade_very_old_question_sessions($attempt) {
|
||||
global $DB;
|
||||
// The old quiz model only allowed a single response per quiz attempt so that there will be
|
||||
// only one state record per question for this attempt.
|
||||
|
||||
// We set the timestamp of all states to the timemodified field of the attempt.
|
||||
$DB->execute("UPDATE {question_states} SET timestamp = ? WHERE attempt = ?",
|
||||
array($attempt->timemodified, $attempt->uniqueid));
|
||||
|
||||
// For each state we create an entry in the question_sessions table, with both newest and
|
||||
// newgraded pointing to this state.
|
||||
// Actually we only do this for states whose question is actually listed in $attempt->layout.
|
||||
// We do not do it for states associated to wrapped questions like for example the questions
|
||||
// used by a random question
|
||||
$session = new stdClass();
|
||||
$session->attemptid = $attempt->uniqueid;
|
||||
$session->sumpenalty = 0;
|
||||
$session->manualcomment = '';
|
||||
$session->manualcommentformat = FORMAT_HTML;
|
||||
$session->flagged = 0;
|
||||
|
||||
$questionlist = str_replace(',0', '', quiz_clean_layout($attempt->layout, true));
|
||||
if (!$questionlist) {
|
||||
return;
|
||||
}
|
||||
list($usql, $question_params) = $DB->get_in_or_equal(explode(',', $questionlist));
|
||||
$params = array_merge(array($attempt->uniqueid), $question_params);
|
||||
|
||||
if ($states = $DB->get_records_select('question_states',
|
||||
"attempt = ? AND question $usql", $params)) {
|
||||
foreach ($states as $state) {
|
||||
if ($DB->record_exists('question_sessions',
|
||||
array('attemptid' => $attempt->uniqueid, 'questionid' => $state->question))) {
|
||||
// It was possible for the code to get here when some of the necessary
|
||||
// question_sessions were already in the database. That lead to a
|
||||
// unique key violation, so we manually detect and avoid that.
|
||||
continue;
|
||||
}
|
||||
$session->newgraded = $state->id;
|
||||
$session->newest = $state->id;
|
||||
$session->questionid = $state->question;
|
||||
$DB->insert_record('question_sessions', $session, false);
|
||||
}
|
||||
}
|
||||
|
||||
// It was possible to have old question_states records for this attempt but
|
||||
// pointing to questionids that were no longer in quiz_attempt->layout.
|
||||
// That makes no sense, and will break things later in the upgrade, so delete
|
||||
// those now.
|
||||
list($qidsql, $params) = $DB->get_in_or_equal(explode(',', $questionlist),
|
||||
SQL_PARAMS_QM, 'param', false);
|
||||
$params[] = $attempt->uniqueid;
|
||||
$DB->delete_records_select('question_states', "question $usql AND attempt = ?", $params);
|
||||
}
|
||||
@@ -48,222 +48,9 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
function xmldb_resource_upgrade($oldversion) {
|
||||
global $CFG, $DB;
|
||||
require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2009041900) {
|
||||
resource_20_prepare_migration();
|
||||
// resource savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009041900, 'resource');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042000) {
|
||||
// Rename field summary on table resource to intro
|
||||
$table = new xmldb_table('resource');
|
||||
$field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'reference');
|
||||
|
||||
// Launch rename field summary
|
||||
$dbman->rename_field($table, $field, 'intro');
|
||||
|
||||
// resource savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042000, 'resource');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042001) {
|
||||
// Define field introformat to be added to resource
|
||||
$table = new xmldb_table('resource');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
// Launch add field introformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('resource', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
|
||||
foreach ($rs as $r) {
|
||||
$r->intro = text_to_html($r->intro, false, false, true);
|
||||
$r->introformat = FORMAT_HTML;
|
||||
$DB->update_record('resource', $r);
|
||||
upgrade_set_timeout();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
// resource savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042001, 'resource');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009062600) {
|
||||
$res_count = $DB->count_records('resource');
|
||||
$old_count = $DB->count_records('resource_old', array('migrated'=>0));
|
||||
if ($res_count != $old_count) {
|
||||
//we can not continue, something is very wrong!!
|
||||
upgrade_log(UPGRADE_LOG_ERROR, null, 'Resource migration failed.');
|
||||
upgrade_mod_savepoint(false, 2009062600, 'resource');
|
||||
}
|
||||
|
||||
// Drop obsoleted fields from resource table
|
||||
$table = new xmldb_table('resource');
|
||||
$fields = array('type', 'reference', 'alltext', 'popup', 'options');
|
||||
foreach ($fields as $fname) {
|
||||
$field = new xmldb_field($fname);
|
||||
$dbman->drop_field($table, $field);
|
||||
}
|
||||
|
||||
// resource savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009062600, 'resource');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009062601) {
|
||||
$table = new xmldb_table('resource');
|
||||
// Define field tobemigrated to be added to resource
|
||||
$field = new xmldb_field('tobemigrated', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'introformat');
|
||||
// Conditionally launch add field tobemigrated
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
// Define field mainfile to be added to resource
|
||||
$field = new xmldb_field('mainfile', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'tobemigrated');
|
||||
// Conditionally launch add field mainfile
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
// Define field legacyfiles to be added to resource
|
||||
$field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'mainfile');
|
||||
// Conditionally launch add field legacyfiles
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
// Define field legacyfileslast to be added to resource
|
||||
$field = new xmldb_field('legacyfileslast', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'legacyfiles');
|
||||
// Conditionally launch add field legacyfileslast
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
// Define field display to be added to resource
|
||||
$field = new xmldb_field('display', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'legacyfileslast');
|
||||
// Conditionally launch add field display
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
// Define field displayoptions to be added to resource
|
||||
$field = new xmldb_field('displayoptions', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'display');
|
||||
// Conditionally launch add field displayoptions
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
// Define field filterfiles to be added to resource
|
||||
$field = new xmldb_field('filterfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'displayoptions');
|
||||
// Conditionally launch add field filterfiles
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
// Define field revision to be added to resource
|
||||
$field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'filterfiles');
|
||||
// Conditionally launch add field revision
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
//mark all records as awaiting migration
|
||||
$DB->set_field('resource', 'tobemigrated', 1, array());
|
||||
|
||||
// resource savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009062601, 'resource');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009062603) {
|
||||
resource_20_migrate();
|
||||
upgrade_mod_savepoint(true, 2009062603, 'resource');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009063000) {
|
||||
//migrate and prune old settings - admins need to review and set up all module settings anyway
|
||||
if (!empty($CFG->resource_framesize)) {
|
||||
set_config('framesize', $CFG->resource_framesize, 'resource');
|
||||
}
|
||||
if (!empty($CFG->resource_popupheight)) {
|
||||
set_config('popupheight', $CFG->resource_popupheight, 'resource');
|
||||
}
|
||||
if (!empty($CFG->resource_popupwidth)) {
|
||||
set_config('popupwidth', $CFG->resource_popupwidth, 'resource');
|
||||
}
|
||||
|
||||
$cleanupsettings = array(
|
||||
// migrated settings
|
||||
'resource_framesize', 'resource_popupheight', 'resource_popupwidth', 'resource_popupmenubar',
|
||||
|
||||
// obsoleted settings
|
||||
'resource_websearch', 'resource_defaulturl', 'resource_allowlocalfiles',
|
||||
'resource_popup', 'resource_popupresizable', 'resource_popupscrollbars',
|
||||
'resource_popupdirectories', 'resource_popuplocation',
|
||||
'resource_popuptoolbar', 'resource_popupstatus',
|
||||
|
||||
//waiting for some other modules or plugins to pick these up
|
||||
/*
|
||||
'resource_secretphrase',
|
||||
*/
|
||||
);
|
||||
foreach ($cleanupsettings as $setting) {
|
||||
unset_config($setting);
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2009063000, 'resource');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009080501) {
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
|
||||
$sql = "SELECT r.id,
|
||||
r.mainfile,
|
||||
cm.id AS cmid
|
||||
FROM {resource} r
|
||||
JOIN {modules} m ON m.name='resource'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = r.id)";
|
||||
|
||||
$instances = $DB->get_recordset_sql($sql);
|
||||
foreach ($instances as $instance) {
|
||||
if (empty($instance->mainfile)) {
|
||||
// weird
|
||||
continue;
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_MODULE, $instance->cmid, MUST_EXIST);
|
||||
$parts = explode('/', $instance->mainfile);
|
||||
$filename = array_pop($parts);
|
||||
$filepath = implode('/', $parts);
|
||||
file_set_sortorder($context->id, 'mod_resource', 'content', 0, $filepath, $filename, 1);
|
||||
}
|
||||
$instances->close();
|
||||
|
||||
/// Define field mainfile to be dropped from resource
|
||||
$table = new xmldb_table('resource');
|
||||
$field = new xmldb_field('mainfile');
|
||||
$dbman->drop_field($table, $field);
|
||||
|
||||
/// resource savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009080501, 'resource');
|
||||
}
|
||||
|
||||
// MDL-10906. Removing resource_allowlocalfiles setting.
|
||||
if ($oldversion < 2010083000) {
|
||||
unset_config('resource_allowlocalfiles');
|
||||
upgrade_mod_savepoint(true, 2010083000, 'resource');
|
||||
}
|
||||
|
||||
if ($oldversion < 2011022700) {
|
||||
// refresh resource links breakage caused by invalid sortorder
|
||||
require_once($CFG->dirroot . '/course/lib.php');
|
||||
rebuild_course_cache(0, true);
|
||||
upgrade_mod_savepoint(true, 2011022700, 'resource');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,304 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Resource module upgrade related helper functions
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage resource
|
||||
* @copyright 2009 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Migrate resource module data from 1.9 resource_old table to new resource table
|
||||
* @return void
|
||||
*/
|
||||
function resource_20_migrate() {
|
||||
global $CFG, $DB;
|
||||
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
require_once("$CFG->libdir/resourcelib.php");
|
||||
require_once("$CFG->dirroot/course/lib.php");
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$withrelativelinks = array('text/html', 'text/xml', 'application/xhtml+xml', 'application/x-shockwave-flash');
|
||||
// note: pdf doc and other types may contain links too, but we do not support relative links there
|
||||
|
||||
$candidates = $DB->get_recordset('resource_old', array('type'=>'file', 'migrated'=>0));
|
||||
if (!$candidates->valid()) {
|
||||
$candidates->close(); // Not going to iterate (but exit), close rs
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
upgrade_set_timeout();
|
||||
|
||||
$path = $candidate->reference;
|
||||
$siteid = get_site()->id;
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (empty($candidate->cmid)) {
|
||||
// skip borked records
|
||||
continue;
|
||||
|
||||
} else if (strpos($path, 'LOCALPATH') === 0) {
|
||||
// ignore not maintained local files - sorry
|
||||
continue;
|
||||
|
||||
} else if (preg_match("|$CFG->wwwroot/file.php(\?file=)?/$siteid(/[^\s'\"&\?#]+)|", $path, $matches)) {
|
||||
// public site files
|
||||
$path = $matches[2];
|
||||
|
||||
$resource = new stdClass();
|
||||
$resource->id = $candidate->oldid;
|
||||
$resource->tobemigrated = 0;
|
||||
$resource->mainfile = $path;
|
||||
$resource->filterfiles = $CFG->filteruploadedfiles;
|
||||
$resource->legacyfiles = RESOURCELIB_LEGACYFILES_NO; // on-demand-migration not possible for site files, sorry
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
|
||||
$sitecontext = get_context_instance(CONTEXT_COURSE, $siteid);
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_resourse', 'filearea'=>'content', 'itemid'=>0);
|
||||
if ($file = $fs->get_file_by_hash(sha1("/$sitecontext->id/course/legacy/content/0".$path))) {
|
||||
try {
|
||||
$fs->create_file_from_storedfile($file_record, $file);
|
||||
} catch (Exception $x) {
|
||||
}
|
||||
$resource->mainfile = $file->get_filepath().$file->get_filename();
|
||||
}
|
||||
|
||||
} else if (preg_match("|$CFG->wwwroot/file.php(\?file=)?/$candidate->course(/[^\s'\"&\?#]+)|", $path, $matches)) {
|
||||
// current course files
|
||||
$path = $matches[2];
|
||||
|
||||
$resource = new stdClass();
|
||||
$resource->id = $candidate->oldid;
|
||||
$resource->tobemigrated = 0;
|
||||
$resource->mainfile = $path;
|
||||
$resource->filterfiles = $CFG->filteruploadedfiles;
|
||||
$mimetype = mimeinfo('type', $resource->mainfile);
|
||||
if (in_array($mimetype, $withrelativelinks)) {
|
||||
$resource->legacyfiles = RESOURCELIB_LEGACYFILES_ACTIVE;
|
||||
} else {
|
||||
$resource->legacyfiles = RESOURCELIB_LEGACYFILES_NO;
|
||||
}
|
||||
|
||||
// try migration of main file - ignore if does not exist
|
||||
if ($file = resourcelib_try_file_migration($resource->mainfile, $candidate->cmid, $candidate->course, 'mod_resource', 'content', 0)) {
|
||||
$resource->mainfile = $file->get_filepath().$file->get_filename();
|
||||
}
|
||||
|
||||
} else if (strpos($path, '://') or strpos($path, '/') === 0) {
|
||||
// http:// https:// ftp:// OR starts with slash - to be converted to link resource
|
||||
continue;
|
||||
|
||||
} else {
|
||||
// current course files
|
||||
// cleanup old path first
|
||||
$path = '/'.trim(trim($path), '/');
|
||||
if (strpos($path, '?forcedownload=1') !== false) {
|
||||
// eliminate old force download tricks
|
||||
$candidate->options = 'forcedownload';
|
||||
$path = str_replace('?forcedownload=1', '', $path);
|
||||
}
|
||||
// get rid of any extra url parameters, sorry we can not support these
|
||||
preg_match("/^[^?#]+/", $path, $matches);
|
||||
$parts = $matches[0];
|
||||
|
||||
$resource = new stdClass();
|
||||
$resource->id = $candidate->oldid;
|
||||
$resource->tobemigrated = 0;
|
||||
$resource->mainfile = $path;
|
||||
$resource->filterfiles = $CFG->filteruploadedfiles;
|
||||
$mimetype = mimeinfo('type', $resource->mainfile);
|
||||
if (in_array($mimetype, $withrelativelinks)) {
|
||||
$resource->legacyfiles = RESOURCELIB_LEGACYFILES_ACTIVE;
|
||||
} else {
|
||||
$resource->legacyfiles = RESOURCELIB_LEGACYFILES_NO;
|
||||
}
|
||||
|
||||
// try migration of main file - ignore if does not exist
|
||||
if ($file = resourcelib_try_file_migration($resource->mainfile, $candidate->cmid, $candidate->course, 'mod_resource', 'content', 0)) {
|
||||
$resource->mainfile = $file->get_filepath().$file->get_filename();
|
||||
}
|
||||
}
|
||||
|
||||
$options = array('printheading'=>0, 'printintro'=>1);
|
||||
if ($candidate->options == 'frame') {
|
||||
$resource->display = RESOURCELIB_DISPLAY_FRAME;
|
||||
|
||||
} else if ($candidate->options == 'objectframe') {
|
||||
$resource->display = RESOURCELIB_DISPLAY_EMBED;
|
||||
|
||||
} else if ($candidate->options == 'forcedownload') {
|
||||
$resource->display = RESOURCELIB_DISPLAY_DOWNLOAD;
|
||||
|
||||
} else if ($candidate->popup) {
|
||||
$resource->display = RESOURCELIB_DISPLAY_POPUP;
|
||||
if ($candidate->popup) {
|
||||
$rawoptions = explode(',', $candidate->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 {
|
||||
$resource->display = RESOURCELIB_DISPLAY_AUTO;
|
||||
}
|
||||
$resource->displayoptions = serialize($options);
|
||||
|
||||
// update resource instance and mark as migrated
|
||||
$DB->update_record('resource', $resource);
|
||||
$candidate->newmodule = 'resource';
|
||||
$candidate->newid = $candidate->oldid;
|
||||
$candidate->migrated = time();
|
||||
$DB->update_record('resource_old', $candidate);
|
||||
}
|
||||
|
||||
$candidates->close();
|
||||
|
||||
// clear all course modinfo caches
|
||||
rebuild_course_cache(0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates resource_old table and copies all data
|
||||
* from resource table, this functions has to be called from
|
||||
* all modules that are successors of old resource module types.
|
||||
* @return bool true if migration required, false if not
|
||||
*/
|
||||
function resource_20_prepare_migration() {
|
||||
global $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
// If the resource not created yet, this is probably a new install
|
||||
$table = new xmldb_table('resource');
|
||||
if (!$dbman->table_exists($table)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Define table resource_old to be created
|
||||
$table = new xmldb_table('resource_old');
|
||||
|
||||
if ($dbman->table_exists($table)) {
|
||||
//already executed
|
||||
return true;
|
||||
}
|
||||
|
||||
// fix invalid NULL popup and options data in old mysql databases
|
||||
$sql = "UPDATE {resource} SET popup = ? WHERE popup IS NULL";
|
||||
$DB->execute($sql, array($DB->sql_empty()));
|
||||
$sql = "UPDATE {resource} SET options = ? WHERE options IS NULL";
|
||||
$DB->execute($sql, array($DB->sql_empty()));
|
||||
|
||||
// Adding fields to table resource_old
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('type', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('reference', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('intro', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
|
||||
$table->add_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('alltext', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('popup', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('options', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('newmodule', XMLDB_TYPE_CHAR, '50', null, null, null, null);
|
||||
$table->add_field('newid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('migrated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
// Adding keys to table resource_old
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
|
||||
// Adding indexes to table resource_old
|
||||
$table->add_index('oldid', XMLDB_INDEX_UNIQUE, array('oldid'));
|
||||
$table->add_index('cmid', XMLDB_INDEX_NOTUNIQUE, array('cmid'));
|
||||
|
||||
// Launch create table for resource_old
|
||||
$dbman->create_table($table);
|
||||
|
||||
$module = $DB->get_field('modules', 'id', array('name'=>'resource'));
|
||||
|
||||
if (!$DB->count_records('resource')) {
|
||||
// upgrade of fresh new server from 1.9 - no upgrade needed
|
||||
return false;
|
||||
}
|
||||
|
||||
// copy old data, the intro text format was FORMAT_MOODLE==0
|
||||
$sql = "INSERT INTO {resource_old} (oldid, course, name, type, reference, intro, introformat, alltext, popup, options, timemodified, cmid)
|
||||
SELECT r.id, r.course, r.name, r.type, r.reference, r.summary, 0, r.alltext, r.popup, r.options, r.timemodified, cm.id
|
||||
FROM {resource} r
|
||||
LEFT JOIN {course_modules} cm ON (r.id = cm.instance AND cm.module = :module)";
|
||||
|
||||
$DB->execute($sql, array('module'=>$module));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate old resource type to new module, updates all related info, keeps the context id.
|
||||
* @param string $modname name of new module
|
||||
* @param object $candidate old instance from resource_old
|
||||
* @param object $newinstance new module instance to be inserted into db
|
||||
* @return mixed false if error, object new instance with id if success
|
||||
*/
|
||||
function resource_migrate_to_module($modname, $candidate, $newinstance) {
|
||||
global $DB;
|
||||
|
||||
if (!$cm = get_coursemodule_from_id('resource', $candidate->cmid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$module = $DB->get_record('modules', array('name'=>$modname))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$resource = $DB->get_record('resource', array('id'=>$candidate->oldid))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// insert new instance
|
||||
$newinstance->id = $DB->insert_record($modname, $newinstance);
|
||||
|
||||
// update course modules
|
||||
$cm->module = $module->id;
|
||||
$cm->instance = $newinstance->id;
|
||||
$DB->update_record('course_modules', $cm);
|
||||
|
||||
//delete old record
|
||||
$DB->delete_records('resource', array('id'=>$resource->id));
|
||||
|
||||
//mark as migrated
|
||||
$candidate->newmodule = $modname;
|
||||
$candidate->newid = $newinstance->id;
|
||||
$candidate->migrated = time();
|
||||
$DB->update_record('resource_old', $candidate);
|
||||
|
||||
//no need to upgrade data in logs because resource module is able to redirect to migrated instances
|
||||
return $newinstance;
|
||||
}
|
||||
@@ -34,575 +34,6 @@ function xmldb_scorm_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
// Adding missing 'whatgrade' field to table scorm
|
||||
if ($oldversion < 2008073000) {
|
||||
$table = new xmldb_table('scorm');
|
||||
$field = new xmldb_field('whatgrade');
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'grademethod');
|
||||
|
||||
/// Launch add field whatgrade
|
||||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
$whatgradefixed = get_config('scorm', 'whatgradefixed');
|
||||
if (empty($whatgradefixed)) {
|
||||
/// fix bad usage of whatgrade/grading method.
|
||||
$scorms = $DB->get_records('scorm');
|
||||
foreach ($scorms as $scorm) {
|
||||
$scorm->whatgrade = $scorm->grademethod/10;
|
||||
$DB->update_record('scorm', $scorm);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//dump this config var as it isn't needed anymore.
|
||||
unset_config('whatgradefixed', 'scorm');
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2008073000, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008082500) {
|
||||
|
||||
/// Define field scormtype to be added to scorm
|
||||
$table = new xmldb_table('scorm');
|
||||
$field = new xmldb_field('scormtype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, 'local', 'name');
|
||||
|
||||
/// Launch add field scormtype
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008082500, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008090300) {
|
||||
|
||||
/// Define field sha1hash to be added to scorm
|
||||
$table = new xmldb_table('scorm');
|
||||
$field = new xmldb_field('sha1hash', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'updatefreq');
|
||||
|
||||
/// Launch add field sha1hash
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090300, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008090301) {
|
||||
|
||||
/// Define field revision to be added to scorm
|
||||
$table = new xmldb_table('scorm');
|
||||
$field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'md5hash');
|
||||
|
||||
/// Launch add field revision
|
||||
$dbman->add_field($table, $field);
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090301, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008090302) {
|
||||
$sql = "UPDATE {scorm}
|
||||
SET scormtype = 'external'
|
||||
WHERE reference LIKE ? OR reference LIKE ? OR reference LIKE ?";
|
||||
$DB->execute($sql, array('http://%imsmanifest.xml', 'https://%imsmanifest.xml', 'www.%imsmanifest.xml'));
|
||||
|
||||
$sql = "UPDATE {scorm}
|
||||
SET scormtype = 'localsync'
|
||||
WHERE reference LIKE ? OR reference LIKE ? OR reference LIKE ?
|
||||
OR reference LIKE ? OR reference LIKE ? OR reference LIKE ?";
|
||||
$DB->execute($sql, array('http://%.zip', 'https://%.zip', 'www.%.zip', 'http://%.pif', 'https://%.pif', 'www.%.pif'));
|
||||
|
||||
$sql = "UPDATE {scorm} SET scormtype = 'imsrepository' WHERE reference LIKE ?";
|
||||
$DB->execute($sql, array('#%'));
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090302, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008090303) {
|
||||
//remove obsoleted config settings
|
||||
unset_config('scorm_advancedsettings');
|
||||
unset_config('scorm_windowsettings');
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090303, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008090304) {
|
||||
/////////////////////////////////////
|
||||
/// new file storage upgrade code ///
|
||||
/////////////////////////////////////
|
||||
|
||||
require_once("$CFG->dirroot/mod/scorm/db/upgradelib.php");
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$sqlfrom = "FROM {scorm} s
|
||||
JOIN {modules} m ON m.name = 'scorm'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = s.id)";
|
||||
|
||||
$count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
|
||||
|
||||
$rs = $DB->get_recordset_sql("SELECT s.id, s.scormtype, s.reference, s.course, cm.id AS cmid $sqlfrom ORDER BY s.course, s.id");
|
||||
if ($rs->valid()) {
|
||||
|
||||
$pbar = new progress_bar('migratescormfiles', 500, true);
|
||||
|
||||
$i = 0;
|
||||
foreach ($rs as $scorm) {
|
||||
$i++;
|
||||
upgrade_set_timeout(180); // set up timeout, may also abort execution
|
||||
$pbar->update($i, $count, "Migrating scorm files - $i/$count.");
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $scorm->cmid);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $scorm->course);
|
||||
|
||||
if ($scorm->scormtype === 'local' and preg_match('/.*(\.zip|\.pif)$/i', $scorm->reference)) {
|
||||
// first copy local packages if found - do not delete in case they are shared ;-)
|
||||
$packagefile = clean_param($scorm->reference, PARAM_PATH);
|
||||
$pathnamehash = sha1("/$coursecontext->id/course/legacy/0/$packagefile");
|
||||
if ($file = $fs->get_file_by_hash($pathnamehash)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_scorm', 'filearea'=>'package',
|
||||
'itemid'=>0, 'filepath'=>'/');
|
||||
try {
|
||||
$fs->create_file_from_storedfile($file_record, $file);
|
||||
} catch (Exception $x) {
|
||||
// ignore any errors, we can not do much anyway
|
||||
}
|
||||
$scorm->reference = $file->get_filepath().$file->get_filename();
|
||||
|
||||
} else {
|
||||
$scorm->reference = '';
|
||||
}
|
||||
$DB->update_record('scorm', $scorm);
|
||||
// the package should be already extracted, we need to move the files there
|
||||
// just in case somebody modified it directly there
|
||||
scorm_migrate_moddata_files($scorm, $context);
|
||||
|
||||
} else if ($scorm->scormtype === 'local' and preg_match('/.*\/imsmanifest\.xml$/i', $scorm->reference)) {
|
||||
// ignore imsmanifest in course root because we would be duplicating all course files which is not acceptable
|
||||
// moddata dir is not used at all, ignore any rubbish there
|
||||
$manifest = clean_param($scorm->reference, PARAM_PATH);
|
||||
|
||||
$pathnamehash = sha1("/$coursecontext->id/course/legacy/0/$manifest");
|
||||
if ($file = $fs->get_file_by_hash($pathnamehash)) {
|
||||
$scorm->reference = $file->get_filepath().$file->get_filename();
|
||||
|
||||
$manifestdir = '/'.str_ireplace('/imsmanifest.xml', '', $manifest).'/';
|
||||
$pregmanifestdir = preg_quote($manifestdir, '/');
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_scorm', 'filearea'=>'content', 'itemid'=>0);
|
||||
if ($files = $fs->get_directory_files($coursecontext->id, 'course', 'legacy', 0, $manifestdir, true)) {
|
||||
foreach ($files as $file) {
|
||||
$file_record['filepath'] = preg_replace("/^$pregmanifestdir/", '/', $file->get_filepath());
|
||||
try {
|
||||
$fs->create_file_from_storedfile($file_record, $file);
|
||||
} catch (Exception $x) {
|
||||
// ignore any errors, we can not do much anyway
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$scorm->reference = '';
|
||||
}
|
||||
$DB->update_record('scorm', $scorm);
|
||||
|
||||
} else {
|
||||
// just try to migrate anything from moddata
|
||||
scorm_migrate_moddata_files($scorm, $context);
|
||||
}
|
||||
|
||||
// remove dirs if empty
|
||||
@rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/$scorm->id/");
|
||||
@rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/");
|
||||
@rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/");
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090304, 'scorm');
|
||||
}
|
||||
|
||||
|
||||
if ($oldversion < 2008090305) {
|
||||
|
||||
/// Define new fields forcecompleted, forcenewattempt, displayattemptstatus, and displaycoursestructure to be added to scorm
|
||||
$table = new xmldb_table('scorm');
|
||||
$field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'maxattempt');
|
||||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
$field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcecompleted');
|
||||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
$field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcenewattempt');
|
||||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
$field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'lastattemptlock');
|
||||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
$field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'displayattemptstatus');
|
||||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090305, 'scorm');
|
||||
}
|
||||
|
||||
|
||||
// remove redundant config values
|
||||
if ($oldversion < 2008090306) {
|
||||
/*
|
||||
* comment this out as it is handled by the update mark 2008090310 below
|
||||
* left for historical documentation as some early adopters may have done
|
||||
* this already.
|
||||
$redundant_config = array(
|
||||
'scorm_allowapidebug',
|
||||
'scorm_allowtypeexternal',
|
||||
'scorm_allowtypeimsrepository',
|
||||
'scorm_allowtypelocalsync',
|
||||
'scorm_apidebugmask',
|
||||
'scorm_frameheight',
|
||||
'scorm_framewidth',
|
||||
'scorm_maxattempts',
|
||||
'scorm_updatetime');
|
||||
foreach ($redundant_config as $rcfg) {
|
||||
if (isset($CFG->$rcfg)) {
|
||||
unset_config($rcfg);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090306, 'scorm');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// remove redundant config values
|
||||
if ($oldversion < 2008090307) {
|
||||
/*
|
||||
* comment this out as it is handled by the update mark 2008090310 below
|
||||
* left for historical documentation as some early adopters may have done
|
||||
* this already.
|
||||
$redundant_config = array(
|
||||
'scorm_allowapidebug',
|
||||
'scorm_allowtypeexternal',
|
||||
'scorm_allowtypeimsrepository',
|
||||
'scorm_allowtypelocalsync',
|
||||
'scorm_apidebugmask',
|
||||
'scorm_frameheight',
|
||||
'scorm_framewidth',
|
||||
'scorm_maxattempts',
|
||||
'scorm_updatetime',
|
||||
'scorm_resizable',
|
||||
'scorm_scrollbars',
|
||||
'scorm_directories',
|
||||
'scorm_location',
|
||||
'scorm_menubar',
|
||||
'scorm_toolbar',
|
||||
'scorm_status',
|
||||
'scorm_grademethod',
|
||||
'scorm_maxgrade',
|
||||
'scorm_whatgrade',
|
||||
'scorm_popup',
|
||||
'scorm_skipview',
|
||||
'scorm_hidebrowse',
|
||||
'scorm_hidetoc',
|
||||
'scorm_hidenav',
|
||||
'scorm_auto',
|
||||
'scorm_updatefreq'
|
||||
);
|
||||
foreach ($redundant_config as $rcfg) {
|
||||
if (isset($CFG->$rcfg)) {
|
||||
unset_config($rcfg);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090307, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2008090308) {
|
||||
$table = new xmldb_table('scorm');
|
||||
$field = new xmldb_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'height');
|
||||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
$field = new xmldb_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeopen');
|
||||
if (!$dbman->field_exists($table,$field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090308, 'scorm');
|
||||
}
|
||||
|
||||
|
||||
if ($oldversion < 2008090310) {
|
||||
// take above blocks that delete config and move the values in to config_plugins
|
||||
|
||||
$redundant_config = array(
|
||||
'scorm_allowapidebug',
|
||||
'scorm_allowtypeexternal',
|
||||
'scorm_allowtypeimsrepository',
|
||||
'scorm_allowtypelocalsync',
|
||||
'scorm_apidebugmask',
|
||||
'scorm_frameheight',
|
||||
'scorm_framewidth',
|
||||
'scorm_maxattempts',
|
||||
'scorm_updatetime',
|
||||
'scorm_resizable',
|
||||
'scorm_scrollbars',
|
||||
'scorm_directories',
|
||||
'scorm_location',
|
||||
'scorm_menubar',
|
||||
'scorm_toolbar',
|
||||
'scorm_status',
|
||||
'scorm_grademethod',
|
||||
'scorm_maxgrade',
|
||||
'scorm_whatgrade',
|
||||
'scorm_popup',
|
||||
'scorm_skipview',
|
||||
'scorm_hidebrowse',
|
||||
'scorm_hidetoc',
|
||||
'scorm_hidenav',
|
||||
'scorm_auto',
|
||||
'scorm_updatefreq',
|
||||
'scorm_displayattemptstatus',
|
||||
'scorm_displaycoursestructure',
|
||||
'scorm_forcecompleted',
|
||||
'scorm_forcenewattempt',
|
||||
'scorm_lastattemptlock'
|
||||
);
|
||||
|
||||
foreach ($redundant_config as $rcfg) {
|
||||
if (isset($CFG->$rcfg)) {
|
||||
$shortname = substr($rcfg, 6);
|
||||
set_config($shortname, $CFG->$rcfg, 'scorm');
|
||||
unset_config($rcfg);
|
||||
}
|
||||
}
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2008090310, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042000) {
|
||||
|
||||
/// Rename field summary on table scorm to intro
|
||||
$table = new xmldb_table('scorm');
|
||||
$field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'reference');
|
||||
|
||||
/// Launch rename field summary
|
||||
$dbman->rename_field($table, $field, 'intro');
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042000, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042001) {
|
||||
|
||||
/// Define field introformat to be added to scorm
|
||||
$table = new xmldb_table('scorm');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Launch add field introformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('scorm', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
|
||||
foreach ($rs as $s) {
|
||||
$s->intro = text_to_html($s->intro, false, false, true);
|
||||
$s->introformat = FORMAT_HTML;
|
||||
$DB->update_record('scorm', $s);
|
||||
upgrade_set_timeout();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042001, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2009042002) {
|
||||
|
||||
/// Define field introformat to be added to scorm
|
||||
$table = new xmldb_table('scorm_scoes');
|
||||
$field = new xmldb_field('launch', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
|
||||
|
||||
/// Launch add field introformat
|
||||
$dbman->change_field_type($table, $field);
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042002, 'scorm');
|
||||
}
|
||||
if ($oldversion < 2010070800) {
|
||||
//check to see if this has already been tidied up by a 1.9 upgrade.
|
||||
$grademethodfixed = get_config('scorm', 'grademethodfixed');
|
||||
if (empty($grademethodfixed)) {
|
||||
/// fix bad usage of whatgrade/grading method.
|
||||
$scorms = $DB->get_records('scorm');
|
||||
if (!empty($scorm)) {
|
||||
foreach ($scorms as $scorm) {
|
||||
$scorm->grademethod = $scorm->grademethod%10;
|
||||
$DB->update_record('scorm', $scorm);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//dump this config var as it isn't needed anymore.
|
||||
unset_config('grademethodfixed', 'scorm');
|
||||
}
|
||||
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010070800, 'scorm');
|
||||
}
|
||||
if ($oldversion < 2010092400) {
|
||||
$count = $DB->count_records('scorm', array('scormtype'=>'external'));
|
||||
if (!empty($count)) {
|
||||
set_config('allowtypeexternal', '1', 'scorm');
|
||||
}
|
||||
$count = $DB->count_records('scorm', array('scormtype'=>'localsync'));
|
||||
if (!empty($count)) {
|
||||
set_config('allowtypelocalsync', '1', 'scorm');
|
||||
}
|
||||
$count = $DB->count_records('scorm', array('scormtype'=>'imsrepository'));
|
||||
if (!empty($count)) {
|
||||
set_config('allowtypeimsrepository', '1', 'scorm');
|
||||
}
|
||||
/// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010092400, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2011011400) {
|
||||
// Fix scorm in the post table after upgrade from 1.9
|
||||
$table = new xmldb_table('scorm');
|
||||
$columns = $DB->get_columns('scorm');
|
||||
|
||||
// forcecompleted should be int(1) not null default 1
|
||||
// Changing to NOT NULL, let's fill the current nulls with default 1
|
||||
$DB->set_field('scorm', 'forcecompleted', 1, array('forcecompleted' => null));
|
||||
$field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'maxattempt');
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->change_field_precision($table, $field);
|
||||
}
|
||||
|
||||
if (array_key_exists('forcenewattempt', $columns) && empty($columns['forcenewattempt']->not_null)) {
|
||||
// forcenewattempt should be int(1) not null default 0
|
||||
// Changing to NOT NULL, let's fill the current nulls with default 0
|
||||
$DB->set_field('scorm', 'forcenewattempt', 0, array('forcenewattempt' => null));
|
||||
$field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcecompleted');
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('lastattemptlock', $columns) && empty($columns['lastattemptlock']->not_null)) {
|
||||
// lastattemptlock should be int(1) not null default 0
|
||||
// Changing to NOT NULL, let's fill the current nulls with default 0
|
||||
$DB->set_field('scorm', 'lastattemptlock', 0, array('lastattemptlock' => null));
|
||||
$field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcenewattempt');
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('displayattemptstatus', $columns) && empty($columns['displayattemptstatus']->not_null)) {
|
||||
// displayattemptstatus should be int(1) not null default 1
|
||||
// Changing to NOT NULL, let's fill the current nulls with default 1
|
||||
$DB->set_field('scorm', 'displayattemptstatus', 1, array('displayattemptstatus' => null));
|
||||
$field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'lastattemptlock');
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('displaycoursestructure', $columns) && empty($columns['displaycoursestructure']->not_null)) {
|
||||
// displaycoursestructure should be int(1) not null default 1
|
||||
// Changing to NOT NULL, let's fill the current nulls with default 1
|
||||
$DB->set_field('scorm', 'displaycoursestructure', 1, array('displaycoursestructure' => null));
|
||||
$field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'displayattemptstatus');
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
}
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2011011400, 'scorm');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
if ($oldversion < 2011021402) {
|
||||
unset_config('updatetime', 'scorm');
|
||||
upgrade_mod_savepoint(true, 2011021402, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2011073100) {
|
||||
// change field type of objectiveid
|
||||
$table = new xmldb_table('scorm_seq_objective');
|
||||
$field = new xmldb_field('objectiveid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'primaryobj');
|
||||
$dbman->change_field_type($table, $field);
|
||||
upgrade_mod_savepoint(true, 2011073100, 'scorm');
|
||||
}
|
||||
|
||||
if ($oldversion < 2011080100) {
|
||||
//MDL-28295 the behaviour of pop-up windows has now changed - it now loads the full Player in the window
|
||||
//because of this, pop-up windows now include the TOC and the nav bar - disabling these for existing SCORMS
|
||||
//as it is a change that most users won't expect.
|
||||
//get all SCORMS that use a new window.
|
||||
require_once($CFG->dirroot."/mod/scorm/lib.php");
|
||||
$rs = $DB->get_recordset('scorm', array('popup' => 1), '', 'id,hidetoc,hidenav');
|
||||
foreach ($rs as $scorm) {
|
||||
$scorm->hidetoc = SCORM_TOC_DISABLED;
|
||||
$scorm->hidenav = 1;
|
||||
$DB->update_record('scorm', $scorm);
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2011080100, 'scorm');
|
||||
}
|
||||
if ($oldversion < 2011110502) {
|
||||
|
||||
// Define table scorm_aicc_session to be created
|
||||
$table = new xmldb_table('scorm_aicc_session');
|
||||
|
||||
// Adding fields to table scorm_aicc_session
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('scormid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('hacpsession', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('scormmode', XMLDB_TYPE_CHAR, '50', null, null, null, null);
|
||||
$table->add_field('scormstatus', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
$table->add_field('attempt', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('lessonstatus', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
$table->add_field('sessiontime', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
// Adding keys to table scorm_aicc_session
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('scormid', XMLDB_KEY_FOREIGN, array('scormid'), 'scorm', array('id'));
|
||||
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
|
||||
|
||||
// Conditionally launch create table for scorm_aicc_session
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// scorm savepoint reached
|
||||
upgrade_mod_savepoint(true, 2011110502, 'scorm');
|
||||
}
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Resource module upgrade related helper functions
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage scorm
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Migrate extracted scorm package from moddata to new area if found
|
||||
* @param stdClass $scorm
|
||||
* @return
|
||||
*/
|
||||
function scorm_migrate_moddata_files($scorm, $context) {
|
||||
global $CFG;
|
||||
|
||||
// now migrate the extracted package
|
||||
$basepath = "$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/$scorm->id";
|
||||
if (!is_dir($basepath)) {
|
||||
//no files?
|
||||
return;
|
||||
}
|
||||
|
||||
scorm_migrate_moddata_subdir($context, $basepath, '/');
|
||||
}
|
||||
/**
|
||||
* Migrates physical scorm package files to proper new file area files
|
||||
* @param stdClass $context
|
||||
* @param string $base
|
||||
* @param string $path
|
||||
* @return void
|
||||
*/
|
||||
function scorm_migrate_moddata_subdir($context, $base, $path) {
|
||||
global $OUTPUT;
|
||||
|
||||
$fullpathname = $base.$path;
|
||||
$fs = get_file_storage();
|
||||
$filearea = 'content';
|
||||
$items = new DirectoryIterator($fullpathname);
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->isDot()) {
|
||||
unset($item); // release file handle
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item->isLink()) {
|
||||
// do not follow symlinks - they were never supported in moddata, sorry
|
||||
unset($item); // release file handle
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item->isFile()) {
|
||||
if (!$item->isReadable()) {
|
||||
echo $OUTPUT->notification(" File not readable, skipping: ".$fullpathname.$item->getFilename());
|
||||
unset($item); // release file handle
|
||||
continue;
|
||||
}
|
||||
|
||||
$filepath = clean_param($path, PARAM_PATH);
|
||||
$filename = clean_param($item->getFilename(), PARAM_FILE);
|
||||
$oldpathname = $fullpathname.$item->getFilename();
|
||||
|
||||
if ($filename === '') {
|
||||
continue;
|
||||
unset($item); // release file handle
|
||||
}
|
||||
|
||||
if (!$fs->file_exists($context->id, 'mod_scorm', $filearea, '0', $filepath, $filename)) {
|
||||
$file_record = array('contextid'=>$context->id, 'component'=>'mod_scorm', 'filearea'=>$filearea, 'itemid'=>0, 'filepath'=>$filepath, 'filename'=>$filename,
|
||||
'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime());
|
||||
unset($item); // release file handle
|
||||
if ($fs->create_file_from_pathname($file_record, $oldpathname)) {
|
||||
@unlink($oldpathname);
|
||||
}
|
||||
} else {
|
||||
unset($item); // release file handle
|
||||
}
|
||||
|
||||
} else {
|
||||
//migrate recursively all subdirectories
|
||||
$oldpathname = $fullpathname.$item->getFilename().'/';
|
||||
$subpath = $path.$item->getFilename().'/';
|
||||
unset($item); // release file handle
|
||||
scorm_migrate_moddata_subdir($context, $base, $subpath);
|
||||
@rmdir($oldpathname); // deletes dir if empty
|
||||
}
|
||||
}
|
||||
unset($items); //release file handles
|
||||
}
|
||||
@@ -25,37 +25,6 @@ function xmldb_survey_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
if ($oldversion < 2009042002) {
|
||||
|
||||
/// Define field introformat to be added to survey
|
||||
$table = new xmldb_table('survey');
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
|
||||
|
||||
/// Conditionally launch add field introformat
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// conditionally migrate to html format in intro
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$rs = $DB->get_recordset('survey', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
|
||||
foreach ($rs as $s) {
|
||||
$s->intro = text_to_html($s->intro, false, false, true);
|
||||
$s->introformat = FORMAT_HTML;
|
||||
$DB->update_record('survey', $s);
|
||||
upgrade_set_timeout();
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/// survey savepoint reached
|
||||
upgrade_mod_savepoint(true, 2009042002, 'survey');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -34,21 +34,4 @@ defined('MOODLE_INTERNAL') || die;
|
||||
function xmldb_url_install() {
|
||||
global $CFG;
|
||||
|
||||
// migrate settings if present
|
||||
if (!empty($CFG->resource_secretphrase)) {
|
||||
set_config('secretphrase', $CFG->resource_secretphrase, 'url');
|
||||
}
|
||||
unset_config('resource_secretphrase');
|
||||
|
||||
// Upgrade from old resource module type if needed
|
||||
require_once("$CFG->dirroot/mod/url/db/upgradelib.php");
|
||||
url_20_migrate();
|
||||
}
|
||||
|
||||
function xmldb_url_install_recovery() {
|
||||
global $CFG;
|
||||
|
||||
// Upgrade from old resource module type if needed
|
||||
require_once("$CFG->dirroot/mod/url/db/upgradelib.php");
|
||||
url_20_migrate();
|
||||
}
|
||||
|
||||
@@ -51,22 +51,6 @@ function xmldb_url_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
if ($oldversion < 2011092800) {
|
||||
|
||||
// Changing nullability of field externalurl on table urls to not-null
|
||||
$table = new xmldb_table('url');
|
||||
$field = new xmldb_field('externalurl', XMLDB_TYPE_TEXT, 'small', null,
|
||||
XMLDB_NOTNULL, null, null, 'introformat');
|
||||
|
||||
$DB->set_field_select('url', 'externalurl', $DB->sql_empty(), 'externalurl IS NULL');
|
||||
// Launch change of nullability for field =externalurl
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
|
||||
// url savepoint reached
|
||||
upgrade_mod_savepoint(true, 2011092800, 'url');
|
||||
}
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* URL module upgrade related helper functions
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage url
|
||||
* @copyright 2009 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Migrate url module data from 1.9 resource_old table to new url table
|
||||
* @return void
|
||||
*/
|
||||
function url_20_migrate() {
|
||||
global $CFG, $DB;
|
||||
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
require_once("$CFG->libdir/resourcelib.php");
|
||||
require_once("$CFG->dirroot/course/lib.php");
|
||||
|
||||
if (!file_exists("$CFG->dirroot/mod/resource/db/upgradelib.php")) {
|
||||
// bad luck, somebody deleted resource module
|
||||
return;
|
||||
}
|
||||
|
||||
require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
|
||||
|
||||
// create resource_old table and copy resource table there if needed
|
||||
if (!resource_20_prepare_migration()) {
|
||||
// no modules or fresh install
|
||||
return;
|
||||
}
|
||||
|
||||
$candidates = $DB->get_recordset('resource_old', array('type'=>'file', 'migrated'=>0));
|
||||
if (!$candidates->valid()) {
|
||||
$candidates->close(); // Not going to iterate (but exit), close rs
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
$path = $candidate->reference;
|
||||
$siteid = get_site()->id;
|
||||
|
||||
if (strpos($path, 'LOCALPATH') === 0) {
|
||||
// ignore not maintained local files - sorry
|
||||
continue;
|
||||
} else if (!strpos($path, '://')) {
|
||||
// not URL
|
||||
continue;
|
||||
} else if (preg_match("|$CFG->wwwroot/file.php(\?file=)?/$siteid(/[^\s'\"&\?#]+)|", $path, $matches)) {
|
||||
// handled by resource module
|
||||
continue;
|
||||
} else if (preg_match("|$CFG->wwwroot/file.php(\?file=)?/$candidate->course(/[^\s'\"&\?#]+)|", $path, $matches)) {
|
||||
// handled by resource module
|
||||
continue;
|
||||
}
|
||||
|
||||
upgrade_set_timeout();
|
||||
|
||||
if ($CFG->texteditors !== 'textarea') {
|
||||
$intro = text_to_html($candidate->intro, false, false, true);
|
||||
$introformat = FORMAT_HTML;
|
||||
} else {
|
||||
$intro = $candidate->intro;
|
||||
$introformat = FORMAT_MOODLE;
|
||||
}
|
||||
|
||||
$url = new stdClass();
|
||||
$url->course = $candidate->course;
|
||||
$url->name = $candidate->name;
|
||||
$url->intro = $intro;
|
||||
$url->introformat = $introformat;
|
||||
$url->externalurl = $path;
|
||||
$url->timemodified = time();
|
||||
|
||||
$options = array('printheading'=>0, 'printintro'=>1);
|
||||
$parameters = array();
|
||||
if ($candidate->options == 'frame') {
|
||||
$url->display = RESOURCELIB_DISPLAY_FRAME;
|
||||
|
||||
} else if ($candidate->options == 'objectframe') {
|
||||
$url->display = RESOURCELIB_DISPLAY_EMBED;
|
||||
|
||||
} else if ($candidate->popup) {
|
||||
$url->display = RESOURCELIB_DISPLAY_POPUP;
|
||||
if ($candidate->popup) {
|
||||
$rawoptions = explode(',', $candidate->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 {
|
||||
$url->display = RESOURCELIB_DISPLAY_AUTO;
|
||||
}
|
||||
$url->displayoptions = serialize($options);
|
||||
|
||||
if ($candidate->alltext) {
|
||||
$rawoptions = explode(',', $candidate->alltext);
|
||||
foreach ($rawoptions as $rawoption) {
|
||||
list($variable, $parameter) = explode('=', trim($rawoption), 2);
|
||||
$parameters[$parameter] = $variable;
|
||||
}
|
||||
}
|
||||
|
||||
$url->parameters = serialize($parameters);
|
||||
|
||||
if (!$url = resource_migrate_to_module('url', $candidate, $url)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$candidates->close();
|
||||
|
||||
// clear all course modinfo caches
|
||||
rebuild_course_cache(0, true);
|
||||
}
|
||||
@@ -3,6 +3,4 @@
|
||||
function xmldb_wiki_install() {
|
||||
global $DB;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,582 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* convert ewiki format text to html format
|
||||
*
|
||||
* @param object $oldentry wiki entry object
|
||||
* @param object $oldpage wiki page object
|
||||
* @param object $oldwiki wiki instance object
|
||||
* @return string html format wiki content
|
||||
*/
|
||||
function wiki_ewiki_2_html($oldentry, $oldpage, $oldwiki) {
|
||||
global $CFG, $wiki_entry, $moodle_disable_camel_case, $ewiki_plugins, $ewiki_config, $moodle_format;
|
||||
|
||||
$wiki_entry = $oldentry;
|
||||
|
||||
$moodle_disable_camel_case = ($oldwiki->disablecamelcase == 1);
|
||||
|
||||
// Block of dinamic ewiki defines
|
||||
wiki_set_define("EWIKI_NAME", $wiki_entry->pagename);
|
||||
wiki_set_define("EWIKI_DEFAULT_LANG", current_language());
|
||||
if ($moodle_disable_camel_case) {
|
||||
wiki_set_define("EWIKI_CHARS_L", "");
|
||||
wiki_set_define("EWIKI_CHARS_U", "");
|
||||
} else {
|
||||
wiki_set_define("EWIKI_CHARS_L", "a-z_µ¤$\337-\377");
|
||||
wiki_set_define("EWIKI_CHARS_U", "A-Z0-9\300-\336");
|
||||
}
|
||||
|
||||
wiki_set_define("EWIKI_CHARS", wiki_get_define('EWIKI_CHARS_L') . wiki_get_define('EWIKI_CHARS_U'));
|
||||
|
||||
require_once($CFG->dirroot . '/mod/wiki/db/migration/wiki/ewikimoodlelib.php');
|
||||
require_once($CFG->dirroot . '/mod/wiki/db/migration/wiki/ewiki/ewiki.php');
|
||||
|
||||
if ($oldwiki->htmlmode == 0) {
|
||||
# No HTML
|
||||
$ewiki_config["htmlentities"] = array(); // HTML is managed by moodle
|
||||
$moodle_format = FORMAT_TEXT;
|
||||
}
|
||||
if ($oldwiki->htmlmode == 1) {
|
||||
# Safe HTML
|
||||
include_once($CFG->dirroot . "/mod/wiki/db/migration/wiki/ewiki/plugins/moodle/moodle_rescue_html.php");
|
||||
$moodle_format = FORMAT_HTML;
|
||||
}
|
||||
if ($oldwiki->htmlmode == 2) {
|
||||
# HTML Only
|
||||
$moodle_format = FORMAT_HTML;
|
||||
$ewiki_use_editor = 1;
|
||||
$ewiki_config["htmlentities"] = array(); // HTML is allowed
|
||||
$ewiki_config["wiki_link_regex"] = "\007 [!~]?(
|
||||
\#?\[[^<>\[\]\n]+\] |
|
||||
\^[-" .
|
||||
wiki_get_define('EWIKI_CHARS_U') . wiki_get_define('EWIKI_CHARS_L') . "]{3,} |
|
||||
\b([\w]{3,}:)*([" .
|
||||
wiki_get_define('EWIKI_CHARS_U') . "]+[" . wiki_get_define('EWIKI_CHARS_L') . "]+){2,}\#?[\w\d]* |
|
||||
\w[-_.+\w]+@(\w[-_\w]+[.])+\w{2,} ) \007x";
|
||||
}
|
||||
|
||||
$content = ewiki_format($oldpage->content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
function wiki_set_define($key, $value) {
|
||||
global $ewikidefines;
|
||||
|
||||
$ewikidefines[$key] = $value;
|
||||
}
|
||||
|
||||
function wiki_get_define($key) {
|
||||
global $ewikidefines;
|
||||
|
||||
return $ewikidefines[$key];
|
||||
}
|
||||
|
||||
function ewiki_mime_magic($binary_data) {
|
||||
$mime_magic_data = array(
|
||||
array(0, 2, 0, "\x06\x02", "application/x-alan-adventure-game"),
|
||||
array(0, 4, 0, "TADS", "application/x-tads-game"),
|
||||
array(0, 2, 0, "\x01\x10", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01\x11", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01", "application/x-executable-file"),
|
||||
array(0, 5, 0, "Core\001", "application/x-executable-file"),
|
||||
array(0, 22, 0, "AMANDA: TAPESTART DATE", "application/x-amanda-header"),
|
||||
array(0, 2, 0xfff0, 0xf0ff, "audio/mpeg"),
|
||||
array(4, 2, 0, "¯\x11", "video/fli"),
|
||||
array(4, 2, 0, "¯\x12", "video/flc"),
|
||||
array(0, 4, 0, "MOVI", "video/x-sgi-movie"),
|
||||
array(4, 4, 0, "moov", "video/quicktime"),
|
||||
array(4, 4, 0, "mdat", "video/quicktime"),
|
||||
array(0, 18, 0, "FiLeStArTfIlEsTaRt", "text/x-apple-binscii"),
|
||||
array(0, 3, 0, "\x0aGL", "application/data"),
|
||||
array(0, 2, 0, "\x76\xff", "application/data"),
|
||||
array(0, 6, 0, "NuFile", "application/data"),
|
||||
array(0, 6, 0, "N\xf5F\xe9l\xe5", "application/data"),
|
||||
array(0, 4, 0, "\x00\x16\x05\x00", "application/data"),
|
||||
array(0, 4, 0, "\x07\x16\x05\x00", "application/data"),
|
||||
array(257, 6, 0, "ustar\0", "application/x-tar"),
|
||||
array(257, 8, 0, "ustar\040\040\0", "application/x-gtar"),
|
||||
array(0, 2, 0, "qÇ", "application/x-cpio"),
|
||||
array(0, 2, 0, "Çq", "application/x-bcpio"),
|
||||
array(0, 6, 0, "070707", "application/x-cpio"),
|
||||
array(0, 6, 0, "070701", "application/x-cpio"),
|
||||
array(0, 6, 0, "070702", "application/x-cpio"),
|
||||
array(0, 2, 0, "ÿm", "application/data"),
|
||||
array(0, 2, 0, "ÿe", "application/data"),
|
||||
array(0, 5, 0, "=<ar>", "application/x-ar"),
|
||||
array(0, 19, 0, "!<arch>\n__________E", "application/x-ar"),
|
||||
array(0, 3, 0, "-h-", "application/data"),
|
||||
array(0, 7, 0, "!<arch>", "application/x-ar"),
|
||||
array(0, 4, 0, "<ar>", "application/x-ar"),
|
||||
array(0, 4, 0, ">ra<", "application/x-ar"),
|
||||
array(0, 4, 0, "!<ar", "application/x-ar"),
|
||||
array(0, 4, 0, "\x00\x03í", "application/data"),
|
||||
array(0, 4, 0, "\x00\x03î", "application/data"),
|
||||
array(0, 4, 0x8080ffff, 0x81a, "application/x-arc"),
|
||||
array(0, 4, 0x8080ffff, 0x91a, "application/x-arc"),
|
||||
array(0, 4, 0x8080ffff, 0x21a, "application/x-arc"),
|
||||
array(0, 4, 0x8080ffff, 0x31a, "application/x-arc"),
|
||||
array(0, 4, 0x8080ffff, 0x41a, "application/x-arc"),
|
||||
array(0, 4, 0x8080ffff, 0x61a, "application/x-arc"),
|
||||
array(0, 8, 0, "\032archive", "application/data"),
|
||||
array(0, 2, 0, "ê`", "application/x-arj"),
|
||||
array(0, 4, 0, "HPAK", "application/data"),
|
||||
array(0, 8, 0, "\351,\001JAM\ ", "application/data"),
|
||||
array(2, 5, 0, "-lh0-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lh1-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lz4-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lz5-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lzs-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lh\40-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lhd-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lh2-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lh3-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lh4-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lh5-", "application/x-lha"),
|
||||
array(0, 4, 0, "Rar!", "application/x-rar"),
|
||||
array(0, 4, 0, "SQSH", "application/data"),
|
||||
array(0, 4, 0, "UC2\x1a", "application/data"),
|
||||
array(0, 4, 0, "PK\003\004", "application/zip"),
|
||||
array(20, 4, 0, "ýħÜ", "application/x-zoo"),
|
||||
array(10, 25, 0, "# This is a shell archive", "application/x-shar"),
|
||||
array(0, 4, 0, "*STA", "application/data"),
|
||||
array(0, 4, 0, "2278", "application/data"),
|
||||
array(0, 2, 0, "p\x01", "application/x-executable-file"),
|
||||
array(0, 2, 0, "q\x01", "application/x-executable-file"),
|
||||
array(0, 5, 0, "\000\004\036\212\200", "application/core"),
|
||||
array(0, 4, 0, ".snd", "audio/basic"),
|
||||
array(0, 4, 0, "\x00ds.", "audio/basic"),
|
||||
array(0, 4, 0, "MThd", "audio/midi"),
|
||||
array(0, 4, 0, "CTMF", "audio/x-cmf"),
|
||||
array(0, 3, 0, "SBI", "audio/x-sbi"),
|
||||
array(0, 19, 0, "Creative Voice File", "audio/x-voc"),
|
||||
array(0, 4, 0, "KRTN", "audio/x-multitrack"),
|
||||
array(0, 4, 0, "RIFF", "audio/x-wav"),
|
||||
array(0, 4, 0, "EMOD", "audio/x-emod"),
|
||||
array(0, 4, 0, "ýar.", "audio/x-pn-realaudio"),
|
||||
array(0, 3, 0, "MTM", "audio/x-multitrack"),
|
||||
array(0, 2, 0, "if", "audio/x-669-mod"),
|
||||
array(0, 3, 0, "FAR", "audio/mod"),
|
||||
array(0, 5, 0, "MAS_U", "audio/x-multimate-mod"),
|
||||
array(0x2c, 4, 0, "SCRM", "audio/x-st3-mod"),
|
||||
array(0, 22, 0, "GF1PATCH110\0ID#000002\0", "audio/x-gus-patch"),
|
||||
array(0, 22, 0, "GF1PATCH100\0ID#000002\0", "audio/x-gus-patch"),
|
||||
array(0, 2, 0, "JN", "audio/x-669-mod"),
|
||||
array(0, 4, 0, "UN05", "audio/x-mikmod-uni"),
|
||||
array(21, 8, 0, "!SCREAM!", "audio/x-st2-mod"),
|
||||
array(1080, 4, 0, "M.K.", "audio/x-protracker-mod"),
|
||||
array(1080, 4, 0, "M!K!", "audio/x-protracker-mod"),
|
||||
array(1080, 4, 0, "FLT4", "audio/x-startracker-mod"),
|
||||
array(1080, 4, 0, "4CHN", "audio/x-fasttracker-mod"),
|
||||
array(1080, 4, 0, "6CHN", "audio/x-fasttracker-mod"),
|
||||
array(1080, 4, 0, "8CHN", "audio/x-fasttracker-mod"),
|
||||
array(1080, 4, 0, "CD81", "audio/x-oktalyzer-mod"),
|
||||
array(1080, 4, 0, "OKTA", "audio/x-oktalyzer-mod"),
|
||||
array(1080, 4, 0, "16CN", "audio/x-taketracker-mod"),
|
||||
array(1080, 4, 0, "32CN", "audio/x-taketracker-mod"),
|
||||
array(0, 3, 0, "TOC", "audio/x-toc"),
|
||||
array(0, 2, 0, "\x07\x01", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01\x06", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x06\x01", "application/x-executable-file"),
|
||||
array(0, 2, 0, "//", "text/cpp"),
|
||||
array(0, 5, 0, "\\1cw ", "application/data"),
|
||||
array(0, 4, 0, "\\1cw", "application/data"),
|
||||
array(0, 4, 0xffffff00, 0x140185, "application/data"),
|
||||
array(0, 4, 0xffffff00, 0xcb0185, "application/data"),
|
||||
array(0, 2, 0, "\x01}", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01", "application/x-executable-file"),
|
||||
array(4, 4, 0, "pipe", "application/data"),
|
||||
array(4, 4, 0, "prof", "application/data"),
|
||||
array(0, 9, 0, "#!/bin/sh", "application/x-sh"),
|
||||
array(0, 10, 0, "#! /bin/sh", "application/x-sh"),
|
||||
array(0, 11, 0, "#!\ /bin/sh", "application/x-sh"),
|
||||
array(0, 10, 0, "#!/bin/csh", "application/x-csh"),
|
||||
array(0, 11, 0, "#! /bin/csh", "application/x-csh"),
|
||||
array(0, 12, 0, "#!\ /bin/csh", "application/x-csh"),
|
||||
array(0, 10, 0, "#!/bin/ksh", "application/x-ksh"),
|
||||
array(0, 11, 0, "#! /bin/ksh", "application/x-ksh"),
|
||||
array(0, 12, 0, "#!\ /bin/ksh", "application/x-ksh"),
|
||||
array(0, 17, 0, "#!/usr/local/tcsh", "application/x-csh"),
|
||||
array(0, 21, 0, "#!/usr/local/bin/tcsh", "application/x-csh"),
|
||||
array(0, 22, 0, "#! /usr/local/bin/tcsh", "application/x-csh"),
|
||||
array(0, 23, 0, "#!\ /usr/local/bin/tcsh", "application/x-csh"),
|
||||
array(0, 20, 0, "#!/usr/local/bin/zsh", "application/x-zsh"),
|
||||
array(0, 21, 0, "#! /usr/local/bin/zsh", "application/x-zsh"),
|
||||
array(0, 22, 0, "#!\ /usr/local/bin/zsh", "application/x-zsh"),
|
||||
array(0, 20, 0, "#!/usr/local/bin/ash", "application/x-sh"),
|
||||
array(0, 21, 0, "#! /usr/local/bin/ash", "application/x-zsh"),
|
||||
array(0, 22, 0, "#!\ /usr/local/bin/ash", "application/x-zsh"),
|
||||
array(0, 19, 0, "#!/usr/local/bin/ae", "text/script"),
|
||||
array(0, 20, 0, "#! /usr/local/bin/ae", "text/script"),
|
||||
array(0, 21, 0, "#!\ /usr/local/bin/ae", "text/script"),
|
||||
array(0, 11, 0, "#!/bin/nawk", "application/x-awk"),
|
||||
array(0, 12, 0, "#! /bin/nawk", "application/x-awk"),
|
||||
array(0, 13, 0, "#!\ /bin/nawk", "application/x-awk"),
|
||||
array(0, 15, 0, "#!/usr/bin/nawk", "application/x-awk"),
|
||||
array(0, 16, 0, "#! /usr/bin/nawk", "application/x-awk"),
|
||||
array(0, 17, 0, "#!\ /usr/bin/nawk", "application/x-awk"),
|
||||
array(0, 21, 0, "#!/usr/local/bin/nawk", "application/x-awk"),
|
||||
array(0, 22, 0, "#! /usr/local/bin/nawk", "application/x-awk"),
|
||||
array(0, 23, 0, "#!\ /usr/local/bin/nawk", "application/x-awk"),
|
||||
array(0, 11, 0, "#!/bin/gawk", "application/x-awk"),
|
||||
array(0, 12, 0, "#! /bin/gawk", "application/x-awk"),
|
||||
array(0, 13, 0, "#!\ /bin/gawk", "application/x-awk"),
|
||||
array(0, 15, 0, "#!/usr/bin/gawk", "application/x-awk"),
|
||||
array(0, 16, 0, "#! /usr/bin/gawk", "application/x-awk"),
|
||||
array(0, 17, 0, "#!\ /usr/bin/gawk", "application/x-awk"),
|
||||
array(0, 21, 0, "#!/usr/local/bin/gawk", "application/x-awk"),
|
||||
array(0, 22, 0, "#! /usr/local/bin/gawk", "application/x-awk"),
|
||||
array(0, 23, 0, "#!\ /usr/local/bin/gawk", "application/x-awk"),
|
||||
array(0, 10, 0, "#!/bin/awk", "application/x-awk"),
|
||||
array(0, 11, 0, "#! /bin/awk", "application/x-awk"),
|
||||
array(0, 12, 0, "#!\ /bin/awk", "application/x-awk"),
|
||||
array(0, 14, 0, "#!/usr/bin/awk", "application/x-awk"),
|
||||
array(0, 15, 0, "#! /usr/bin/awk", "application/x-awk"),
|
||||
array(0, 16, 0, "#!\ /usr/bin/awk", "application/x-awk"),
|
||||
array(0, 5, 0, "BEGIN", "application/x-awk"),
|
||||
array(0, 11, 0, "#!/bin/perl", "application/x-perl"),
|
||||
array(0, 12, 0, "#! /bin/perl", "application/x-perl"),
|
||||
array(0, 13, 0, "#!\ /bin/perl", "application/x-perl"),
|
||||
array(0, 20, 0, "eval \"exec /bin/perl", "application/x-perl"),
|
||||
array(0, 15, 0, "#!/usr/bin/perl", "application/x-perl"),
|
||||
array(0, 16, 0, "#! /usr/bin/perl", "application/x-perl"),
|
||||
array(0, 17, 0, "#!\ /usr/bin/perl", "application/x-perl"),
|
||||
array(0, 24, 0, "eval \"exec /usr/bin/perl", "application/x-perl"),
|
||||
array(0, 21, 0, "#!/usr/local/bin/perl", "application/x-perl"),
|
||||
array(0, 22, 0, "#! /usr/local/bin/perl", "application/x-perl"),
|
||||
array(0, 23, 0, "#!\ /usr/local/bin/perl", "application/x-perl"),
|
||||
array(0, 30, 0, "eval \"exec /usr/local/bin/perl", "application/x-perl"),
|
||||
array(0, 9, 0, "#!/bin/rc", "text/script"),
|
||||
array(0, 10, 0, "#! /bin/rc", "text/script"),
|
||||
array(0, 11, 0, "#!\ /bin/rc", "text/script"),
|
||||
array(0, 11, 0, "#!/bin/bash", "application/x-sh"),
|
||||
array(0, 12, 0, "#! /bin/bash", "application/x-sh"),
|
||||
array(0, 13, 0, "#!\ /bin/bash", "application/x-sh"),
|
||||
array(0, 21, 0, "#!/usr/local/bin/bash", "application/x-sh"),
|
||||
array(0, 22, 0, "#! /usr/local/bin/bash", "application/x-sh"),
|
||||
array(0, 23, 0, "#!\ /usr/local/bin/bash", "application/x-sh"),
|
||||
array(0, 4, 0, "#! /", "text/script"),
|
||||
array(0, 5, 0, "#!\ /", "text/script"),
|
||||
array(0, 3, 0, "#!/", "text/script"),
|
||||
array(0, 3, 0, "#! ", "text/script"),
|
||||
array(0, 2, 0, "\037\235", "application/compress"),
|
||||
array(0, 2, 0, "\037\213", "application/x-gzip"),
|
||||
array(0, 2, 0, "\037\036", "application/data"),
|
||||
array(0, 2, 0, "\x1f\x1f", "application/data"),
|
||||
array(0, 2, 0, "\x1fÿ", "application/data"),
|
||||
array(0, 2, 0, "\377\037", "application/data"),
|
||||
array(0, 2, 0, "Ë\x05", "application/data"),
|
||||
array(0, 3, 0, "BZh", "application/x-bzip2"),
|
||||
array(0, 2, 0, "ÿv", "application/data"),
|
||||
array(0, 2, 0, "þv", "application/data"),
|
||||
array(0, 2, 0, "ýv", "application/x-lzh"),
|
||||
array(0, 2, 0, "\037\237", "application/data"),
|
||||
array(0, 2, 0, "\037\236", "application/data"),
|
||||
array(0, 2, 0, "\037\240", "application/data"),
|
||||
array(0, 2, 0, "BZ", "application/x-bzip"),
|
||||
array(0, 9, 0, "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a", "application/data"),
|
||||
array(0, 4, 0, "W\x12\x01\x00", "application/core"),
|
||||
array(0, 4, 0, "ÎW\x13", "application/x-gdbm"),
|
||||
array(0, 4, 0, "\x13WÎ", "application/x-gdbm"),
|
||||
array(0, 4, 0, "GDBM", "application/x-gdbm"),
|
||||
array(0, 4, 0, "a\x15\x06\x00", "application/x-db"),
|
||||
array(0, 4, 0, "b1\x05\x00", "application/x-db"),
|
||||
array(0, 23, 0, "=<list>\n<protocol bbn-m", "application/data"),
|
||||
array(0, 5, 0, "diff ", "text/x-patch"),
|
||||
array(0, 4, 0, "*** ", "text/x-patch"),
|
||||
array(0, 8, 0, "Only in ", "text/x-patch"),
|
||||
array(0, 23, 0, "Common subdirectories: ", "text/x-patch"),
|
||||
array(0, 19, 0, "!<arch>\n________64E", "application/data"),
|
||||
array(0, 2, 0, "\x01", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01", "application/x-object-file"),
|
||||
array(0, 3, 0, "\377\377\177", "application/data"),
|
||||
array(0, 3, 0, "\377\377\174", "application/data"),
|
||||
array(0, 3, 0, "\377\377\176", "application/data"),
|
||||
array(0, 3, 0, "\033c\033", "application/data"),
|
||||
array(0, 4, 0, "\x00\x12Ö", "image/x11"),
|
||||
array(0, 8, 0, "!<PDF>!\n", "application/x-prof"),
|
||||
array(0, 2, 0, "\x05\x01", "application/x-locale"),
|
||||
array(0, 4, 0, "\177ELF", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01T", "application/data"),
|
||||
array(0, 2, 0, "\x01U", "application/x-executable-file"),
|
||||
array(0x438, 2, 0, "ïS", "application/x-linux-ext2fs"),
|
||||
array(0, 4, 0, "\366\366\366\366", "application/x-pc-floppy"),
|
||||
array(0774, 2, 0, "¾Ú", "application/data"),
|
||||
array(0x1FE, 2, 0, "ªU", "application/data"),
|
||||
array(0x410, 2, 0, "\x13", "application/x-filesystem"),
|
||||
array(0x410, 2, 0, "\x13", "application/x-filesystem"),
|
||||
array(0x410, 2, 0, "\x24h", "application/x-filesystem"),
|
||||
array(0x410, 2, 0, "\x24x", "application/x-filesystem"),
|
||||
array(0, 9, 0, "-rom1fs-\0", "application/x-filesystem"),
|
||||
array(0, 4, 0, "\x1b\x03\x136", "application/x-bootable"),
|
||||
array(0x18b, 4, 0, "OS/2", "application/x-bootable"),
|
||||
array(0, 4, 0, "FONT", "font/x-vfont"),
|
||||
array(0, 2, 0, "\x01\x1e", "font/x-vfont"),
|
||||
array(0, 2, 0, "\x1e\x01", "font/x-vfont"),
|
||||
array(0, 18, 0, "%!PS-AdobeFont-1.0", "font/type1"),
|
||||
array(6, 18, 0, "%!PS-AdobeFont-1.0", "font/type1"),
|
||||
array(0, 10, 0, "STARTFONT\040", "font/x-bdf"),
|
||||
array(0, 4, 0, "\001fcp", "font/x-pcf"),
|
||||
array(0, 5, 0, "D1.0\015", "font/x-speedo"),
|
||||
array(0, 3, 0, "flf", "font/x-figlet"),
|
||||
array(0, 3, 0, "flc", "application/x-font"),
|
||||
array(0, 4, 0, "\x19Y\x02\x14", "font/x-libgrx"),
|
||||
array(0, 4, 0, "NOFÿ", "font/x-dos"),
|
||||
array(7, 4, 0, "AGE\x00", "font/x-dos"),
|
||||
array(7, 4, 0, "DIV\x00", "font/x-dos"),
|
||||
array(0, 10, 0, "<MakerFile", "application/x-framemaker"),
|
||||
array(0, 8, 0, "<MIFFile", "application/x-framemaker"),
|
||||
array(0, 16, 0, "<MakerDictionary", "application/x-framemaker"),
|
||||
array(0, 16, 0, "<MakerScreenFont", "font/x-framemaker"),
|
||||
array(0, 4, 0, "<MML", "application/x-framemaker"),
|
||||
array(0, 9, 0, "<BookFile", "application/x-framemaker"),
|
||||
array(0, 6, 0, "<Maker", "application/x-framemaker"),
|
||||
array(0, 4, 0377777777, 0x860107, "application/x-executable-file"),
|
||||
array(0, 4, 0377777777, 0x860108, "application/x-executable-file"),
|
||||
array(0, 4, 0377777777, 0x86010b, "application/x-executable-file"),
|
||||
array(0, 4, 0377777777, 0x8600cc, "application/x-executable-file"),
|
||||
array(7, 22, 0, "\357\020\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", "application/core"),
|
||||
array(0, 4, 0, "LDHi", "application/data"),
|
||||
array(0, 13, 0, "GIMP Gradient", "application/x-gimp-gradient"),
|
||||
array(0, 8, 0, "gimp xcf", "application/x-gimp-image"),
|
||||
array(20, 4, 0, "GPAT", "application/x-gimp-pattern"),
|
||||
array(20, 4, 0, "GIMP", "application/x-gimp-brush"),
|
||||
array(0, 4, 0, "\336\22\4\225", "application/x-locale"),
|
||||
array(0, 4, 0, "\225\4\22\336", "application/x-locale"),
|
||||
array(0, 2, 0, "\x01", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01", "application/x-executable-file"),
|
||||
array(0, 5, 0, "\000\001\000\000\000", "font/ttf"),
|
||||
array(0, 4, 0, "\x0a\x0f\x08\x0e", "application/data"),
|
||||
array(0, 4, 0, "\x0f\x0a\x0e\x08", "application/data"),
|
||||
array(0, 4, 0, "\x08\x0e\x0a\x0f", "application/data"),
|
||||
array(0, 4, 0, "\x0e\x08\x0f\x0a", "application/data"),
|
||||
array(0, 4, 0, "\x06\x01\x10\x02", "application/x-object-file"),
|
||||
array(0, 4, 0, "\x07\x01\x10\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x08\x01\x10\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x0b\x01\x10\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x0e\x01\x10\x02", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x0d\x01\x10\x02", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x06\x01\x14\x02", "application/x-object-file"),
|
||||
array(0, 4, 0, "\x07\x01\x14\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x08\x01\x14\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x0b\x01\x14\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x0e\x01\x14\x02", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x0d\x01\x14\x02", "application/x-object-file"),
|
||||
array(0, 4, 0, "\x06\x01\x0b\x02", "application/x-object-file"),
|
||||
array(0, 4, 0, "\x07\x01\x0b\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x08\x01\x0b\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x0b\x01\x0b\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x0e\x01\x0b\x02", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x0d\x01\x0b\x02", "application/x-library-file"),
|
||||
array(0, 4, 0, "ra<!", "application/x-ar"),
|
||||
array(0, 4, 0, "\x02\x08\x01\x06", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x02\x08\x01\x07", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x02\x08\x01\x08", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x08\x01\x0c\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x07\x01\x0c\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x0b\x01\x0c\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x06\x01\x0c\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x08\x01\x0a\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x07\x01\x0a\x02", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x0e\x01\x0c\x02", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x0d\x01\x0c\x02", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x02\x0aÿe", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x02\x0cÿe", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x02\x08ÿe", "application/x-library-file"),
|
||||
array(0, 4, 0, "\x01X!¦", "application/core"),
|
||||
array(0, 4, 0, "M§îè", "font/x-hp-windows"),
|
||||
array(0, 10, 0, "Bitmapfile", "image/unknown"),
|
||||
array(0, 4, 0, "\x02\x0c\x01\x0c", "application/x-lisp"),
|
||||
array(0, 8, 0, "msgcat01", "application/x-locale"),
|
||||
array(0, 2, 0, "P1", "image/x-portable-bitmap"),
|
||||
array(0, 2, 0, "P2", "image/x-portable-graymap"),
|
||||
array(0, 2, 0, "P3", "image/x-portable-pixmap"),
|
||||
array(0, 2, 0, "P4", "image/x-portable-bitmap"),
|
||||
array(0, 2, 0, "P5", "image/x-portable-graymap"),
|
||||
array(0, 2, 0, "P6", "image/x-portable-pixmap"),
|
||||
array(0, 4, 0, "IIN1", "image/tiff"),
|
||||
array(0, 4, 0, "MM\x00\x2a", "image/tiff"),
|
||||
array(0, 4, 0, "II\x2a\x00", "image/tiff"),
|
||||
array(0, 4, 0, "\x89PNG", "image/x-png"),
|
||||
array(1, 3, 0, "PNG", "image/x-png"),
|
||||
array(0, 4, 0, "GIF8", "image/gif"),
|
||||
array(0, 4, 0, "\361\0\100\273", "image/x-cmu-raster"),
|
||||
array(0, 2, 0, "Øÿ", "image/jpeg"),
|
||||
array(0, 4, 0, "hsi1", "image/x-jpeg-proprietary"),
|
||||
array(0, 2, 0, "BM", "image/x-bmp"),
|
||||
array(0, 2, 0, "IC", "image/x-ico"),
|
||||
array(0, 4, 0, "j¦Y", "x/x-image-sun-raster"),
|
||||
array(0, 2, 0, "Ú\x01", "x/x-image-sgi"),
|
||||
array(2048, 7, 0, "PCD_IPI", "x/x-photo-cd-pack-file"),
|
||||
array(0, 7, 0, "PCD_OPA", "x/x-photo-cd-overfiew-file"),
|
||||
array(0, 2, 0, "\x01H", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01I", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01J", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01R", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x01L", "application/x-executable-file"),
|
||||
array(0, 2, 0, "\x046", "font/linux-psf"),
|
||||
array(0, 4, 0, "FFIL", "font/ttf"),
|
||||
array(65, 4, 0, "FFIL", "font/ttf"),
|
||||
array(0, 4, 0, "LWFN", "font/type1"),
|
||||
array(65, 4, 0, "LWFN", "font/type1"),
|
||||
array(0, 12, 0, "Return-Path:", "message/rfc822"),
|
||||
array(0, 5, 0, "Path:", "message/news"),
|
||||
array(0, 5, 0, "Xref:", "message/news"),
|
||||
array(0, 5, 0, "From:", "message/rfc822"),
|
||||
array(0, 7, 0, "Article", "message/news"),
|
||||
array(0, 5, 0, "BABYL", "message/x-gnu-rmail"),
|
||||
array(0, 9, 0, "Received:", "message/rfc822"),
|
||||
array(0, 2, 0, "MZ", "application/x-ms-dos-executable"),
|
||||
array(2080, 27, 0, "Microsoft Word 6.0 Document", "text/vnd.ms-word"),
|
||||
array(2080, 26, 0, "Documento Microsoft Word 6", "text/vnd.ms-word"),
|
||||
array(2112, 9, 0, "MSWordDoc", "text/vnd.ms-word"),
|
||||
array(0, 5, 0, "PO^Q`", "text/vnd.ms-word"),
|
||||
array(2080, 29, 0, "Microsoft Excel 5.0 Worksheet", "application/vnd.ms-excel"),
|
||||
array(2114, 5, 0, "Biff5", "application/vnd.ms-excel"),
|
||||
array(1, 3, 0, "WPC", "text/vnd.wordperfect"),
|
||||
array(0, 4, 0377777777, 0x7018600, "NetBSD/i386"),
|
||||
array(0, 4, 0377777777, 0x7018700, "NetBSD/m68k"),
|
||||
array(0, 4, 0377777777, 0x7018800, "NetBSD/m68k4k"),
|
||||
array(0, 4, 0377777777, 0x7018900, "NetBSD/ns32532"),
|
||||
array(0, 4, 0377777777, 0x7018a00, "NetBSD/sparc"),
|
||||
array(0, 4, 0377777777, 0x7018b00, "NetBSD/pmax"),
|
||||
array(0, 4, 0377777777, 0x7018c00, "NetBSD/vax"),
|
||||
array(0, 4, 0377777777, 0x7018e00, "NetBSD/mips"),
|
||||
array(0, 4, 0377777777, 0x7018f00, "NetBSD/arm32"),
|
||||
array(0, 16, 0, "StartFontMetrics", "font/x-sunos-news"),
|
||||
array(0, 9, 0, "StartFont", "font/x-sunos-news"),
|
||||
array(0, 4, 0, "D)z\x13", "font/x-sunos-news"),
|
||||
array(0, 4, 0, "G)z\x13", "font/x-sunos-news"),
|
||||
array(0, 4, 0, "P)z\x13", "font/x-sunos-news"),
|
||||
array(0, 4, 0, "Q)z\x13", "font/x-sunos-news"),
|
||||
array(8, 4, 0, "E+z\x13", "font/x-sunos-news"),
|
||||
array(8, 4, 0, "H+z\x13", "font/x-sunos-news"),
|
||||
array(0, 2, 0, "%!", "application/postscript"),
|
||||
array(0, 3, 0, "\004%!", "application/postscript"),
|
||||
array(0, 3, 0, "\033E\033", "image/x-pcl-hp"),
|
||||
array(0, 14, 0, "<!DOCTYPE HTML", "text/html"),
|
||||
array(0, 14, 0, "<!doctype html", "text/html"),
|
||||
array(0, 5, 0, "<HEAD", "text/html"),
|
||||
array(0, 5, 0, "<head", "text/html"),
|
||||
array(0, 6, 0, "<TITLE", "text/html"),
|
||||
array(0, 6, 0, "<title", "text/html"),
|
||||
array(0, 5, 0, "<html", "text/html"),
|
||||
array(0, 5, 0, "<HTML", "text/html"),
|
||||
array(0, 2, 0, "\367\203", "font/x-tex"),
|
||||
array(0, 2, 0, "\367\131", "font/x-tex"),
|
||||
array(0, 2, 0, "\367\312", "font/x-tex"),
|
||||
array(2, 2, 0, "\000\021", "font/x-tex-tfm"),
|
||||
array(2, 2, 0, "\000\022", "font/x-tex-tfm"),
|
||||
array('>2', 2, 0, "º¾", "application/java"),
|
||||
array(8, 4, 0, "AIFF", "audio/x-aiff"),
|
||||
array(8, 4, 0, "AIFC", "audio/x-aiff"),
|
||||
array(8, 4, 0, "8SVX", "audio/x-aiff"),
|
||||
array('>8', 4, 0, "WAVE", "audio/x-wav"),
|
||||
array('>8', 3, 0, "AVI", "video/x-msvideo"),
|
||||
array(0, 3, 0, "ID3", "audio/mpeg"),
|
||||
array(0, 4, 0, "OggS", "audio/x-ogg"),
|
||||
array(0, 6, 0, "/* XPM", "image/x-xpm"),
|
||||
array(16, 2, 0, "==", "image/x-3ds"),
|
||||
array(0, 11, 0, "#!/bin/tcsh", "application/x-shellscript"),
|
||||
array(0, 12, 0, "#! /bin/tcsh", "application/x-shellscript"),
|
||||
array(0, 18, 0, "#! /usr/local/tcsh", "application/x-shellscript"),
|
||||
array('>8', 6, 0, "debian", "application/x-debian-package"),
|
||||
array('>2', 2, 0, "Ûî", "application/x-rpm"),
|
||||
array(2, 5, 0, "-lh -", "application/x-lha"),
|
||||
array(2, 5, 0, "-lh6-", "application/x-lha"),
|
||||
array(2, 5, 0, "-lh7-", "application/x-lha"),
|
||||
array(0, 15, 0, "<MakerScreenFon", "application/x-frame"),
|
||||
array(0, 5, 0, "<Book", "application/x-frame"),
|
||||
array(0, 3, 0, "<h1", "text/html"),
|
||||
array(0, 3, 0, "<H1", "text/html"),
|
||||
array(0, 14, 0, "<!doctype HTML", "text/html"),
|
||||
array(0, 2, 0, "MM", "image/tiff"),
|
||||
array(0, 2, 0, "II", "image/tiff"),
|
||||
array(0, 6, 0, "GIF94z", "image/unknown"),
|
||||
array(0, 6, 0, "FGF95a", "image/unknown"),
|
||||
array(0, 3, 0, "PBF", "image/unknown"),
|
||||
array(0, 3, 0, "GIF", "image/gif"),
|
||||
array(0, 4, 0, "\376\067\0\043", "application/msword"),
|
||||
array(0, 6, 0, "\320\317\021\340\241\261", "application/msword"),
|
||||
array(0, 6, 0, "\333\245-\0\0\0", "application/msword"),
|
||||
array(0, 2, 0, "\x02÷", "application/x-dvi"),
|
||||
array(0, 2, 0, "¯\x11", "video/fli"),
|
||||
array(0, 2, 0, "¯\x12", "video/flc"),
|
||||
array('>8', 4, 0, "AVI ", "video/avi"),
|
||||
array(0, 1, 0, "\x01", "video/unknown"),
|
||||
array(0, 1, 0, "\x02", "video/unknown"),
|
||||
array(0, 19, 0, "[KDE Desktop Entry]", "application/x-kdelnk"),
|
||||
array(0, 18, 0, "\# KDE Config File", "application/x-kdelnk"),
|
||||
array(0, 7, 0, "\# xmcd", "text/xmcd"),
|
||||
array(0, 4, 0, "\x8aMNG", "video/x-mng"),
|
||||
array(0, 4, 0, "ó\x03\x00\x00", "application/x-executable-file"),
|
||||
array(0, 4, 0, "ç\x03\x00\x00", "application/x-library-file"),
|
||||
array(0, 4, 0, "³\x01\x00\x00", "video/mpeg"),
|
||||
array(0, 4, 0, "º\x01\x00\x00", "video/mpeg"),
|
||||
array(0, 4, 0, "\x00\x00l", "application/x-apl-workspace"),
|
||||
array(0, 4, 0, "\x00\x00ÿm", "application/x-ar"),
|
||||
array(0, 4, 0, "\x00\x00ÿe", "application/data"),
|
||||
array(0, 4, 0, "\x00\x00\x01\x06", "application/x-executable-file"),
|
||||
array(0, 4, 0, "G\x01\x00\x00", "application/x-object-file"),
|
||||
array(0, 4, 0, "K\x01\x00\x00", "application/x-executable-file"),
|
||||
array(0, 4, 0, "M\x01\x00\x00", "application/x-executable-file"),
|
||||
array(0, 4, 0, "O\x01\x00\x00", "application/x-executable-file"),
|
||||
array(24, 4, 0, "kê\x00\x00", "application/data"),
|
||||
array(24, 4, 0, "lê\x00\x00", "application/data"),
|
||||
array(24, 4, 0, "mê\x00\x00", "application/data"),
|
||||
array(24, 4, 0, "nê\x00\x00", "application/data"),
|
||||
array(0, 4, 0, "\x01\x00\x00", "application/x-object-file"),
|
||||
array(0, 4, 0, "\x01\x00\x00", "application/data"),
|
||||
array(24, 4, 0, "\x00\x00êl", "application/x-dump"),
|
||||
array(24, 4, 0, "\x00\x00êk", "application/x-dump"),
|
||||
array(0, 4, 0, "\x00\x00¾1", "text/vnd.ms-word"),
|
||||
array(0, 2, 0, "\x00\x00", "audio/mpeg"),
|
||||
array('>16', 2, 0, "\x00\x01", "application/x-object"),
|
||||
array('>16', 2, 0, "\x00\x02", "application/x-executable"),
|
||||
array('>16', 2, 0, "\x00\x03", "application/x-sharedlib"),
|
||||
array('>16', 2, 0, "\x00\x04", "application/x-coredump"),
|
||||
array(0, 4, 0, "\x00\x00\x00Ì", "application/x-executable-file"),
|
||||
array(0, 4, 0, "\x04\x00\x00\x00", "font/x-snf"),
|
||||
array(0, 4, 0, "\x00\x00\x00\x04", "font/x-snf"),
|
||||
array('>12', 4, 0, "\x01\x00\x00\x00", "audio/basic"),
|
||||
array('>12', 4, 0, "\x02\x00\x00\x00", "audio/basic"),
|
||||
array('>12', 4, 0, "\x03\x00\x00\x00", "audio/basic"),
|
||||
array('>12', 4, 0, "\x04\x00\x00\x00", "audio/basic"),
|
||||
array('>12', 4, 0, "\x05\x00\x00\x00", "audio/basic"),
|
||||
array('>12', 4, 0, "\x06\x00\x00\x00", "audio/basic"),
|
||||
array('>12', 4, 0, "\x07\x00\x00\x00", "audio/basic"),
|
||||
array('>12', 4, 0, "\x17\x00\x00\x00", "audio/x-adpcm"),
|
||||
array('>12', 4, 0, "\x00\x00\x00\x01", "audio/x-dec-basic"),
|
||||
array('>12', 4, 0, "\x00\x00\x00\x02", "audio/x-dec-basic"),
|
||||
array('>12', 4, 0, "\x00\x00\x00\x03", "audio/x-dec-basic"),
|
||||
array('>12', 4, 0, "\x00\x00\x00\x04", "audio/x-dec-basic"),
|
||||
array('>12', 4, 0, "\x00\x00\x00\x05", "audio/x-dec-basic"),
|
||||
array('>12', 4, 0, "\x00\x00\x00\x06", "audio/x-dec-basic"),
|
||||
array('>12', 4, 0, "\x00\x00\x00\x07", "audio/x-dec-basic"),
|
||||
array('>12', 4, 0, "\x00\x00\x00\x17", "audio/x-dec-adpcm")
|
||||
);
|
||||
|
||||
$fd = substr($binary_data, 0, 3072);
|
||||
foreach ($mime_magic_data as $def) {
|
||||
$pos0 = $def[0];
|
||||
if ($pos0[0] == ">") {
|
||||
$pos0 = substr($pos0, 1);
|
||||
if (@strpos($fd, $def[3], $pos0) !== false) {
|
||||
return($def[4]);
|
||||
}
|
||||
} else {
|
||||
$part = substr($fd, $pos0, $def[1]);
|
||||
$mask = $def[2];
|
||||
if ($mask) {
|
||||
// if $mask is 0
|
||||
$value = 1 * ('0x'.bin2hex($part));
|
||||
if (($value & $mask) == $def[3]) {
|
||||
return($def[4]);
|
||||
}
|
||||
} else {
|
||||
if ($part == $def[3]) {
|
||||
return($def[4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
/*
|
||||
Can be used to allow preserving of certain "safe" HTML <tags>
|
||||
(as seen in [sfWiki | http://sfwiki.sf.net/].
|
||||
"Safe" tags include Q, S, PRE, TT, H1-H6, KBD, VAR, XMP, B, I
|
||||
but just see (or change) ewiki_format() for more. They are not
|
||||
accepted if written with mixed lowercase and uppercase letters,
|
||||
and they cannot contain any tag attributes.
|
||||
|
||||
RESCUE_HTML was formerly part of the main rendering function, but
|
||||
has now been extracted into this plugin, so one only needs to
|
||||
include it to get simple html tags working.
|
||||
*/
|
||||
|
||||
|
||||
$ewiki_plugins["format_source"][] = "ewiki_moodle_rescue_html";
|
||||
|
||||
|
||||
function ewiki_moodle_rescue_html(&$wiki_source) {
|
||||
$safe_html = EWIKI_RESCUE_HTML;
|
||||
$safe_html += 1;
|
||||
|
||||
$rescue_html = array(
|
||||
"br", "tt", "b", "i", "strong", "em", "s", "kbd", "var", "xmp", "sup", "sub",
|
||||
"pre", "q", "h1", "h2", "h3", "h4", "h5", "h6", "cite", "code", "u",
|
||||
);
|
||||
|
||||
|
||||
|
||||
#-- unescape allowed html
|
||||
if ($safe_html) {
|
||||
/*
|
||||
foreach ($rescue_html as $tag) {
|
||||
foreach(array($tag, "/$tag", ($tag=strtoupper($tag)), "/$tag") as $tag) {
|
||||
$wiki_source = str_replace('<'.$tag.'>', "<".$tag.">", $wiki_source);
|
||||
} }
|
||||
*/
|
||||
$regexp='#<(/?('.implode("|",$rescue_html).'))( /)?>#i';
|
||||
$wiki_source = preg_replace($regexp, '<$1>', $wiki_source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,316 +0,0 @@
|
||||
<?php
|
||||
/* MySQL database backend
|
||||
(Glue between Moodle and ewiki Database)
|
||||
|
||||
Adapted by Michael Schneider
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
/// Glue
|
||||
$ewiki_plugins["database"][0] = "ewiki_database_moodle";
|
||||
|
||||
/// #-- predefine some of the configuration constants
|
||||
//define("EWIKI_NAME", $wiki_entry->pagename); COMMENTED BY PIGUI BECOUSE OF MIGRATION
|
||||
|
||||
define("EWIKI_CONTROL_LINE", 0);
|
||||
define("EWIKI_LIST_LIMIT", 25);
|
||||
//define("EWIKI_DEFAULT_LANG", current_language()); COMMENTED BY PIGUI BECOUSE OF MIGRATION
|
||||
define("EWIKI_HTML_CHARS", 1);
|
||||
define("EWIKI_DB_TABLE_NAME", "wiki_pages_old");
|
||||
|
||||
|
||||
function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
|
||||
global $wiki, $wiki_entry, $CFG, $DB;
|
||||
#-- result array
|
||||
$r = array();
|
||||
|
||||
switch($action) {
|
||||
|
||||
/* Returns database entry as array for the page whose name was given
|
||||
with the "id" key in the $args array, usually fetches the latest
|
||||
version of a page, unless a specific "version" was requested in
|
||||
the $args array.
|
||||
*/
|
||||
# Ugly, but we need to choose which wiki we are about to change/read
|
||||
case "GET":
|
||||
$params = array('id'=>$args["id"]);
|
||||
if ($version = 0 + @$args["version"]) {
|
||||
$params['version'] = $version;
|
||||
$versionsql = "AND version = :version";
|
||||
} else {
|
||||
$versionsql = "";
|
||||
|
||||
}
|
||||
|
||||
# $result = mysql_query("SELECT * FROM " . EWIKI_DB_TABLE_NAME
|
||||
# . " WHERE (pagename=$id) $version ORDER BY version DESC LIMIT 1"
|
||||
#);
|
||||
#if ($result && ($r = mysql_fetch_array($result, MYSQL_ASSOC))) {
|
||||
# $r["id"] = $r["pagename"];
|
||||
# unset($r["pagename"]);
|
||||
#}
|
||||
#if (strlen($r["meta"])) {
|
||||
# $r["meta"] = @unserialize($r["meta"]);
|
||||
#}
|
||||
|
||||
$select="(pagename=:id) AND wiki= :weid $versionsql ";
|
||||
$params['weid'] = $wiki_entry->id;
|
||||
$sort="version DESC";
|
||||
|
||||
if ($result_arr = $DB->get_records_select(EWIKI_DB_TABLE_NAME, $select, $params, $sort,"*",0,1)) {
|
||||
//Iterate to get the first (and unique!)
|
||||
foreach ($result_arr as $obj) {
|
||||
$result_obj = $obj;
|
||||
}
|
||||
}
|
||||
if($result_obj) {
|
||||
//Convert to array
|
||||
$r=get_object_vars($result_obj);
|
||||
$r["id"] = $r["pagename"];
|
||||
unset($r["pagename"]);
|
||||
$r["meta"] = @unserialize($r["meta"]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
/* Increases the hit counter for the page name given in $args array
|
||||
with "id" index key.
|
||||
*/
|
||||
case "HIT":
|
||||
#mysql_query("UPDATE " . EWIKI_DB_TABLE_NAME . " SET hits=(hits+1) WHERE pagename='" . anydb_escape_string($args["id"]) . "'");
|
||||
# $DB->set_field does not work because of the "hits+1" construct
|
||||
#print "DO ".anydb__escape_string($args["id"]); exit;
|
||||
$DB->execute("UPDATE {".EWIKI_DB_TABLE_NAME."} SET hits=(hits+1) WHERE pagename=? and wiki=?", array($args["id"], $wiki_entry->id));
|
||||
break;
|
||||
/* Stores the $data array into the database, while not overwriting
|
||||
existing entries (using WRITE); returns 0 on failure and 1 if
|
||||
saved correctly.
|
||||
*/
|
||||
case "OVERWRITE":
|
||||
$COMMAND = "REPLACE";
|
||||
break;
|
||||
|
||||
case "WRITE":
|
||||
$COMMAND="WRITE";
|
||||
$args["pagename"] = $args["id"];
|
||||
unset($args["id"]);
|
||||
|
||||
if (is_array($args["meta"])) {
|
||||
$args["meta"] = serialize($args["meta"]);
|
||||
}
|
||||
|
||||
#$sql1 = $sql2 = "";
|
||||
#foreach ($args as $index => $value) {
|
||||
# if (is_int($index)) {
|
||||
# continue;
|
||||
# }
|
||||
# $a = ($sql1 ? ', ' : '');
|
||||
# $sql1 .= $a . $index;
|
||||
# $sql2 .= $a . "'" . anydb_escape_string($value) . "'";
|
||||
#}
|
||||
|
||||
#strlen(@$COMMAND) || ($COMMAND = "INSERT");
|
||||
|
||||
foreach ($args as $index => $value) {
|
||||
if (is_int($index)) {
|
||||
continue;
|
||||
}
|
||||
$args[$index] =anydb_escape_string($value);
|
||||
}
|
||||
$args["wiki"]=$wiki_entry->id;
|
||||
|
||||
# Check if Record exists
|
||||
if($COMMAND=="REPLACE") {
|
||||
if ($DB->count_records(EWIKI_DB_TABLE_NAME, array("wiki"=>$wiki_entry->id,"pagename"=>$args["pagename"],"version"=>$args["version"]))) {
|
||||
$DB->delete_record(EWIKI_DB_TABLE_NAME, array("wiki"=>$wiki_entry->id,"pagename"=>$args["pagename"],"version"=>$args["version"]));
|
||||
}
|
||||
}
|
||||
|
||||
# Write
|
||||
$result=$DB->insert_record(EWIKI_DB_TABLE_NAME,(object)$args,false);
|
||||
|
||||
#$result = mysql_query("$COMMAND INTO " . EWIKI_DB_TABLE_NAME .
|
||||
# " (" . $sql1 . ") VALUES (" . $sql2 . ")"
|
||||
#);
|
||||
#return($result && mysql_affected_rows() ?1:0);
|
||||
|
||||
return $result;
|
||||
break;
|
||||
|
||||
|
||||
|
||||
/* Checks for existence of the WikiPages whose names are given in
|
||||
the $args array. Returns an array with the specified WikiPageNames
|
||||
associated with values of "0" or "1" (stating if the page exists
|
||||
in the database). For images/binary db entries returns the "meta"
|
||||
field instead of an "1".
|
||||
*/
|
||||
case "FIND":
|
||||
$select = "";
|
||||
$params = array();
|
||||
$p=0;
|
||||
foreach (array_values($args) as $id) {
|
||||
if (strlen($id)) {
|
||||
$p++;
|
||||
$pname = "par$p";
|
||||
$r[$id] = 0;
|
||||
$select .= ($select ? " OR " : "") .
|
||||
"(pagename= :$pname)";
|
||||
$params[$pname] = $id;
|
||||
}
|
||||
}
|
||||
if($select) {
|
||||
$select = "(".$select.") AND wiki= :weid ";
|
||||
$params['weid'] = $wiki_entry->id;
|
||||
$result = $DB->get_records_select(EWIKI_DB_TABLE_NAME,$select, $params);
|
||||
|
||||
while(list($key, $val) = @each($result)) {
|
||||
$r[$val->pagename]=strpos($val->meta, 's:5:"image"') ? $val->meta : 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Counts the number of Versions
|
||||
*/
|
||||
case "COUNTVERSIONS":
|
||||
$sql= "SELECT pagename AS id, count(*) as versioncount".
|
||||
" FROM {".EWIKI_DB_TABLE_NAME."}
|
||||
WHERE wiki = ?".
|
||||
" GROUP BY pagename";
|
||||
|
||||
#print "$sql";
|
||||
$result=$DB->get_records_sql($sql, array($wiki_entry->id));
|
||||
while(list($key, $val) = each($result)) {
|
||||
$r[$key]=$val->versioncount;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Returns an array of the lastest versions of __all__ pages,
|
||||
where each entry is made up of the fields from the database
|
||||
requested with the $args array, e.g.
|
||||
array("flags","meta","lastmodified");
|
||||
*/
|
||||
case "GETALL":
|
||||
switch ($DB->get_db_family()) {
|
||||
case 'postgres':
|
||||
// All but the latest version eliminated by DISTINCT
|
||||
// ON (pagename)
|
||||
$sql= "SELECT DISTINCT ON (pagename) pagename AS id, ".
|
||||
implode(", ", $args) .
|
||||
" FROM {".EWIKI_DB_TABLE_NAME."}".
|
||||
" WHERE wiki = ?".
|
||||
" ORDER BY pagename, version DESC";
|
||||
break;
|
||||
case 'mysql':
|
||||
// All but the latest version eliminated by
|
||||
// mysql-specific GROUP BY-semantics
|
||||
$sql= "SELECT pagename AS id, ".
|
||||
implode(", ", $args) .
|
||||
" FROM {".EWIKI_DB_TABLE_NAME."}".
|
||||
" WHERE wiki = ?".
|
||||
" GROUP BY id, version DESC " ;
|
||||
default:
|
||||
// All but the latest version are here eliminated in
|
||||
// $DB->get_records_sql, since it will return an array
|
||||
// with only one result per id-field value. Note,
|
||||
// that for this to work the query needs to order the
|
||||
// records ascending by version, so later versions
|
||||
// will overwrite previous ones in
|
||||
// recordset_to_array. This is not pretty.
|
||||
$sql= "SELECT pagename AS id, ".
|
||||
implode(", ", $args) .
|
||||
" FROM {".EWIKI_DB_TABLE_NAME."}".
|
||||
" WHERE wiki = ?".
|
||||
" ORDER BY version";
|
||||
}
|
||||
|
||||
$result = $DB->get_records_sql($sql, array($wiki_entry->id));
|
||||
$r = new ewiki_dbquery_result($args);
|
||||
|
||||
if ($result) {
|
||||
foreach($result as $val) {
|
||||
$r->add(get_object_vars($val));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
/* Returns array of database entries (also arrays), where the one
|
||||
specified column matches the specified content string, for example
|
||||
$args = array("content" => "text...piece")
|
||||
is not guaranteed to only search/return the latest version of a page
|
||||
*/
|
||||
case "SEARCH":
|
||||
$field = implode("", array_keys($args));
|
||||
$content = strtolower(implode("", $args));
|
||||
if ($field == "id") { $field = "pagename"; }
|
||||
$sql= "SELECT pagename AS id, version, flags" .
|
||||
(EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
|
||||
" FROM {".EWIKI_DB_TABLE_NAME."}".
|
||||
" WHERE " . $DB->sql_like($field, '?', false) . " and wiki= ?".
|
||||
" ORDER BY id, version ASC";
|
||||
$result=$DB->get_records_sql($sql, array("%$content%", $wiki_entry->id));
|
||||
|
||||
$r = new ewiki_dbquery_result(array("id","version",$field));
|
||||
$drop = "";
|
||||
#while ($result && ($row = mysql_fetch_array($result, MYSQL_ASSOC))) {
|
||||
# $i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"];
|
||||
# if ($i != $drop) {
|
||||
# $drop = $i;
|
||||
# $r->add($row);
|
||||
# }
|
||||
#}
|
||||
while(list($key, $val) = @each($result)) {
|
||||
$row=get_object_vars($val);
|
||||
$i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"];
|
||||
if ($i != $drop) {
|
||||
$drop = $i;
|
||||
$r->add($row);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case "DELETE":
|
||||
$id = $args["id"];
|
||||
$version = $args["version"];
|
||||
|
||||
#mysql_query("DELETE FROM " . EWIKI_DB_TABLE_NAME ."
|
||||
# WHERE pagename='$id' AND version=$version");
|
||||
# print "DELETING wiki:".$wiki_entry->id."Pagename: $id Version: $version <br />\n";
|
||||
$DB->delete_records(EWIKI_DB_TABLE_NAME, array("wiki"=>$wiki_entry->id,"pagename"=>$id,"version"=>$version));
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case "INIT":
|
||||
#mysql_query("CREATE TABLE " . EWIKI_DB_TABLE_NAME ."
|
||||
# (pagename VARCHAR(160) NOT NULL,
|
||||
# version INTEGER UNSIGNED NOT NULL DEFAULT 0,
|
||||
# flags INTEGER UNSIGNED DEFAULT 0,
|
||||
# content MEDIUMTEXT,
|
||||
# author VARCHAR(100) DEFAULT 'ewiki',
|
||||
# created INTEGER UNSIGNED DEFAULT ".time().",
|
||||
# lastmodified INTEGER UNSIGNED DEFAULT 0,
|
||||
# refs MEDIUMTEXT,
|
||||
# meta MEDIUMTEXT,
|
||||
# hits INTEGER UNSIGNED DEFAULT 0,
|
||||
# PRIMARY KEY id (pagename, version) )
|
||||
# ");
|
||||
#echo mysql_error();
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
return($r);
|
||||
}
|
||||
|
||||
function anydb_escape_string($s) {
|
||||
return($s);
|
||||
}
|
||||
|
||||
@@ -41,337 +41,6 @@ function xmldb_wiki_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
// Step 0: Add new fields to main wiki table
|
||||
if ($oldversion < 2010040100) {
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
echo $OUTPUT->notification('Adding new fields to wiki table', 'notifysuccess');
|
||||
wiki_add_wiki_fields();
|
||||
|
||||
upgrade_mod_savepoint(true, 2010040100, 'wiki');
|
||||
}
|
||||
|
||||
// Step 1: Rename old tables
|
||||
if ($oldversion < 2010040101) {
|
||||
$tables = array('wiki_pages', 'wiki_locks', 'wiki_entries');
|
||||
|
||||
echo $OUTPUT->notification('Renaming old wiki module tables', 'notifysuccess');
|
||||
foreach ($tables as $tablename) {
|
||||
$table = new xmldb_table($tablename);
|
||||
if ($dbman->table_exists($table)) {
|
||||
if ($dbman->table_exists($table)) {
|
||||
$dbman->rename_table($table, $tablename . '_old');
|
||||
}
|
||||
}
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2010040101, 'wiki');
|
||||
}
|
||||
|
||||
// Step 2: Creating new tables
|
||||
if ($oldversion < 2010040102) {
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
echo $OUTPUT->notification('Installing new wiki module tables', 'notifysuccess');
|
||||
wiki_upgrade_install_20_tables();
|
||||
upgrade_mod_savepoint(true, 2010040102, 'wiki');
|
||||
}
|
||||
|
||||
// Step 3: migrating wiki instances
|
||||
if ($oldversion < 2010040103) {
|
||||
upgrade_set_timeout();
|
||||
|
||||
// Setting up wiki configuration
|
||||
$sql = "UPDATE {wiki}
|
||||
SET intro = summary,
|
||||
firstpagetitle = pagename,
|
||||
defaultformat = ?";
|
||||
$DB->execute($sql, array('html'));
|
||||
|
||||
$sql = "UPDATE {wiki}
|
||||
SET wikimode = ?
|
||||
WHERE wtype = ?";
|
||||
$DB->execute($sql, array('collaborative', 'group'));
|
||||
|
||||
$sql = "UPDATE {wiki}
|
||||
SET wikimode = ?
|
||||
WHERE wtype != ?";
|
||||
$DB->execute($sql, array('individual', 'group'));
|
||||
|
||||
// Removing edit & create capability to students in old teacher wikis
|
||||
$studentroles = $DB->get_records('role', array('archetype' => 'student'));
|
||||
$wikis = $DB->get_records('wiki');
|
||||
foreach ($wikis as $wiki) {
|
||||
echo $OUTPUT->notification('Migrating '.$wiki->wtype.' type wiki instance: '.$wiki->name, 'notifysuccess');
|
||||
if ($wiki->wtype == 'teacher') {
|
||||
$cm = get_coursemodule_from_instance('wiki', $wiki->id);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
foreach ($studentroles as $studentrole) {
|
||||
role_change_permission($studentrole->id, $context, 'mod/wiki:editpage', CAP_PROHIBIT);
|
||||
role_change_permission($studentrole->id, $context, 'mod/wiki:createpage', CAP_PROHIBIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $OUTPUT->notification('Migrating old wikis to new wikis', 'notifysuccess');
|
||||
upgrade_mod_savepoint(true, 2010040103, 'wiki');
|
||||
}
|
||||
|
||||
// Step 4: migrating wiki entries to new subwikis
|
||||
if ($oldversion < 2010040104) {
|
||||
/**
|
||||
* Migrating wiki entries to new subwikis
|
||||
*/
|
||||
$sql = "INSERT INTO {wiki_subwikis} (wikiid, groupid, userid)
|
||||
SELECT DISTINCT e.wikiid, e.groupid, e.userid
|
||||
FROM {wiki_entries_old} e";
|
||||
echo $OUTPUT->notification('Migrating old entries to new subwikis', 'notifysuccess');
|
||||
|
||||
$DB->execute($sql, array());
|
||||
|
||||
upgrade_mod_savepoint(true, 2010040104, 'wiki');
|
||||
}
|
||||
|
||||
// Step 5: Migrating pages
|
||||
if ($oldversion < 2010040105) {
|
||||
|
||||
// select all wiki pages
|
||||
$sql = "SELECT s.id, p.pagename, p.created, p.lastmodified, p.userid, p.hits
|
||||
FROM {wiki_pages_old} p
|
||||
LEFT OUTER JOIN {wiki_entries_old} e ON e.id = p.wiki
|
||||
LEFT OUTER JOIN {wiki_subwikis} s ON s.wikiid = e.wikiid AND s.groupid = e.groupid AND s.userid = e.userid
|
||||
WHERE p.version = (SELECT max(po.version)
|
||||
FROM {wiki_pages_old} po
|
||||
WHERE p.pagename = po.pagename AND p.wiki = po.wiki)";
|
||||
echo $OUTPUT->notification('Migrating old pages to new pages', 'notifysuccess');
|
||||
|
||||
$records = $DB->get_recordset_sql($sql);
|
||||
foreach ($records as $record) {
|
||||
$page = new stdclass();
|
||||
$page->subwikiid = $record->id;
|
||||
$page->title = $record->pagename;
|
||||
$page->cachedcontent = '**reparse needed**';
|
||||
$page->timecreated = $record->created;
|
||||
$page->timemodified = $record->lastmodified;
|
||||
$page->userid = $record->userid;
|
||||
$page->pageviews = $record->hits;
|
||||
try {
|
||||
// make sure there is no duplicated records exist
|
||||
if (!$DB->record_exists('wiki_pages', array('subwikiid'=>$record->id, 'userid'=>$record->userid, 'title'=>$record->pagename))) {
|
||||
$DB->insert_record('wiki_pages', $page);
|
||||
}
|
||||
} catch (dml_exception $e) {
|
||||
// catch possible insert exception
|
||||
debugging($e->getMessage());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$records->close();
|
||||
|
||||
upgrade_mod_savepoint(true, 2010040105, 'wiki');
|
||||
}
|
||||
|
||||
// Step 6: Migrating versions
|
||||
if ($oldversion < 2010040106) {
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
echo $OUTPUT->notification('Migrating old history to new history', 'notifysuccess');
|
||||
wiki_upgrade_migrate_versions();
|
||||
upgrade_mod_savepoint(true, 2010040106, 'wiki');
|
||||
}
|
||||
|
||||
// Step 7: refresh cachedcontent and fill wiki links table
|
||||
if ($oldversion < 2010040107) {
|
||||
require_once($CFG->dirroot. '/mod/wiki/locallib.php');
|
||||
upgrade_set_timeout();
|
||||
|
||||
$pages = $DB->get_recordset('wiki_pages');
|
||||
|
||||
foreach ($pages as $page) {
|
||||
wiki_refresh_cachedcontent($page);
|
||||
}
|
||||
|
||||
$pages->close();
|
||||
|
||||
echo $OUTPUT->notification('Caching content', 'notifysuccess');
|
||||
upgrade_mod_savepoint(true, 2010040107, 'wiki');
|
||||
}
|
||||
// Step 8, migrating files
|
||||
if ($oldversion < 2010040108) {
|
||||
$fs = get_file_storage();
|
||||
$sql = "SELECT files.*, po.meta AS filemeta FROM {wiki_pages_old} po JOIN (
|
||||
SELECT DISTINCT po.id, po.pagename, w.id AS wikiid, po.userid,
|
||||
eo.id AS entryid, eo.groupid, s.id AS subwiki,
|
||||
w.course AS courseid, cm.id AS cmid
|
||||
FROM {wiki_pages_old} po
|
||||
LEFT OUTER JOIN {wiki_entries_old} eo
|
||||
ON eo.id=po.wiki
|
||||
LEFT OUTER JOIN {wiki} w
|
||||
ON w.id = eo.wikiid
|
||||
LEFT OUTER JOIN {wiki_subwikis} s
|
||||
ON s.groupid = eo.groupid AND s.wikiid = eo.wikiid AND eo.userid = s.userid
|
||||
JOIN {modules} m ON m.name = 'wiki'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = w.id)
|
||||
) files ON files.id = po.id";
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql);
|
||||
foreach ($rs as $r) {
|
||||
if (strpos($r->pagename, 'internal://') !== false) {
|
||||
// Found a file resource!
|
||||
$pattern = 'internal://';
|
||||
$matches = array();
|
||||
$filename = str_replace($pattern, '', $r->pagename);
|
||||
$orgifilename = $filename = clean_param($filename, PARAM_FILE);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $r->cmid);
|
||||
$filemeta = unserialize($r->filemeta);
|
||||
$filesection = $filemeta['section'];
|
||||
// When attach a file to wiki page, user can customize the file name instead of original file name
|
||||
// if user did, old wiki will create two pages, internal://original_pagename and internal://renamed_pagename
|
||||
// internal://original_pagename record has renamed pagename in meta field
|
||||
// but all file have this field
|
||||
// old wiki will rename file names to filter space and special character
|
||||
if (!empty($filemeta['Content-Location'])) {
|
||||
$orgifilename = urldecode($filemeta['Content-Location']);
|
||||
$orgifilename = str_replace(' ', '_', $orgifilename);
|
||||
}
|
||||
$thefile = $CFG->dataroot . '/' . $r->courseid . '/moddata/wiki/' . $r->wikiid .'/' . $r->entryid . '/'. $filesection .'/'. $filename;
|
||||
|
||||
if (is_file($thefile) && is_readable($thefile)) {
|
||||
$filerecord = array('contextid' => $context->id,
|
||||
'component' => 'mod_wiki',
|
||||
'filearea' => 'attachments',
|
||||
'itemid' => $r->subwiki,
|
||||
'filepath' => '/',
|
||||
'filename' => $orgifilename,
|
||||
'userid' => $r->userid);
|
||||
if (!$fs->file_exists($context->id, 'mod_wiki', 'attachments', $r->subwiki, '/', $orgifilename)) {
|
||||
//echo $OUTPUT->notification('Migrating file '.$orgifilename, 'notifysuccess');
|
||||
$storedfile = $fs->create_file_from_pathname($filerecord, $thefile);
|
||||
}
|
||||
// we have to create another file here to make sure interlinks work
|
||||
if (!$fs->file_exists($context->id, 'mod_wiki', 'attachments', $r->subwiki, '/', $filename)) {
|
||||
$filerecord['filename'] = $filename;
|
||||
//echo $OUTPUT->notification('Migrating file '.$filename, 'notifysuccess');
|
||||
$storedfile = $fs->create_file_from_pathname($filerecord, $thefile);
|
||||
}
|
||||
} else {
|
||||
echo $OUTPUT->notification("Bad data found: $r->pagename <br/> Expected file path: $thefile Please fix the bad file path manually.");
|
||||
}
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
upgrade_mod_savepoint(true, 2010040108, 'wiki');
|
||||
}
|
||||
|
||||
// Step 9: clean wiki table
|
||||
if ($oldversion < 2010040109) {
|
||||
$fields = array('summary', 'pagename', 'wtype', 'ewikiprinttitle', 'htmlmode', 'ewikiacceptbinary', 'disablecamelcase', 'setpageflags', 'strippages', 'removepages', 'revertchanges', 'initialcontent');
|
||||
$table = new xmldb_table('wiki');
|
||||
foreach ($fields as $fieldname) {
|
||||
$field = new xmldb_field($fieldname);
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->drop_field($table, $field);
|
||||
}
|
||||
|
||||
}
|
||||
echo $OUTPUT->notification('Cleaning wiki table', 'notifysuccess');
|
||||
upgrade_mod_savepoint(true, 2010040109, 'wiki');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010080201) {
|
||||
|
||||
$sql = "UPDATE {comments}
|
||||
SET commentarea = 'wiki_page'
|
||||
WHERE commentarea = 'wiki_comment_section'";
|
||||
$DB->execute($sql);
|
||||
|
||||
$sql = "UPDATE {tag_instance}
|
||||
SET itemtype = 'wiki_page'
|
||||
WHERE itemtype = 'wiki'";
|
||||
$DB->execute($sql);
|
||||
|
||||
echo $OUTPUT->notification('Updating comments and tags', 'notifysuccess');
|
||||
|
||||
upgrade_mod_savepoint(true, 2010080201, 'wiki');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010102500) {
|
||||
|
||||
// Define key subwikifk (foreign) to be added to wiki_pages
|
||||
$table = new xmldb_table('wiki_pages');
|
||||
$key = new xmldb_key('subwikifk', XMLDB_KEY_FOREIGN, array('subwikiid'), 'wiki_subwikis', array('id'));
|
||||
|
||||
// Launch add key subwikifk
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
// Define key subwikifk (foreign) to be added to wiki_links
|
||||
$table = new xmldb_table('wiki_links');
|
||||
$key = new xmldb_key('subwikifk', XMLDB_KEY_FOREIGN, array('subwikiid'), 'wiki_subwikis', array('id'));
|
||||
|
||||
// Launch add key subwikifk
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
// wiki savepoint reached
|
||||
upgrade_mod_savepoint(true, 2010102500, 'wiki');
|
||||
}
|
||||
|
||||
if ($oldversion < 2010102800) {
|
||||
|
||||
$sql = "UPDATE {tag_instance}
|
||||
SET itemtype = 'wiki_pages'
|
||||
WHERE itemtype = 'wiki_page'";
|
||||
$DB->execute($sql);
|
||||
|
||||
echo $OUTPUT->notification('Updating tags itemtype', 'notifysuccess');
|
||||
|
||||
upgrade_mod_savepoint(true, 2010102800, 'wiki');
|
||||
}
|
||||
|
||||
if ($oldversion < 2011011000) {
|
||||
// Fix wiki in the post table after upgrade from 1.9
|
||||
$table = new xmldb_table('wiki');
|
||||
|
||||
// name should default to Wiki
|
||||
$field = new xmldb_field('name', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL, null, 'Wiki', 'course');
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->change_field_default($table, $field);
|
||||
}
|
||||
|
||||
// timecreated field is missing after 1.9 upgrade
|
||||
$field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'introformat');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// timemodified field is missing after 1.9 upgrade
|
||||
$field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, 10, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'timecreated');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// scaleid is not there any more
|
||||
$field = new xmldb_field('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->drop_field($table, $field);
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2011011000, 'wiki');
|
||||
}
|
||||
|
||||
// TODO: Will hold the old tables so we will have chance to fix problems
|
||||
// Will remove old tables once migrating 100% stable
|
||||
// Step 10: delete old tables
|
||||
//if ($oldversion < 2011060300) {
|
||||
//$tables = array('wiki_pages', 'wiki_locks', 'wiki_entries');
|
||||
|
||||
//foreach ($tables as $tablename) {
|
||||
//$table = new xmldb_table($tablename . '_old');
|
||||
//if ($dbman->table_exists($table)) {
|
||||
//$dbman->drop_table($table);
|
||||
//}
|
||||
//}
|
||||
//echo $OUTPUT->notification('Droping old tables', 'notifysuccess');
|
||||
//upgrade_mod_savepoint(true, 2011060300, 'wiki');
|
||||
//}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
<?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
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
function wiki_add_wiki_fields() {
|
||||
global $DB;
|
||||
|
||||
upgrade_set_timeout();
|
||||
$dbman = $DB->get_manager();
|
||||
/// Define table wiki to be created
|
||||
$table = new xmldb_table('wiki');
|
||||
|
||||
// Adding fields to wiki table
|
||||
$wikitable = new xmldb_table('wiki');
|
||||
|
||||
// in MOODLE_20_SABLE branch, summary field is renamed as intro
|
||||
// so we renamed it back to summary to keep upgrade going as moodle 1.9
|
||||
$field = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
|
||||
if ($dbman->field_exists($wikitable, $field)) {
|
||||
$dbman->rename_field($wikitable, $field, 'summary');
|
||||
}
|
||||
$dbman->add_field($wikitable, $field);
|
||||
|
||||
$field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
|
||||
if (!$dbman->field_exists($wikitable, $field)) {
|
||||
$dbman->add_field($wikitable, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('firstpagetitle', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'First Page', null);
|
||||
$dbman->add_field($wikitable, $field);
|
||||
|
||||
$field = new xmldb_field('wikimode', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'collaborative', null);
|
||||
$dbman->add_field($wikitable, $field);
|
||||
|
||||
$field = new xmldb_field('defaultformat', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'creole', null);
|
||||
$dbman->add_field($wikitable, $field);
|
||||
|
||||
$field = new xmldb_field('forceformat', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', null);
|
||||
$dbman->add_field($wikitable, $field);
|
||||
|
||||
$field = new xmldb_field('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
|
||||
$dbman->add_field($wikitable, $field);
|
||||
|
||||
$field = new xmldb_field('editbegin', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
|
||||
$dbman->add_field($wikitable, $field);
|
||||
|
||||
$field = new xmldb_field('editend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', null);
|
||||
$dbman->add_field($wikitable, $field);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Install wiki 2.0 tables
|
||||
*/
|
||||
function wiki_upgrade_install_20_tables() {
|
||||
global $DB;
|
||||
upgrade_set_timeout();
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
/// Define table wiki_subwikis to be created
|
||||
$table = new xmldb_table('wiki_subwikis');
|
||||
|
||||
/// Adding fields to table wiki_subwikis
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('wikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
/// Adding keys to table wiki_subwikis
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('wikiidgroupiduserid', XMLDB_KEY_UNIQUE, array('wikiid', 'groupid', 'userid'));
|
||||
$table->add_key('wikifk', XMLDB_KEY_FOREIGN, array('wikiid'), 'wiki', array('id'));
|
||||
|
||||
/// Conditionally launch create table for wiki_subwikis
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
/// Define table wiki_pages to be created
|
||||
$table = new xmldb_table('wiki_pages');
|
||||
|
||||
/// Adding fields to table wiki_pages
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('subwikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'title');
|
||||
$table->add_field('cachedcontent', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timerendered', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('pageviews', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
/// Adding keys to table wiki_pages
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('subwikititleuser', XMLDB_KEY_UNIQUE, array('subwikiid', 'title', 'userid'));
|
||||
$table->add_key('subwikifk', XMLDB_KEY_FOREIGN, array('subwikiid'), 'wiki_subwiki', array('id'));
|
||||
|
||||
/// Conditionally launch create table for wiki_pages
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
/// Define table wiki_versions to be created
|
||||
$table = new xmldb_table('wiki_versions');
|
||||
|
||||
/// Adding fields to table wiki_versions
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('content', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('contentformat', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'creole');
|
||||
$table->add_field('version', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
/// Adding keys to table wiki_versions
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('pagefk', XMLDB_KEY_FOREIGN, array('pageid'), 'wiki_pages', array('id'));
|
||||
|
||||
/// Conditionally launch create table for wiki_versions
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
/// Define table wiki_synonyms to be created
|
||||
$table = new xmldb_table('wiki_synonyms');
|
||||
|
||||
/// Adding fields to table wiki_synonyms
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('subwikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('pagesynonym', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'Pagesynonym');
|
||||
|
||||
/// Adding keys to table wiki_synonyms
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('pageidsyn', XMLDB_KEY_UNIQUE, array('pageid', 'pagesynonym'));
|
||||
|
||||
/// Conditionally launch create table for wiki_synonyms
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
/// Define table wiki_links to be created
|
||||
$table = new xmldb_table('wiki_links');
|
||||
|
||||
/// Adding fields to table wiki_links
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('subwikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('frompageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('topageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('tomissingpage', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
|
||||
/// Adding keys to table wiki_links
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('frompageidfk', XMLDB_KEY_FOREIGN, array('frompageid'), 'wiki_pages', array('id'));
|
||||
$table->add_key('subwikifk', XMLDB_KEY_FOREIGN, array('subwikiid'), 'wiki_subwiki', array('id'));
|
||||
|
||||
/// Conditionally launch create table for wiki_links
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
/// Define table wiki_locks to be created
|
||||
$table = new xmldb_table('wiki_locks');
|
||||
|
||||
/// Adding fields to table wiki_locks
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('sectionname', XMLDB_TYPE_CHAR, '255', null, null, null, null);
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('lockedat', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
/// Adding keys to table wiki_locks
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
|
||||
/// Conditionally launch create table for wiki_locks
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrating wiki pages history
|
||||
*/
|
||||
function wiki_upgrade_migrate_versions() {
|
||||
global $DB, $CFG, $OUTPUT;
|
||||
require_once($CFG->dirroot . '/mod/wiki/db/migration/lib.php');
|
||||
// need to move the binary data in db
|
||||
$fs = get_file_storage();
|
||||
// select all wiki pages history
|
||||
$sql = "SELECT po.id AS oldpage_id, po.pagename AS oldpage_pagename, po.version, po.flags,
|
||||
po.content, po.author, po.userid AS oldpage_userid, po.created, po.lastmodified, po.refs, po.meta, po.hits, po.wiki,
|
||||
p.id AS newpage_id, p.subwikiid, p.title, p.cachedcontent, p.timecreated, p.timemodified AS newpage_timemodified,
|
||||
p.timerendered, p.userid AS newpage_userid, p.pageviews, p.readonly, e.id AS entry_id, e.wikiid, e.course AS entrycourse,
|
||||
e.groupid, e.userid AS entry_userid, e.pagename AS entry_pagename, e.timemodified AS entry_timemodified,
|
||||
w.id AS wiki_id, w.course AS wiki_course, w.name, w.summary AS summary, w.pagename AS wiki_pagename, w.wtype,
|
||||
w.ewikiprinttitle, w.htmlmode, w.ewikiacceptbinary, w.disablecamelcase, w.setpageflags, w.strippages, w.removepages,
|
||||
w.revertchanges, w.initialcontent, w.timemodified AS wiki_timemodified,
|
||||
cm.id AS cmid
|
||||
FROM {wiki_pages_old} po
|
||||
LEFT OUTER JOIN {wiki_entries_old} e ON e.id = po.wiki
|
||||
LEFT OUTER JOIN {wiki} w ON w.id = e.wikiid
|
||||
LEFT OUTER JOIN {wiki_subwikis} s ON e.groupid = s.groupid AND e.wikiid = s.wikiid AND e.userid = s.userid
|
||||
LEFT OUTER JOIN {wiki_pages} p ON po.pagename = p.title AND p.subwikiid = s.id
|
||||
JOIN {modules} m ON m.name = 'wiki'
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = w.id)";
|
||||
|
||||
$pagesinfo = $DB->get_recordset_sql($sql, array());
|
||||
|
||||
foreach ($pagesinfo as $pageinfo) {
|
||||
upgrade_set_timeout();
|
||||
|
||||
$mimetype = ewiki_mime_magic($pageinfo->content);
|
||||
if (!empty($mimetype)) {
|
||||
// if mimetype is not empty, means this is a file stored in db
|
||||
$context = get_context_instance(CONTEXT_MODULE, $pageinfo->cmid);
|
||||
// clean up file name
|
||||
$filename = clean_param($pageinfo->oldpage_pagename, PARAM_FILE);
|
||||
$filerecord = array('contextid' => $context->id,
|
||||
'component' => 'mod_wiki',
|
||||
'filearea' => 'attachments',
|
||||
'itemid' => $pageinfo->subwikiid,
|
||||
'filepath' => '/',
|
||||
'filename' => $filename,
|
||||
'userid' => $pageinfo->oldpage_userid);
|
||||
if (!$fs->file_exists($context->id, 'mod_wiki', 'attachments', $pageinfo->subwikiid, '/', $pageinfo->pagename)) {
|
||||
$storedfile = $fs->create_file_from_string($filerecord, $pageinfo->content);
|
||||
}
|
||||
|
||||
// replace page content to a link point to the file
|
||||
$pageinfo->content = "<a href='@@PLUGINFILE@@/$filename'>$pageinfo->oldpage_pagename</a>";
|
||||
}
|
||||
|
||||
$oldpage = new StdClass();
|
||||
$oldpage->id = $pageinfo->oldpage_id;
|
||||
$oldpage->pagename = $pageinfo->oldpage_pagename;
|
||||
$oldpage->version = $pageinfo->version;
|
||||
$oldpage->flags = $pageinfo->flags;
|
||||
$oldpage->content = $pageinfo->content;
|
||||
$oldpage->author = $pageinfo->author;
|
||||
$oldpage->userid = $pageinfo->oldpage_userid;
|
||||
$oldpage->created = $pageinfo->created;
|
||||
$oldpage->lastmodified = $pageinfo->lastmodified;
|
||||
$oldpage->refs = $pageinfo->refs;
|
||||
$oldpage->meta = $pageinfo->meta;
|
||||
$oldpage->hits = $pageinfo->hits;
|
||||
$oldpage->wiki = $pageinfo->wiki;
|
||||
|
||||
$page = new StdClass();
|
||||
$page->id = $pageinfo->newpage_id;
|
||||
$page->subwikiid = $pageinfo->subwikiid;
|
||||
$page->title = $pageinfo->title;
|
||||
$page->cachedcontent = $pageinfo->cachedcontent;
|
||||
$page->timecreated = $pageinfo->timecreated;
|
||||
$page->timemodified = $pageinfo->newpage_timemodified;
|
||||
$page->timerendered = $pageinfo->timerendered;
|
||||
$page->userid = $pageinfo->newpage_userid;
|
||||
$page->pageviews = $pageinfo->pageviews;
|
||||
$page->readonly = $pageinfo->readonly;
|
||||
|
||||
$entry = new StdClass();
|
||||
$entry->id = $pageinfo->entry_id;
|
||||
$entry->wikiid = $pageinfo->wikiid;
|
||||
$entry->course = $pageinfo->entrycourse;
|
||||
$entry->groupid = $pageinfo->groupid;
|
||||
$entry->userid = $pageinfo->entry_userid;
|
||||
$entry->pagename = $pageinfo->entry_pagename;
|
||||
$entry->timemodified = $pageinfo->entry_timemodified;
|
||||
|
||||
$wiki = new StdClass();
|
||||
$wiki->id = $pageinfo->wiki_id;
|
||||
$wiki->course = $pageinfo->wiki_course;
|
||||
$wiki->name = $pageinfo->name;
|
||||
$wiki->summary = $pageinfo->summary;
|
||||
$wiki->pagename = $pageinfo->wiki_pagename;
|
||||
$wiki->wtype = $pageinfo->wtype;
|
||||
$wiki->ewikiprinttitle = $pageinfo->ewikiprinttitle;
|
||||
$wiki->htmlmode = $pageinfo->htmlmode;
|
||||
$wiki->ewikiacceptbinary = $pageinfo->ewikiacceptbinary;
|
||||
$wiki->disablecamelcase = $pageinfo->disablecamelcase;
|
||||
$wiki->setpageflags = $pageinfo->setpageflags;
|
||||
$wiki->strippages = $pageinfo->strippages;
|
||||
$wiki->removepages = $pageinfo->removepages;
|
||||
$wiki->revertchanges = $pageinfo->revertchanges;
|
||||
$wiki->initialcontent = $pageinfo->initialcontent;
|
||||
$wiki->timemodified = $pageinfo->wiki_timemodified;
|
||||
|
||||
$version = new StdClass();
|
||||
$version->pageid = $page->id;
|
||||
// convert wiki content to html format
|
||||
$version->content = wiki_ewiki_2_html($entry, $oldpage, $wiki);
|
||||
$version->contentformat = 'html';
|
||||
$version->version = $oldpage->version;
|
||||
$version->timecreated = $oldpage->lastmodified;
|
||||
$version->userid = $oldpage->userid;
|
||||
if ($version->version == 1) {
|
||||
// The oldest version of page in moodle 2.0 is 0 which has empty content
|
||||
// so we need to insert an extra record
|
||||
try {
|
||||
$content = $version->content;
|
||||
$version->version = 0;
|
||||
$version->content = '';
|
||||
$DB->insert_record('wiki_versions', $version);
|
||||
$version->version = 1;
|
||||
$version->content = $content;
|
||||
$DB->insert_record('wiki_versions', $version);
|
||||
} catch (dml_exception $e) {
|
||||
debugging($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$DB->insert_record('wiki_versions', $version);
|
||||
} catch (dml_exception $e) {
|
||||
debugging($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pagesinfo->close();
|
||||
}
|
||||
@@ -38,286 +38,6 @@ function xmldb_workshop_upgrade($oldversion) {
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
//===== 1.9.0 upgrade line ======//
|
||||
|
||||
/**
|
||||
* the following blocks contain all the db/upgrade.php logic from MOODLE_19_STABLE branch
|
||||
* so that it does not matter if we are upgrading from 1.9.0, 1.9.3 or 1.9.whatever
|
||||
*/
|
||||
|
||||
if ($oldversion < 2007101510) {
|
||||
$orphans = $DB->get_records_sql('SELECT wa.id
|
||||
FROM {workshop_assessments} wa
|
||||
LEFT JOIN {workshop_submissions} ws ON wa.submissionid = ws.id
|
||||
WHERE ws.id IS NULL');
|
||||
if (!empty($orphans)) {
|
||||
echo $OUTPUT->notification('Orphaned assessment records found - cleaning...');
|
||||
$DB->delete_records_list('workshop_assessments', 'id', array_keys($orphans));
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2007101510, 'workshop');
|
||||
}
|
||||
|
||||
//===== end of 1.9.0 upgrade line ======//
|
||||
|
||||
/**
|
||||
* Upgrading from workshop 1.9.x - big things going to happen now...
|
||||
* The migration procedure is divided into smaller chunks using incremental
|
||||
* versions 2009102900, 2009102901, 2009102902 etc. The day zero of the new
|
||||
* workshop 2.0 is version 2009103000 since when the upgrade code is maintained.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Migration from 1.9 - step 1 - rename old tables
|
||||
*/
|
||||
if ($oldversion < 2009102901) {
|
||||
echo $OUTPUT->notification('Renaming old workshop module tables', 'notifysuccess');
|
||||
foreach (array('workshop', 'workshop_elements', 'workshop_rubrics', 'workshop_submissions', 'workshop_assessments',
|
||||
'workshop_grades', 'workshop_comments', 'workshop_stockcomments') as $tableorig) {
|
||||
$tablearchive = $tableorig . '_old';
|
||||
if ($dbman->table_exists($tableorig)) {
|
||||
$dbman->rename_table(new xmldb_table($tableorig), $tablearchive);
|
||||
}
|
||||
// append a new field 'newplugin' into every archived table. In this field, the name of the subplugin
|
||||
// who adopted the record during the migration is stored. null value means the record is not migrated yet
|
||||
$table = new xmldb_table($tablearchive);
|
||||
$field = new xmldb_field('newplugin', XMLDB_TYPE_CHAR, '28', null, null, null, null);
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
// append a new field 'newid' in every archived table. null value means the record was not migrated yet.
|
||||
// the field will hold the new id of the migrated record
|
||||
$table = new xmldb_table($tablearchive);
|
||||
$field = new xmldb_field('newid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2009102901, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration from 1.9 - step 2 - create new workshop core tables
|
||||
*/
|
||||
if ($oldversion < 2009102902) {
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
echo $OUTPUT->notification('Preparing new workshop module tables', 'notifysuccess');
|
||||
workshop_upgrade_prepare_20_tables();
|
||||
upgrade_mod_savepoint(true, 2009102902, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration from 1.9 - step 3 - migrate workshop instances
|
||||
*/
|
||||
if ($oldversion < 2009102903) {
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
echo $OUTPUT->notification('Copying workshop core data', 'notifysuccess');
|
||||
workshop_upgrade_module_instances();
|
||||
upgrade_mod_savepoint(true, 2009102903, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration from 1.9 - step 4 - migrate submissions
|
||||
*/
|
||||
if ($oldversion < 2009102904) {
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
echo $OUTPUT->notification('Copying submissions', 'notifysuccess');
|
||||
workshop_upgrade_submissions();
|
||||
upgrade_mod_savepoint(true, 2009102904, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration from 1.9 - step 5 - migrate submission attachment to new file storage
|
||||
*/
|
||||
if ($oldversion < 2009102905) {
|
||||
// $filearea = "$workshop->course/$CFG->moddata/workshop/$submission->id";
|
||||
$fs = get_file_storage();
|
||||
$from = 'FROM {workshop_submissions} s
|
||||
JOIN {workshop} w ON (w.id = s.workshopid)
|
||||
JOIN {modules} m ON (m.name = :modulename)
|
||||
JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = w.id)
|
||||
WHERE s.attachment <> 1';
|
||||
$params = array('modulename' => 'workshop');
|
||||
$count = $DB->count_records_sql('SELECT COUNT(s.id) ' . $from, $params);
|
||||
$rs = $DB->get_recordset_sql('SELECT s.id, s.authorid, s.workshopid, cm.course, cm.id AS cmid ' .
|
||||
$from . ' ORDER BY cm.course, w.id', $params);
|
||||
$pbar = new progress_bar('migrateworkshopsubmissions', 500, true);
|
||||
$i = 0;
|
||||
foreach ($rs as $submission) {
|
||||
$i++;
|
||||
upgrade_set_timeout(60); // set up timeout, may also abort execution
|
||||
$pbar->update($i, $count, "Migrating workshop submissions - $i/$count");
|
||||
|
||||
$filedir = "$CFG->dataroot/$submission->course/$CFG->moddata/workshop/$submission->id";
|
||||
if ($files = get_directory_list($filedir, '', false)) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $submission->cmid);
|
||||
foreach ($files as $filename) {
|
||||
$filepath = $filedir . '/' . $filename;
|
||||
if (!is_readable($filepath)) {
|
||||
echo $OUTPUT->notification('File not readable: ' . $filepath);
|
||||
continue;
|
||||
}
|
||||
$filename = clean_param($filename, PARAM_FILE);
|
||||
if ($filename === '') {
|
||||
echo $OUTPUT->notification('Unsupported submission filename: ' . $filepath);
|
||||
continue;
|
||||
}
|
||||
if (! $fs->file_exists($context->id, 'mod_workshop', 'submission_attachment', $submission->id, '/', $filename)) {
|
||||
$filerecord = array('contextid' => $context->id,
|
||||
'component' => 'mod_workshop',
|
||||
'filearea' => 'submission_attachment',
|
||||
'itemid' => $submission->id,
|
||||
'filepath' => '/',
|
||||
'filename' => $filename,
|
||||
'userid' => $submission->authorid);
|
||||
if ($fs->create_file_from_pathname($filerecord, $filepath)) {
|
||||
$submission->attachment = 1;
|
||||
$DB->update_record('workshop_submissions', $submission);
|
||||
unlink($filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove dirs if empty
|
||||
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/workshop/$submission->id");
|
||||
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/workshop");
|
||||
@rmdir("$CFG->dataroot/$submission->course/$CFG->moddata");
|
||||
@rmdir("$CFG->dataroot/$submission->course");
|
||||
}
|
||||
$rs->close();
|
||||
upgrade_mod_savepoint(true, 2009102905, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Migration from 1.9 - step 6 - migrate assessments
|
||||
*/
|
||||
if ($oldversion < 2009102906) {
|
||||
require_once(dirname(__FILE__) . '/upgradelib.php');
|
||||
echo $OUTPUT->notification('Copying assessments', 'notifysuccess');
|
||||
workshop_upgrade_assessments();
|
||||
upgrade_mod_savepoint(true, 2009102906, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* End of migration from 1.9
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add 'published' field into workshop_submissions
|
||||
*/
|
||||
if ($oldversion < 2009121800) {
|
||||
$table = new xmldb_table('workshop_submissions');
|
||||
$field = new xmldb_field('published', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '0', 'timegraded');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2009121800, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'evaluation' field into workshop
|
||||
*/
|
||||
if ($oldversion < 2010070700) {
|
||||
$table = new xmldb_table('workshop');
|
||||
$field = new xmldb_field('evaluation', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, 'strategy');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2010070700, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of the new 'evaluation' field to 'best', there is no alternative at the moment
|
||||
*/
|
||||
if ($oldversion < 2010070701) {
|
||||
$DB->set_field('workshop', 'evaluation', 'best');
|
||||
upgrade_mod_savepoint(true, 2010070701, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'late' field into workshop_submissions
|
||||
*/
|
||||
if ($oldversion < 2010072300) {
|
||||
$table = new xmldb_table('workshop_submissions');
|
||||
$field = new xmldb_field('late', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'published');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2010072300, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create legacy _old tables to sync install.xml and real database
|
||||
*
|
||||
* In most cases these tables already exists because they were created during 1.9->2.0 migration
|
||||
* This step is just for those site that were installed from vanilla 2.0 and these _old tables
|
||||
* were not created.
|
||||
* Note that these tables will be dropped again later in 2.x
|
||||
*/
|
||||
if ($oldversion < 2010111200) {
|
||||
foreach (array('workshop', 'workshop_elements', 'workshop_rubrics', 'workshop_submissions', 'workshop_assessments',
|
||||
'workshop_grades', 'workshop_comments', 'workshop_stockcomments') as $tableorig) {
|
||||
$tablearchive = $tableorig . '_old';
|
||||
if (!$dbman->table_exists($tablearchive)) {
|
||||
$dbman->install_one_table_from_xmldb_file($CFG->dirroot.'/mod/workshop/db/install.xml', $tablearchive);
|
||||
}
|
||||
}
|
||||
upgrade_mod_savepoint(true, 2010111200, 'workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the course_module integrity - see MDL-26312 for details
|
||||
*
|
||||
* Because of a bug in Workshop upgrade code, multiple workshop course_modules can
|
||||
* potentially point to a single workshop instance. The chance is pretty low as in most cases,
|
||||
* the upgrade failed. But under certain circumstances, workshop could be upgraded with
|
||||
* this data integrity issue. We want to detect it now and let the admin know.
|
||||
*/
|
||||
if ($oldversion < 2011021100) {
|
||||
$sql = "SELECT cm.id, cm.course, cm.instance
|
||||
FROM {course_modules} cm
|
||||
WHERE cm.module IN (SELECT id
|
||||
FROM {modules}
|
||||
WHERE name = ?)";
|
||||
$rs = $DB->get_recordset_sql($sql, array('workshop'));
|
||||
$map = array(); // returned stdClasses by instance id
|
||||
foreach ($rs as $cm) {
|
||||
$map[$cm->instance][$cm->id] = $cm;
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
$problems = array();
|
||||
foreach ($map as $instanceid => $cms) {
|
||||
if (count($cms) > 1) {
|
||||
$problems[] = 'workshop instance ' . $instanceid . ' referenced by course_modules ' . implode(', ', array_keys($cms));
|
||||
}
|
||||
}
|
||||
if ($problems) {
|
||||
echo $OUTPUT->notification('¡Ay, caramba! Data integrity corruption has been detected in your workshop ' . PHP_EOL .
|
||||
'module database tables. This might be caused by a bug in workshop upgrade code. ' . PHP_EOL .
|
||||
'Please report this issue immediately in workshop module support forum at ' . PHP_EOL .
|
||||
'http://moodle.org so that we can help to fix this problem. Please copy and keep ' . PHP_EOL .
|
||||
'following information for future reference:');
|
||||
foreach ($problems as $problem) {
|
||||
echo $OUTPUT->notification($problem);
|
||||
upgrade_log(UPGRADE_LOG_NOTICE, 'mod_workshop', 'course_modules integrity problem', $problem);
|
||||
}
|
||||
}
|
||||
|
||||
unset($problems);
|
||||
unset($map);
|
||||
upgrade_mod_savepoint(true, 2011021100, 'workshop');
|
||||
}
|
||||
|
||||
// Moodle v2.1.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
/**
|
||||
* Fix the eventually corrupted workshop table id sequence
|
||||
*/
|
||||
if ($oldversion < 2011110400) {
|
||||
$dbman->reset_sequence('workshop');
|
||||
upgrade_mod_savepoint(true, 2011110400, 'workshop');
|
||||
}
|
||||
|
||||
// Moodle v2.2.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
@@ -1,469 +0,0 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Functions used by some stages in workshop db/upgrade.php
|
||||
*
|
||||
* @package mod
|
||||
* @subpackage workshop
|
||||
* @copyright 2009 David Mudrak <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prepares the inital workshop 2.0 core tables
|
||||
*/
|
||||
function workshop_upgrade_prepare_20_tables() {
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
if (!$dbman->table_exists('workshop')) {
|
||||
$table = new xmldb_table('workshop');
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('intro', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('introformat', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('instructauthors', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('instructauthorsformat', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('instructreviewers', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('instructreviewersformat', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('phase', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('useexamples', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('usepeerassessment', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('useselfassessment', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('grade', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, null, null, '80');
|
||||
$table->add_field('gradinggrade', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, null, null, '20');
|
||||
$table->add_field('strategy', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('gradedecimals', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('nattachments', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('latesubmissions', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('maxbytes', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '100000');
|
||||
$table->add_field('examplesmode', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('submissionstart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('submissionend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('assessmentstart', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('assessmentend', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('course_fk', XMLDB_KEY_FOREIGN, array('course'), 'course', array('id'));
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
if (!$dbman->table_exists('workshop_submissions')) {
|
||||
$table = new xmldb_table('workshop_submissions');
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('workshopid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('example', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('authorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('content', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('contentformat', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('contenttrust', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('attachment', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('grade', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('gradeover', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('gradeoverby', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('feedbackauthor', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('feedbackauthorformat', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('timegraded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('workshop_fk', XMLDB_KEY_FOREIGN, array('workshopid'), 'workshop', array('id'));
|
||||
$table->add_key('overriddenby_fk', XMLDB_KEY_FOREIGN, array('gradeoverby'), 'user', array('id'));
|
||||
$table->add_key('author_fk', XMLDB_KEY_FOREIGN, array('authorid'), 'user', array('id'));
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
if (!$dbman->table_exists('workshop_assessments')) {
|
||||
$table = new xmldb_table('workshop_assessments');
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('submissionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('reviewerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('weight', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('grade', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('gradinggrade', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('gradinggradeover', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('gradinggradeoverby', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('feedbackauthor', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('feedbackauthorformat', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_field('feedbackreviewer', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('feedbackreviewerformat', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0');
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('submission_fk', XMLDB_KEY_FOREIGN, array('submissionid'), 'workshop_submissions', array('id'));
|
||||
$table->add_key('overriddenby_fk', XMLDB_KEY_FOREIGN, array('gradinggradeoverby'), 'user', array('id'));
|
||||
$table->add_key('reviewer_fk', XMLDB_KEY_FOREIGN, array('reviewerid'), 'user', array('id'));
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
if (!$dbman->table_exists('workshop_grades')) {
|
||||
$table = new xmldb_table('workshop_grades');
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('assessmentid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('strategy', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('dimensionid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('grade', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('peercomment', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
|
||||
$table->add_field('peercommentformat', XMLDB_TYPE_INTEGER, '3', null, null, null, '0');
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('assessment_fk', XMLDB_KEY_FOREIGN, array('assessmentid'), 'workshop_assessments', array('id'));
|
||||
$table->add_key('formfield_uk', XMLDB_KEY_UNIQUE, array('assessmentid', 'strategy', 'dimensionid'));
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
if (!$dbman->table_exists('workshop_aggregations')) {
|
||||
$table = new xmldb_table('workshop_aggregations');
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('workshopid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('gradinggrade', XMLDB_TYPE_NUMBER, '10, 5', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_field('timegraded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
|
||||
$table->add_key('workshop_fk', XMLDB_KEY_FOREIGN, array('workshopid'), 'workshop', array('id'));
|
||||
$table->add_key('user_fk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
|
||||
$table->add_key('workshopuser', XMLDB_KEY_UNIQUE, array('workshopid', 'userid'));
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the records from workshop_old into workshop table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function workshop_upgrade_module_instances() {
|
||||
global $CFG, $DB;
|
||||
|
||||
upgrade_set_timeout();
|
||||
$moduleid = $DB->get_field('modules', 'id', array('name' => 'workshop'), MUST_EXIST);
|
||||
$rs = $DB->get_recordset_select('workshop_old', 'newid IS NULL', null, 'id');
|
||||
foreach ($rs as $old) {
|
||||
$new = workshop_upgrade_transform_instance($old);
|
||||
$new->id = $old->id;
|
||||
$DB->import_record('workshop', $new);
|
||||
$DB->set_field('workshop_old', 'newplugin', 'workshop', array('id' => $old->id));
|
||||
$DB->set_field('workshop_old', 'newid', $new->id, array('id' => $old->id));
|
||||
}
|
||||
$rs->close();
|
||||
$dbman = $DB->get_manager();
|
||||
$dbman->reset_sequence('workshop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a record containing data from 1.9 workshop table, returns object containing data as should be saved in 2.0 workshop table
|
||||
*
|
||||
* @param stdClass $old record from 1.9 workshop table
|
||||
* @return stdClass
|
||||
*/
|
||||
function workshop_upgrade_transform_instance(stdClass $old) {
|
||||
global $CFG;
|
||||
require_once(dirname(dirname(__FILE__)) . '/locallib.php');
|
||||
|
||||
$new = new stdClass();
|
||||
$new->course = $old->course;
|
||||
$new->name = $old->name;
|
||||
$new->intro = $old->description;
|
||||
$new->introformat = $old->format;
|
||||
$new->nattachments = $old->nattachments;
|
||||
$new->maxbytes = $old->maxbytes;
|
||||
$new->grade = $old->grade;
|
||||
$new->gradinggrade = $old->gradinggrade;
|
||||
$new->phase = workshop::PHASE_CLOSED;
|
||||
$new->timemodified = time();
|
||||
if ($old->ntassessments > 0) {
|
||||
$new->useexamples = 1;
|
||||
} else {
|
||||
$new->useexamples = 0;
|
||||
}
|
||||
$new->usepeerassessment = 1;
|
||||
$new->useselfassessment = $old->includeself;
|
||||
switch ($old->gradingstrategy) {
|
||||
case 0: // 'notgraded' - renamed
|
||||
$new->strategy = 'comments';
|
||||
break;
|
||||
case 1: // 'accumulative'
|
||||
$new->strategy = 'accumulative';
|
||||
break;
|
||||
case 2: // 'errorbanded' - renamed
|
||||
$new->strategy = 'numerrors';
|
||||
break;
|
||||
case 3: // 'criterion' - will be migrated into 'rubric'
|
||||
$new->strategy = 'rubric';
|
||||
break;
|
||||
case 4: // 'rubric'
|
||||
$new->strategy = 'rubric';
|
||||
break;
|
||||
}
|
||||
if ($old->submissionstart < $old->submissionend) {
|
||||
$new->submissionstart = $old->submissionstart;
|
||||
$new->submissionend = $old->submissionend;
|
||||
}
|
||||
if ($old->assessmentstart < $old->assessmentend) {
|
||||
$new->assessmentstart = $old->assessmentstart;
|
||||
$new->assessmentend = $old->assessmentend;
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies records from workshop_submissions_old into workshop_submissions. Can be called after all workshop module instances
|
||||
* were correctly migrated and new ids are filled in workshop_old
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function workshop_upgrade_submissions() {
|
||||
global $CFG, $DB;
|
||||
|
||||
upgrade_set_timeout();
|
||||
|
||||
// list of teachers in every workshop: array of (int)workshopid => array of (int)userid => notused
|
||||
$workshopteachers = array();
|
||||
|
||||
$rs = $DB->get_recordset_select('workshop_submissions_old', 'newid IS NULL');
|
||||
foreach ($rs as $old) {
|
||||
if (!isset($workshopteachers[$old->workshopid])) {
|
||||
$cm = get_coursemodule_from_instance('workshop', $old->workshopid, 0, false, MUST_EXIST);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$workshopteachers[$old->workshopid] = get_users_by_capability($context, 'mod/workshop:manage', 'u.id');
|
||||
}
|
||||
$new = workshop_upgrade_transform_submission($old, $old->workshopid, $workshopteachers[$old->workshopid]);
|
||||
$newid = $DB->insert_record('workshop_submissions', $new, true, true);
|
||||
$DB->set_field('workshop_submissions_old', 'newplugin', 'submissions', array('id' => $old->id));
|
||||
$DB->set_field('workshop_submissions_old', 'newid', $newid, array('id' => $old->id));
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a record from 1.x workshop_submissions_old, returns data for 2.0 workshop_submissions
|
||||
*
|
||||
* @param stdClass $old
|
||||
* @param int $newworkshopid new workshop id
|
||||
* @param array $legacyteachers $userid => notused the list of legacy workshop teachers for the submission's workshop
|
||||
* @return stdClass
|
||||
*/
|
||||
function workshop_upgrade_transform_submission(stdClass $old, $newworkshopid, array $legacyteachers) {
|
||||
|
||||
$new = new stdclass(); // new submission record to be returned
|
||||
$new->workshopid = $newworkshopid;
|
||||
|
||||
if (isset($legacyteachers[$old->userid])) {
|
||||
// the author of the submission was teacher = had mod/workshop:manage. this is the only way how we can
|
||||
// recognize the submission should be treated as example submission (ach jo...)
|
||||
$new->example = 1;
|
||||
} else {
|
||||
$new->example = 0;
|
||||
}
|
||||
|
||||
$new->authorid = $old->userid;
|
||||
$new->timecreated = $old->timecreated;
|
||||
$new->timemodified = $old->timecreated;
|
||||
$new->title = $old->title;
|
||||
$new->content = $old->description;
|
||||
$new->contentformat = FORMAT_HTML;
|
||||
$new->contenttrust = 0;
|
||||
$new->published = 0;
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of new submission instances ids
|
||||
*
|
||||
* @return array (int)oldid => (int)newid
|
||||
*/
|
||||
function workshop_upgrade_submission_id_mappings() {
|
||||
global $DB;
|
||||
|
||||
$oldrecords = $DB->get_records('workshop_submissions_old', null, 'id', 'id,newid');
|
||||
$newids = array();
|
||||
foreach ($oldrecords as $oldid => $oldrecord) {
|
||||
if ($oldrecord->id and $oldrecord->newid) {
|
||||
$newids[$oldid] = $oldrecord->newid;
|
||||
}
|
||||
}
|
||||
return $newids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of teacherweight values as were set in legacy workshop instances
|
||||
*
|
||||
* @return array (int)oldid => (int)teacherweight
|
||||
*/
|
||||
function workshop_upgrade_legacy_teacher_weights() {
|
||||
global $DB;
|
||||
|
||||
$oldrecords = $DB->get_records('workshop_old', null, 'id', 'id,teacherweight');
|
||||
$weights = array();
|
||||
foreach ($oldrecords as $oldid => $oldrecord) {
|
||||
if (is_null($oldrecord->teacherweight)) {
|
||||
$weights[$oldid] = 1;
|
||||
} else {
|
||||
$weights[$oldid] = $oldrecord->teacherweight;
|
||||
}
|
||||
}
|
||||
return $weights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all assessments from workshop_assessments_old to workshop_assessments. Can be called after all
|
||||
* submissions were migrated.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function workshop_upgrade_assessments() {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
|
||||
upgrade_set_timeout();
|
||||
|
||||
$newsubmissionids = workshop_upgrade_submission_id_mappings();
|
||||
$teacherweights = workshop_upgrade_legacy_teacher_weights();
|
||||
|
||||
// list of teachers in every workshop: array of (int)workshopid => array of (int)userid => notused
|
||||
$workshopteachers = array();
|
||||
|
||||
// get the list of ids of the new example submissions
|
||||
$examplesubmissions = $DB->get_records('workshop_submissions', array('example' => 1), '', 'id');
|
||||
|
||||
$rs = $DB->get_recordset_select('workshop_assessments_old', 'newid IS NULL');
|
||||
foreach ($rs as $old) {
|
||||
if (!isset($workshopteachers[$old->workshopid])) {
|
||||
$cm = get_coursemodule_from_instance('workshop', $old->workshopid, 0, false, MUST_EXIST);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$workshopteachers[$old->workshopid] = get_users_by_capability($context, 'mod/workshop:manage', 'u.id');
|
||||
}
|
||||
$ofexample = isset($examplesubmissions[$newsubmissionids[$old->submissionid]]);
|
||||
$new = workshop_upgrade_transform_assessment($old, $newsubmissionids[$old->submissionid],
|
||||
$workshopteachers[$old->workshopid], $teacherweights[$old->workshopid], $ofexample);
|
||||
$newid = $DB->insert_record('workshop_assessments', $new, true, true);
|
||||
$DB->set_field('workshop_assessments_old', 'newplugin', 'assessments', array('id' => $old->id));
|
||||
$DB->set_field('workshop_assessments_old', 'newid', $newid, array('id' => $old->id));
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a record from workshop_assessments_old, returns record to be stored in workshop_assessment
|
||||
*
|
||||
* @param stdClass $old record from workshop_assessments_old,
|
||||
* @param int $newsubmissionid new submission id
|
||||
* @param array $legacyteachers (int)userid => notused the list of legacy workshop teachers for the submission's workshop
|
||||
* @param int $legacyteacherweight weight of teacher's assessment in legacy workshop
|
||||
* @param bool $ofexample is this the assessment of an example submission?
|
||||
* @return stdClass
|
||||
*/
|
||||
function workshop_upgrade_transform_assessment(stdClass $old, $newsubmissionid, array $legacyteachers, $legacyteacherweight, $ofexample) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
|
||||
$new = new stdclass();
|
||||
$new->submissionid = $newsubmissionid;
|
||||
$new->reviewerid = $old->userid;
|
||||
|
||||
if ($ofexample) {
|
||||
// this is the assessment of an example submission
|
||||
if (isset($legacyteachers[$old->userid])) {
|
||||
// this is probably the reference assessment of the example submission
|
||||
$new->weight = 1;
|
||||
} else {
|
||||
$new->weight = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (isset($legacyteachers[$old->userid])) {
|
||||
$new->weight = $legacyteacherweight;
|
||||
} else {
|
||||
$new->weight = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($old->grade < 0) {
|
||||
// in workshop 1.x, this is just allocated assessment that has not been touched yet, having timecreated one year in the future :-/
|
||||
$new->timecreated = time();
|
||||
} else {
|
||||
$new->grade = grade_floatval($old->grade);
|
||||
if ($old->teachergraded) {
|
||||
$new->gradinggradeover = grade_floatval($old->gradinggrade);
|
||||
} else {
|
||||
$new->gradinggrade = grade_floatval($old->gradinggrade);
|
||||
}
|
||||
$new->feedbackauthor = $old->generalcomment;
|
||||
$new->feedbackauthorformat = FORMAT_HTML;
|
||||
$new->feedbackreviewer = $old->teachercomment;
|
||||
$new->feedbackreviewerformat = FORMAT_HTML;
|
||||
$new->timecreated = $old->timecreated;
|
||||
$new->timemodified = $old->timegraded;
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of new assessment ids
|
||||
*
|
||||
* @return array (int)oldid => (int)newid
|
||||
*/
|
||||
function workshop_upgrade_assessment_id_mappings() {
|
||||
global $DB;
|
||||
|
||||
$oldrecords = $DB->get_records('workshop_assessments_old', null, 'id', 'id,newid');
|
||||
$newids = array();
|
||||
foreach ($oldrecords as $oldid => $oldrecord) {
|
||||
if ($oldrecord->id and $oldrecord->newid) {
|
||||
$newids[$oldid] = $oldrecord->newid;
|
||||
}
|
||||
}
|
||||
return $newids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of new element (dimension) ids
|
||||
*
|
||||
* @param string $strategy the name of strategy subplugin that the element was migrated into
|
||||
* @return array (int)workshopid => array (int)elementno => stdclass ->(int)newid {->(string)type} {->(int)maxscore}
|
||||
*/
|
||||
function workshop_upgrade_element_id_mappings($strategy) {
|
||||
global $DB;
|
||||
|
||||
$oldrecords = $DB->get_records('workshop_elements_old', array('newplugin' => $strategy),
|
||||
'workshopid,elementno', 'id,workshopid,elementno,scale,maxscore,newid');
|
||||
$newids = array();
|
||||
foreach ($oldrecords as $old) {
|
||||
if (!isset($newids[$old->workshopid])) {
|
||||
$newids[$old->workshopid] = array();
|
||||
}
|
||||
$info = new stdclass();
|
||||
$info->newid = $old->newid;
|
||||
if ($strategy == 'accumulative') {
|
||||
if ($old->scale >= 0 and $old->scale <= 6) {
|
||||
$info->type = 'scale';
|
||||
} else {
|
||||
$info->type = 'value';
|
||||
}
|
||||
}
|
||||
if ($strategy == 'rubric_levels') {
|
||||
$info->maxscore = $old->maxscore;
|
||||
}
|
||||
$newids[$old->workshopid][$old->elementno] = $info;
|
||||
}
|
||||
return $newids;
|
||||
}
|
||||
Reference in New Issue
Block a user