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/1.0.20200221/ivprog/index.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 = 'iVProg'; $newentry->url = 'http://www.matematica.br/ivprog'; $newentry->version = '1.0.20200221'; $newentry->description = '{"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}'; $newentry->extension = 'ivph'; $newentry->file_jar = 'iVProg/1.0.20200221/ivprog/'; // to JAR this is the '*_files.id' correponding to the iLM storaged in '/var/moodledata/filedir/' $newentry->file_class = 'index.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) if ($oldversion < 2017120100) { // last one: 2017042800 from 2017/02/19 // Create new field 'type', putting 'Java' if JAR and 'HTML5' if HTML5 // Update fields 'file_jar, file_class' of iLM iVProgH5 (from 'iVProgH5, ivprog-html/main.html' to 'ilm/ivprog-html/, main.html' //--- // Define new field in iassign table to be added: type varchar(20) in { 'Java' 'HTML5' } $table = new xmldb_table('iassign_ilm'); $new_field_type = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, null, null, null, 'version'); // after field 'version' if (!$dbman->field_exists($table, $new_field_type)) $dbman->add_field($table, $new_field_type); //--- // All iAssign iLM (usually 'JAR package') must get the type 'Java' $list_of_ilm_installed = $DB->get_records('iassign_ilm'); foreach ($list_of_ilm_installed as $ilm_installed) { $ilm_name = strtolower($ilm_installed->name); if ($ilm_name=="ivprogh5" || $ilm_name=="ifractions" || $ilm_name=="fractions") { // if it is 'iVProgH5' (perhaps 'iFractions' already installed?) $ilm_installed->type = "HTML5"; // it is HTML5 $file_jar = strtolower($ilm_installed->file_jar); if ($ilm_name=="ivprogh5" && $file_jar=="ivprogh5") { // fields 'file_jar' and 'file_class' must have: 'ilm/ivprog-html/' and 'main.html' $ilm_installed->file_jar = "ilm/ivprog-html/"; // iVProgH5 ivprog-html/main.html $ilm_installed->file_class = "main.html"; } } else $ilm_installed->type = "Java"; // otherwise it is Java $DB->update_record('iassign_ilm', $ilm_installed); } // foreach //--- // Insert in table '{iassign_ilm}' the new iLM iFractions version 0.1.2017.11.22 // Table 'iassign_ilm' : id name version type description url extension parent file_jar file_class width height enable timemodified author timecreated evaluate } // if ($oldversion < 2017120101) if ($oldversion < 2018031000) { // Verify if exist iLM with the same name // then, update the version and file_jar $records = array( array_combine( // iGeom 5.9.22 array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'), array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}', 'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600, 1, time(), $USER->id, time(), 1)), array_combine( // iGraf 4.4.0.10 array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'), array('iGraf', 'http://www.matematica.br/igraf', '4.4.0.10', 'Java', '{"en":"Interactive Graphic on the Internet","pt_br":"Gráficos Interativos na Internet"}', 'grf', 'ilm/iGraf/4.4.0.10/iGraf.jar', 'igraf.IGraf.class', 840, 600, 1, time(), $USER->id, time(), 1)), ); foreach ($records as $record) { if ($record['type'] == 'HTML5') { // Verify if there is a HTML5 iLM register => update it $iassign_ilm = $DB->get_records('iassign_ilm', array('name' => $record['name'])); if ($iassign_ilm) { // Update file_jar and file_class foreach ($iassign_ilm as $iassign) { $iassign->name = trim($iassign->name); $iassign->version = trim($iassign->version); // If HTML5 iLM is the same version, only update the path if ($iassign->version == $record['version']) { $newentry = new stdClass(); $newentry->id = $iassign->id; $newentry->file_jar = $record['file_jar']; $newentry->file_class = $record['file_class']; $DB->update_record("iassign_ilm", $newentry); } else { // If HTML5 iLM is NOT the same version, make a copy of the iLM $dest = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign->name . '/' . $iassign->version . '/'; mkdir($dest, 0755); // permissions "drwxr-xr-x" $source = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign->name . '/' . $record['version'] . '/'; foreach ( $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) { if ($item->isDir()) { mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); } else { // copy or move? copy($item, $dest . $iterator->getSubPathName()); // copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); // rename($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); } } $newentry = new stdClass(); $newentry->id = $iassign->id; $newentry->file_jar = 'ilm/' . $iassign->name . '/' . $iassign->version . '/' . basename($record['file_jar']) . '/'; $newentry->file_class = $record['file_class']; $DB->update_record("iassign_ilm", $newentry); } } // foreach ($iassign_ilm as $iassign) } else { // if ($iassign_ilm) // If not found a iLM with the same name $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm' } } // if ($record['type'] == 'HTML5') else { // Verify if there is a Java iLM register to update it $iassign_ilm = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'version' => $record['version'])); if ($iassign_ilm) { // Update file_jar and file_class $newentry = new stdClass(); $newentry->id = $iassign_ilm->id; $newentry->file_jar = $record['file_jar']; $newentry->file_class = $record['file_class']; $DB->update_record("iassign_ilm", $newentry); } else { // if ($iassign_ilm) - I couldn't find an iLM with this name ($record['name']) and under this version ($record['version']) // If not found a Java iLM with the same name and version, search a // different version, to use as parent of new version $iassign_ilm_parent = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'parent' => 0)); if ($iassign_ilm_parent) { $record['parent'] = $iassign_ilm_parent->id; $DB->insert_record('iassign_ilm', $record, false); // insert with parent // Download the JAR file of parent from MoodleData and put it in iassign/ilm/ $dest = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign_ilm_parent->name . '/' . $iassign_ilm_parent->version . '/'; mkdir($dest, 0777); $fs = get_file_storage(); $file = $fs->get_file_by_id($iassign_ilm_parent->file_jar); $file->copy_content_to($dest . $file->get_filename()); // Update file_jar of iLM parent $update_parent = new stdClass(); $update_parent->id = $iassign_ilm_parent->id; $update_parent->file_jar = 'ilm/' . $iassign_ilm_parent->name . '/' . $iassign_ilm_parent->version . '/' . $file->get_filename(); $DB->update_record("iassign_ilm", $update_parent); } else { $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm' without a parent } } // else if ($iassign_ilm) } // else if ($record['type'] == 'HTML5') } // foreach ($records as $record) } // if ($oldversion < 2018031000) //L if ($oldversion < 2019112219) { if ($oldversion < 2020070613) { $table = new xmldb_table('iassign_submission'); $field = new xmldb_field('previous_grade', XMLDB_TYPE_FLOAT, null, null, null, null, null); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } $records = array( // iLM adjusted to iAssign 2020/08/03 array_combine( // iGeom 5.9.22 array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'), array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}', 'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600, 1, time(), $USER->id, time(), 1, 0)), array_combine( // iGraf 4.4.0.10 array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'), array('iGraf', 'http://www.matematica.br/igraf', '4.4.0.10', 'Java', '{"en":"Interactive Graphic on the Internet","pt_br":"Gráficos Interativos na Internet"}', 'grf', 'ilm/iGraf/4.4.0.10/iGraf.jar', 'igraf.IGraf.class', 840, 600, 1, time(), $USER->id, time(), 1, 0)), array_combine( // iHanoi 1.0.20200803 array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'), array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20200803', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}', 'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500, 1, time(), $USER->id, time(), 1, 0)), array_combine( // iVProg 1.0.20200221/ - HTML5 - 2020 array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'), array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20200221', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/iVProg/1.0.20200221/ivprog/', 'index.html', 800, 600, 1, time(), $USER->id, time(), 1, 1)), array_combine( // iFractions 0.1.20200221 - HTML5 array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'), array('iFractions', 'http://www.matematica.br/ifractions', '0.1.20200221', 'HTML5', '{"en":"Interactive Fractions game","pt_br":"Jogo interativa de frações"}', 'frc', 'ilm/iFractions/0.1.20200221/ifractions/', 'index.html', 1000, 600, 1, time(), $USER->id, time(), 1, 0)) ); $iassign_ilm = $DB->get_records('iassign_ilm'); $strNot_installed = ''; foreach ($records as $record) { // this version 'iassign_ilm' does not has field 'reevaluate' $newentry = new stdClass(); $newentry->name = $record['name']; $newentry->version = $record['version']; $newentry->type = $record['type']; $newentry->url = $record['url']; $newentry->description = $record['description']; $newentry->extension = $record['extension']; $newentry->file_jar = $record['file_jar']; $newentry->file_class = $record['file_class']; $newentry->width = $record['width']; $newentry->height = $record['height']; $newentry->enable = $record['enable']; $newentry->timemodified = time(); $newentry->author = $USER->id; $newentry->timecreated = time(); $newentry->evaluate = $record['evaluate']; $exists = 0; if ($iassign_ilm) { // Search if there is any iLM of this with this version $record_type = strtolower($record['type']); foreach ($iassign_ilm as $iassign) { if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) { if ($iassign->version == $record['version']) { // or with the one with the same version $exists = 1; // iLM found - exit with the last one, same version $strNot_installed += "\n" + '
  • ' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + '
  • ' + "\n"; break; } } } } if ($exists == 0) try { // iLM does not exists or it has old version $DB->insert_record("iassign_ilm", $newentry, false); } catch (Exception $e) { print 'Caught exception: ' . $e->getMessage() . "
    \n"; } } // foreach ($records as $record) if ($strNot_installed != '') { // ATTENTION: this implies that Moodle administrator updated this iLM, please verify if it is really the current one. print '' + "\n"; } // Verify if each iLM previously installed is present in fresh new iAssign. This does not means problem, perhaps the admin installed a particular iLM. $strNot_found = ''; if ($iassign_ilm) { // exists iLM ($DB->get_records('iassign_ilm')) foreach ($iassign_ilm as $iassign) { $found = false; foreach ($records as $record) { if ($iassign->name == $record['name']) { $found = true; break; } } if (!$found) { $strNot_found .= '
  • ' . $iassign->name . ' - ' . $iassign->url . '
  • ' . "\n"; $updateentry = new stdClass(); $updateentry->id = $iassign->id; $updateentry->enable = 0; $updateentry->timemodified = time(); $DB->update_record("iassign_ilm", $updateentry); // insert new iLM } } // foreach ($iassign_ilm as $iassign) } // if ($iassign_ilm) if ($strNot_found != '') { print '' + "\n"; } } // if ($oldversion < 2020070613) if ($oldversion < 2020070613) { $table = new xmldb_table('iassign_ilm'); $field = new xmldb_field('reevaluate'); $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', null, null, null); if (!$dbman->field_exists($table, $field)) { // if 'iassign_ilm.reevaluate' does not exist, then create this field $dbman->add_field($table, $field); } $iassign_ilm = $DB->get_records('iassign_ilm'); foreach ($iassign_ilm as $iassign) { // If already installed iVProg/JS or iHanoi/JS set it with re-evaluate feature if ($iassign->type == 'HTML5' && ($iassign->name == 'iVProg' || $iassign->name == 'iHanoi')) { $updateentry = new stdClass(); $updateentry->id = $iassign->id; $updateentry->reevaluate = 1; $updateentry->timemodified = time(); $DB->update_record("iassign_ilm", $updateentry); break; } } } // if ($oldversion < 2020070612) if ($oldversion < 2020080300) { // new iHanoi // iassign_submission . grade : from 'BIGINT(11)' to 'real' if ($dbman->field_exists('iassign', 'grade')) { $sql = 'ALTER TABLE {iassign} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0'; $DB->execute($sql); } if ($dbman->field_exists('iassign_statement', 'grade')) { $sql = 'ALTER TABLE {iassign_statement} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0'; $DB->execute($sql); } if ($dbman->field_exists('iassign_submission', 'grade')) { $sql = 'ALTER TABLE {iassign_submission} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0'; $DB->execute($sql); } if ($dbman->field_exists('iassign_submission', 'previous_grade')) { // $sql = 'ALTER TABLE {iassign_submission} CHANGE previous_grade previous_grade REAL NOT NULL DEFAULT 0.0'; // Invalid use of NULL value $sql = 'ALTER TABLE {iassign_submission} CHANGE previous_grade previous_grade FLOAT DEFAULT 0.0'; $DB->execute($sql); } // Update iHanoi, iVProg, iFractions and iGeom $records = array( array_combine( // iHanoi 1.0.20200803 array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'evaluate', 'reevaluate', 'author', 'timecreated'), array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20200803', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}', 'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500, 1, time(), 1, 1, $USER->id, time())) ); $iassign_ilm = $DB->get_records('iassign_ilm'); foreach ($records as $record) { // For each iLM in the current version of iAssign $newentry = new stdClass(); $newentry->name = $record['name']; $newentry->version = $record['version']; $newentry->type = $record['type']; $newentry->url = $record['url']; $newentry->description = $record['description']; $newentry->extension = $record['extension']; $newentry->file_jar = $record['file_jar']; $newentry->file_class = $record['file_class']; $newentry->width = $record['width']; $newentry->height = $record['height']; $newentry->enable = $record['enable']; $newentry->timemodified = time(); $newentry->evaluate = $record['evaluate']; $newentry->reevaluate = $record['reevaluate']; $newentry->author = $USER->id; $newentry->timecreated = time(); $newentry->evaluate = $record['evaluate']; $exists = 0; $last_id = -1; if ($iassign_ilm) { // Search if there is any previous installed iLM that is also in the current version of iAssign $record_type = strtolower($record['type']); foreach ($iassign_ilm as $iassign) { if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) { if ($iassign->id > $last_id) $last_id = $iassign->id; // last ID => last version (hopefully) if ($iassign->version == $record['version']) { // or with the one with the same version $exists = 1; // iLM found - exit with the last one, same version $strNot_installed += "\n" + '
  • ' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + '
  • ' + "\n"; break; } } } } if ($exists == 0) { // iLM does not exists or it has old version $newentry->parent = $record['parent']; $DB->insert_record("iassign_ilm", $newentry, false); } } // foreach ($records as $record) if ($strNot_installed != '') { print '' + "\n"; } // s_iassign_ilm: atualizou iHanoi existente, mas nao era isso! Deveria ter inserido novo! // id name version type ... parent file_jar file_class width height ... evaluate reevaluate // 53 iHanoi 2 HTML5 ... 0 ilm/iHanoi/2/ihanoi/ index.html 1100 700 ... 1 0 $iassign_ilm = $DB->get_records('iassign_ilm'); foreach ($iassign_ilm as $iassign) { // for iLM iHanoi update the new field 'reevaluate' as 1 if ($iassign->name == 'iHanoi' && $iassign->type == 'HTML5' && $iassign->reevaluate!=1) { $updateentry = new stdClass(); $updateentry->id = $iassign->id; $updateentry->reevaluate = 1; $updateentry->timemodified = time(); $DB->update_record("iassign_ilm", $updateentry); break; } } // iAssign savepoint reached. upgrade_mod_savepoint(true, 2020080300, 'iassign'); } // if ($oldversion < 2020080300) //TODO Codigo do Igor para atualizar 'files.itemid' e 'iassign_statement.filesid': if ($oldversion < 2020102800) { // 1. encontrar os contextos dos arquivos do itarefa: $iassign_contexts_list = $DB->get_records_sql("SELECT contextid FROM {files} f " . " WHERE component='mod_iassign'"); // 2. compor um array com todos os contextos encontrados: $contexts = array(); foreach ($iassign_contexts_list as $iassign_context_item) { array_push($contexts, $iassign_context_item->contextid); } // 3. encontrar todas as atividades do itarefa, em que o arquivo não tenha o mesmo id do statement: $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " . " WHERE s.id != s.file"); $fs = get_file_storage(); // 4. percorrer o conjunto de atividades: foreach ($iassign_statement_list as $iassign_statement_activity_item) { // 5. encontrar o arquivo, considerando os possíveis contextos: $files = array(); foreach ($contexts as $context) { $files = $fs->get_area_files($context, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file); // 6. se o arquivo for encontrado, fazer uma cópia do conteúdo, // com o itemid novo, atualizar o iassign_statement, e apagar o arquivo antigo: if ($files) { foreach ($files as $value) { if ($value != null && $value->get_filename() != ".") { // 6.A. Fazer uma cópia: $newfile = $fs->create_file_from_storedfile(array('contextid' => $context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement_activity_item->id), $value); // 6.B. Atualizar o registro da atividade para o arquivo novo: $update_entry = new stdClass(); $update_entry->id = $iassign_statement_activity_item->id; $update_entry->file = $newfile->get_itemid(); $DB->update_record("iassign_statement", $update_entry); // 6.C. Remover o arquivo antigo: $value->delete(); } else if ($value != null && $value->get_filename() == ".") { // 6.C.I. Remover também os indicadores de diretório: $value->delete(); } } break; } } } } // if ($oldversion < 2020102800) // 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; } // function xmldb_iassign_upgrade($oldversion)