iMath) - Computer Science Dep. of IME-USP (Brazil) * * License * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * * @param $oldversion Number of the old version. */ require_once ($CFG->dirroot . '/mod/iassign/locallib.php'); function xmldb_iassign_upgrade ($oldversion) { global $CFG, $DB, $USER; $dbman = $DB->get_manager(); if ($oldversion < 2014012100) { // Define field and index in iLM table to be added $table = new xmldb_table('iassign_ilm'); $index_name = new xmldb_index('name'); $index_name->set_attributes(XMLDB_INDEX_UNIQUE, array('name')); if ($dbman->index_exists($table, $index_name)) { $dbman->drop_index($table, $index_name, $continue = true, $feedback = true); } $index_name_version = new xmldb_index('name_version'); $index_name_version->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'version')); if (!$dbman->index_exists($table, $index_name_version)) { $dbman->add_index($table, $index_name_version, $continue = true, $feedback = true); } // Fix field name in ilm table to be added. $table = new xmldb_table('iassign_ilm'); $field_height = new xmldb_field('heigth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '600', 'width'); if ($dbman->field_exists($table, $field_height)) $dbman->rename_field($table, $field_height, 'height'); // Define fields in iassign table to be added. $table = new xmldb_table('iassign'); $field_intro = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'name'); if (!$dbman->field_exists($table, $field_intro)) $dbman->add_field($table, $field_intro); $field_introformat = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro'); if (!$dbman->field_exists($table, $field_introformat)) $dbman->add_field($table, $field_introformat); $field_grade = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, '0', 'activity_group'); if (!$dbman->field_exists($table, $field_grade)) $dbman->add_field($table, $field_grade); $field_timeavailable = new xmldb_field('timeavailable', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'grade'); if (!$dbman->field_exists($table, $field_timeavailable)) $dbman->add_field($table, $field_timeavailable); $field_timedue = new xmldb_field('timedue', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeavailable'); if (!$dbman->field_exists($table, $field_timedue)) $dbman->add_field($table, $field_timedue); $field_preventlate = new xmldb_field('preventlate', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '1', 'timedue'); if (!$dbman->field_exists($table, $field_preventlate)) $dbman->add_field($table, $field_preventlate); $field_test = new xmldb_field('test', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', 'preventlate'); if (!$dbman->field_exists($table, $field_test)) $dbman->add_field($table, $field_test); $field_max_experiment = new xmldb_field('max_experiment', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'test'); if (!$dbman->field_exists($table, $field_max_experiment)) $dbman->add_field($table, $field_max_experiment); if (!$dbman->table_exists($table)) { $field_id = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE); $field_time = new xmldb_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); $field_userid = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'time'); $field_ip = new xmldb_field('ip', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'userid'); $field_course = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ip'); $field_cmid = new xmldb_field('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'course'); $field_ilmid = new xmldb_field('ilmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'cmid'); $field_action = new xmldb_field('action', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'ilmid'); $field_info = new xmldb_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'action'); $field_language = new xmldb_field('language', XMLDB_TYPE_CHAR, '10', null, null, null, null, 'info'); $field_user_agent = new xmldb_field('user_agent', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'language'); $field_javascript = new xmldb_field('javascript', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'user_agent'); $field_java = new xmldb_field('java', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'javascript'); $key = new xmldb_key('primary'); $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'), null, null); $index = new xmldb_index('course'); $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course')); $table->addField($field_id); $table->addField($field_time); $table->addField($field_userid); $table->addField($field_ip); $table->addField($field_course); $table->addField($field_cmid); $table->addField($field_ilmid); $table->addField($field_action); $table->addField($field_info); $table->addField($field_language); $table->addField($field_user_agent); $table->addField($field_javascript); $table->addField($field_java); $table->addKey($key); $table->addIndex($index); $status = $dbman->create_table($table); } // if (!$dbman->table_exists($table)) // Now update Moodle table '*_files' related to the iAssign: insert new field 'filearea' $fs = get_file_storage(); $is_delete = true; $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/"; // All iAssign 'exercises' must get the label 'exercise' $exercise_files = $DB->get_records('files', array("component" => "mod_iassign", "filearea" => "activity")); foreach ($exercise_files as $exercise_file) { $exercise_file->filearea = "exercise"; $DB->update_record('files', $exercise_file); } // All iAssign iLM (usually 'JAR package') must get the label 'activity' $activity_files = $DB->get_records('files', array("component" => "mod_iassign", "filearea" => "ilm")); foreach ($activity_files as $activity_file) { $activity_file->filearea = "activity"; $DB->update_record('files', $activity_file); } // iAssign savepoint reached upgrade_mod_savepoint(true, 2014012100, 'iassign'); } // if ($oldversion < 2014012100) if ($oldversion < 2017021900) { // update to migrate from 2016021300 to 2017021900 (2.2.00) // iassign_ilm : id; name; version; description; url; extension; parent; file_jar; file_class; width; height; enable; timemodified; author; timecreated; evaluate $count_iassign_ilm = $DB->count_records_sql('SELECT COUNT(id) FROM {iassign_ilm}'); // count the number of existing iLM in table '*_iassign_ilm' if ($count_iassign_ilm>0) { // Insert new iLM: iVProgH5 (package in HTML5 technology) // Insert an entry in the Moodle table '*_files' $context = context_system::instance(); $file_ilm = array( 'userid' => $USER->id, // ID of context 'contextid' => $context->id, // ID of context 'component' => 'mod_iassign', // usually = table name 'filearea' => 'ilm', // in table '*_files' all iAssign exercises will have 'filearea="exercise"' and all iLM must be 'ilm' 'itemid' => 0, 'filepath' => '/iassign/ilm/', // any path beginning and ending in / 'filename' => "ivprog-html/main.html"); // any filename: use the starting point of iVProgH5 // Now update Moodle table '*_files' related to the iAssign: insert new field 'filearea' $fs = get_file_storage(); $is_delete = true; $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/"; //TODO iLM_HTML5 : What model to implement to HTML5? //TODO 1. The first version of iLM HTML5 in '/var/www/html/moodle/mod/iassign/ilm/ilm-nome' and others in '/var/moodledata/filedir/'? //TODO 2. Inserting new iLM HTML5 by ZIP file => explode it and register in '/var/moodledata/filedir/'? // Create file using the content: the file information is inserted in the Moodle table '*_files' // The real file will be registered in Moodle data (default '/var/moodledata/filedir/xx/yy' - 'xxyy' is the first 4 char in '*_files.contenthash') //TODO Keep this even change the model to not insert iLM HTML5 (need this object to connect with '*_iassign_ilm' bellow) $file_ilm = $fs->create_file_from_string($file_ilm, file_get_contents($ilm_path . "ivprog-html/main.html")); if ($file_ilm) $is_delete &= @unlink($ilm_path . "ivprog-html"); // Insert an entry in iAssign table '*_iassign_ilm' $newentry = new stdClass(); $newentry->name = 'iVProgH5'; $newentry->url = 'http://www.matematica.br/ivprogh5'; $newentry->version = '0.1.0'; $newentry->description = '{"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}'; $newentry->extension = 'ivph'; $newentry->file_jar = 'iVProgH5'; // to JAR this is the '*_files.id' correponding to the iLM storaged in '/var/moodledata/filedir/' $newentry->file_class = 'ivprog-html/main.html'; $newentry->width = 800; $newentry->height = 700; $newentry->enable = 1; $newentry->timemodified = time(); $newentry->author = $USER->id; $newentry->timecreated = time(); $newentry->evaluate = 1; // $DB->insert_records('iassign_ilm', $newentry); $newentry->id = $DB->insert_record("iassign_ilm", $newentry); // iAssign savepoint reached upgrade_mod_savepoint(true, 2017021900, 'iassign'); } // if ($count_iassign_ilm>0) } // if ($oldversion < 2017021900) // log event ----------------------------------------------------- if (class_exists('plugin_manager')) $pluginman = plugin_manager::instance(); else $pluginman = core_plugin_manager::instance(); $plugins = $pluginman->get_plugins(); iassign_log::add_log('upgrade', 'version: ' . $plugins['mod']['iassign']->versiondisk); // log event ----------------------------------------------------- return true; }