upgrade.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <?php
  2. /**
  3. * This file keeps track of upgrades to the lams module.
  4. *
  5. * Sometimes, changes between versions involve
  6. * alterations to database structures and other
  7. * major things that may break installations.
  8. * The upgrade function in this file will attempt
  9. * to perform all the necessary actions to upgrade
  10. * your older installtion to the current version.
  11. * If there's something it cannot do itself, it
  12. * will tell you what you need to do.
  13. * The commands in here will all be database-neutral,
  14. * using the functions defined in lib/ddllib.php
  15. *
  16. * - v 1.5.1 2020/05/28-30
  17. * + Avoid to update one iLM causing colision with other instance of the same iLM
  18. * - v 1.4 2013/09/19
  19. * + Insert general fields for iassign statement (grade, timeavaliable, timedue, preventlate, test, max_experiment).
  20. * + Change index field 'name' in 'iassign_ilm' table to index field 'name,version'.
  21. * - v 1.2 2013/08/30
  22. * + Change 'filearea' for new concept for files.
  23. * + Change path file for ilm, consider version in pathname.
  24. *
  25. * @author Leônidas O. Brandão
  26. * @author Patricia Alves Rodrigues
  27. * @author Igor Moreira Félix
  28. * @version v 1.5.1 2020/05/28-30
  29. * @version v 1.5 2019/03/13
  30. * @version v 1.4 2013/09/19
  31. * @package mod_iassign_db
  32. * @since 2010/12/21
  33. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  34. *
  35. * <b>License</b>
  36. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37. *
  38. * @param $oldversion Number of the old version.
  39. */
  40. require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
  41. function xmldb_iassign_upgrade ($oldversion) {
  42. global $CFG, $DB, $USER;
  43. $dbman = $DB->get_manager();
  44. if ($oldversion < 2014012100) {
  45. // Define field and index in iLM table to be added
  46. $table = new xmldb_table('iassign_ilm');
  47. $index_name = new xmldb_index('name');
  48. $index_name->set_attributes(XMLDB_INDEX_UNIQUE, array('name'));
  49. if ($dbman->index_exists($table, $index_name)) {
  50. $dbman->drop_index($table, $index_name, $continue = true, $feedback = true);
  51. }
  52. $index_name_version = new xmldb_index('name_version');
  53. $index_name_version->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'version'));
  54. if (!$dbman->index_exists($table, $index_name_version)) {
  55. $dbman->add_index($table, $index_name_version, $continue = true, $feedback = true);
  56. }
  57. // Fix field name in ilm table to be added.
  58. $table = new xmldb_table('iassign_ilm');
  59. $field_height = new xmldb_field('heigth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '600', 'width');
  60. if ($dbman->field_exists($table, $field_height))
  61. $dbman->rename_field($table, $field_height, 'height');
  62. // Define fields in iassign table to be added.
  63. $table = new xmldb_table('iassign');
  64. $field_intro = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'name');
  65. if (!$dbman->field_exists($table, $field_intro))
  66. $dbman->add_field($table, $field_intro);
  67. $field_introformat = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro');
  68. if (!$dbman->field_exists($table, $field_introformat))
  69. $dbman->add_field($table, $field_introformat);
  70. $field_grade = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, '0', 'activity_group');
  71. if (!$dbman->field_exists($table, $field_grade))
  72. $dbman->add_field($table, $field_grade);
  73. $field_timeavailable = new xmldb_field('timeavailable', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'grade');
  74. if (!$dbman->field_exists($table, $field_timeavailable))
  75. $dbman->add_field($table, $field_timeavailable);
  76. $field_timedue = new xmldb_field('timedue', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeavailable');
  77. if (!$dbman->field_exists($table, $field_timedue))
  78. $dbman->add_field($table, $field_timedue);
  79. $field_preventlate = new xmldb_field('preventlate', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '1', 'timedue');
  80. if (!$dbman->field_exists($table, $field_preventlate))
  81. $dbman->add_field($table, $field_preventlate);
  82. $field_test = new xmldb_field('test', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', 'preventlate');
  83. if (!$dbman->field_exists($table, $field_test))
  84. $dbman->add_field($table, $field_test);
  85. $field_max_experiment = new xmldb_field('max_experiment', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'test');
  86. if (!$dbman->field_exists($table, $field_max_experiment))
  87. $dbman->add_field($table, $field_max_experiment);
  88. if (!$dbman->table_exists($table)) {
  89. $field_id = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
  90. $field_time = new xmldb_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
  91. $field_userid = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'time');
  92. $field_ip = new xmldb_field('ip', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'userid');
  93. $field_course = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ip');
  94. $field_cmid = new xmldb_field('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'course');
  95. $field_ilmid = new xmldb_field('ilmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'cmid');
  96. $field_action = new xmldb_field('action', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'ilmid');
  97. $field_info = new xmldb_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'action');
  98. $field_language = new xmldb_field('language', XMLDB_TYPE_CHAR, '10', null, null, null, null, 'info');
  99. $field_user_agent = new xmldb_field('user_agent', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'language');
  100. $field_javascript = new xmldb_field('javascript', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'user_agent');
  101. $field_java = new xmldb_field('java', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'javascript');
  102. $key = new xmldb_key('primary');
  103. $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'), null, null);
  104. $index = new xmldb_index('course');
  105. $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
  106. $table->addField($field_id);
  107. $table->addField($field_time);
  108. $table->addField($field_userid);
  109. $table->addField($field_ip);
  110. $table->addField($field_course);
  111. $table->addField($field_cmid);
  112. $table->addField($field_ilmid);
  113. $table->addField($field_action);
  114. $table->addField($field_info);
  115. $table->addField($field_language);
  116. $table->addField($field_user_agent);
  117. $table->addField($field_javascript);
  118. $table->addField($field_java);
  119. $table->addKey($key);
  120. $table->addIndex($index);
  121. $status = $dbman->create_table($table);
  122. } // if (!$dbman->table_exists($table))
  123. // Now update Moodle table '*_files' related to the iAssign: insert new field 'filearea'
  124. $fs = get_file_storage();
  125. $is_delete = true;
  126. $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/";
  127. // All iAssign 'exercises' must get the label 'exercise'
  128. $exercise_files = $DB->get_records('files', array("component" => "mod_iassign", "filearea" => "activity"));
  129. foreach ($exercise_files as $exercise_file) {
  130. $exercise_file->filearea = "exercise";
  131. $DB->update_record('files', $exercise_file);
  132. }
  133. // All iAssign iLM (usually 'JAR package') must get the label 'activity'
  134. $activity_files = $DB->get_records('files', array("component" => "mod_iassign", "filearea" => "ilm"));
  135. foreach ($activity_files as $activity_file) {
  136. $activity_file->filearea = "activity";
  137. $DB->update_record('files', $activity_file);
  138. }
  139. // iAssign savepoint reached
  140. upgrade_mod_savepoint(true, 2014012100, 'iassign');
  141. } // if ($oldversion < 2014012100)
  142. if ($oldversion < 2017021900) { // update to migrate from 2016021300 to 2017021900 (2.2.00)
  143. // iassign_ilm : id; name; version; description; url; extension; parent; file_jar; file_class; width; height; enable; timemodified; author; timecreated; evaluate
  144. $count_iassign_ilm = $DB->count_records_sql('SELECT COUNT(id) FROM {iassign_ilm}'); // count the number of existing iLM in table '*_iassign_ilm'
  145. if ($count_iassign_ilm>0) { // Insert new iLM: iVProgH5 (package in HTML5 technology)
  146. // Insert an entry in the Moodle table '*_files'
  147. $context = context_system::instance();
  148. $file_ilm = array(
  149. 'userid' => $USER->id, // ID of context
  150. 'contextid' => $context->id, // ID of context
  151. 'component' => 'mod_iassign', // usually = table name
  152. 'filearea' => 'ilm', // in table '*_files' all iAssign exercises will have 'filearea="exercise"' and all iLM must be 'ilm'
  153. 'itemid' => 0,
  154. 'filepath' => '/iassign/ilm/', // any path beginning and ending in /
  155. 'filename' => "ivprog-html/main.html"); // any filename: use the starting point of iVProgH5
  156. // Now update Moodle table '*_files' related to the iAssign: insert new field 'filearea'
  157. $fs = get_file_storage();
  158. $is_delete = true;
  159. $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/";
  160. //TODO iLM_HTML5 : What model to implement to HTML5?
  161. //TODO 1. The first version of iLM HTML5 in '/var/www/html/moodle/mod/iassign/ilm/ilm-nome' and others in '/var/moodledata/filedir/'?
  162. //TODO 2. Inserting new iLM HTML5 by ZIP file => explode it and register in '/var/moodledata/filedir/'?
  163. // Create file using the content: the file information is inserted in the Moodle table '*_files'
  164. // The real file will be registered in Moodle data (default '/var/moodledata/filedir/xx/yy' - 'xxyy' is the first 4 char in '*_files.contenthash')
  165. //TODO Keep this even change the model to not insert iLM HTML5 (need this object to connect with '*_iassign_ilm' bellow)
  166. $file_ilm = $fs->create_file_from_string($file_ilm, file_get_contents($ilm_path . "ivprog-html/main.html"));
  167. if ($file_ilm)
  168. $is_delete &= @unlink($ilm_path . "ivprog-html");
  169. // Insert an entry in iAssign table '*_iassign_ilm'
  170. $newentry = new stdClass();
  171. $newentry->name = 'iVProgH5';
  172. $newentry->url = 'http://www.matematica.br/ivprogh5';
  173. $newentry->version = '0.1.1';
  174. $newentry->description = '{"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}';
  175. $newentry->extension = 'ivph';
  176. $newentry->file_jar = 'iVProgH5'; // to JAR this is the '*_files.id' correponding to the iLM storaged in '/var/moodledata/filedir/'
  177. $newentry->file_class = 'ivprog-html/index.html';
  178. $newentry->width = 800;
  179. $newentry->height = 700;
  180. $newentry->enable = 1;
  181. $newentry->timemodified = time();
  182. $newentry->author = $USER->id;
  183. $newentry->timecreated = time();
  184. $newentry->evaluate = 1;
  185. // $DB->insert_records('iassign_ilm', $newentry);
  186. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  187. // iAssign savepoint reached
  188. upgrade_mod_savepoint(true, 2017021900, 'iassign');
  189. } // if ($count_iassign_ilm>0)
  190. } // if ($oldversion < 2017021900)
  191. if ($oldversion < 2017120100) { // last one: 2017042800 from 2017/02/19
  192. // Create new field 'type', putting 'Java' if JAR and 'HTML5' if HTML5
  193. // Update fields 'file_jar, file_class' of iLM iVProgH5 (from 'iVProgH5, ivprog-html/main.html' to 'ilm/ivprog-html/, main.html'
  194. //---
  195. // Define new field in iassign table to be added: type varchar(20) in { 'Java' 'HTML5' }
  196. $table = new xmldb_table('iassign_ilm');
  197. $new_field_type = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, null, null, null, 'version'); // after field 'version'
  198. if (!$dbman->field_exists($table, $new_field_type))
  199. $dbman->add_field($table, $new_field_type);
  200. //---
  201. // All iAssign iLM (usually 'JAR package') must get the type 'Java'
  202. $list_of_ilm_installed = $DB->get_records('iassign_ilm');
  203. foreach ($list_of_ilm_installed as $ilm_installed) {
  204. $ilm_name = strtolower($ilm_installed->name);
  205. //D echo $ilm_name . " : " . $ilm_installed->file_jar . " : " . $ilm_installed->file_class . " : " . $ilm_installed->extension . "<br/>\n";
  206. if ($ilm_name=="ivprogh5" || $ilm_name=="ifractions" || $ilm_name=="fractions") { // if it is 'iVProgH5' (perhaps 'iFractions' already installed?)
  207. $ilm_installed->type = "HTML5"; // it is HTML5
  208. $file_jar = strtolower($ilm_installed->file_jar);
  209. if ($ilm_name=="ivprogh5" && $file_jar=="ivprogh5") { // fields 'file_jar' and 'file_class' must have: 'ilm/ivprog-html/' and 'main.html'
  210. $ilm_installed->file_jar = "ilm/ivprog-html/"; // iVProgH5 ivprog-html/main.html
  211. $ilm_installed->file_class = "main.html";
  212. }
  213. }
  214. else
  215. $ilm_installed->type = "Java"; // otherwise it is Java
  216. $DB->update_record('iassign_ilm', $ilm_installed);
  217. } // foreach
  218. //---
  219. // Insert in table '{iassign_ilm}' the new iLM iFractions version 0.1.2017.11.22
  220. // Table 'iassign_ilm' : id name version type description url extension parent file_jar file_class width height enable timemodified author timecreated evaluate
  221. /*$new_ilm_ifractions['name'] = 'iFractions';
  222. $new_ilm_ifractions['version'] = '0.1.2017.11.22';
  223. $new_ilm_ifractions['type'] = 'HTML5';
  224. $new_ilm_ifractions['description'] = '{"en":"Visual Interactive Fractions Learning","pt_br":"Aprendizagem visual interativa de frações"}';
  225. $new_ilm_ifractions['url'] = 'http://www.matematica.br/ifractions';
  226. $new_ilm_ifractions['extension'] = 'frc';
  227. $new_ilm_ifractions['parent'] = '0';
  228. $new_ilm_ifractions['file_jar'] = 'ilm/ifractions/';
  229. $new_ilm_ifractions['file_class'] = 'index.html';
  230. $new_ilm_ifractions['width'] = '900';
  231. $new_ilm_ifractions['height'] = '600';
  232. $new_ilm_ifractions['enable'] = '1';
  233. $new_ilm_ifractions['timemodified'] = time();
  234. $new_ilm_ifractions['author'] = $USER->id;
  235. $new_ilm_ifractions['timecreated'] = time();
  236. $new_ilm_ifractions['evaluate'] = 1;
  237. $DB->insert_record('iassign_ilm', $new_ilm_ifractions, false); // insert new iLM in the table '{iassign_ilm}';*/
  238. } // if ($oldversion < 2017120101)
  239. if ($oldversion < 2018031000) {
  240. // Verify if exist iLM with the same name
  241. // then, update the version and file_jar
  242. $records = array(
  243. // iGeom 5.9.22
  244. array_combine(
  245. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  246. 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)),
  247. // iGraf 4.4.0.10
  248. array_combine(
  249. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  250. 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)),
  251. // iComb 0.9.5
  252. array_combine(
  253. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  254. array('iComb', 'http://www.matematica.br/icomb', '0.9.5', 'Java', '{"en":"Combinatorics Interactive on the Internet","pt_br":"Combinatória Interativa na Internet"}', 'icb,cmb', 'ilm/iComb/0.9.5/iComb.jar', 'icomb.IComb.class', 750, 685, 1, time(), $USER->id, time(), 1)),
  255. // iVProg2 2.1.0
  256. array_combine(
  257. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  258. array('iVProg2', 'http://www.matematica.br/ivprog2', '2.1.0', 'Java', '{"en":"Visual Interactive Programming on the Internet","pt_br":"Programação visual interativa na Internet"}', 'ivp2', 'ilm/iVProg2/2.1.0/iVProg2.jar', 'usp.ime.line.ivprog.Ilm.class', 800, 700, 1, time(), $USER->id, time(), 1)),
  259. // iTangram2 0.4.6
  260. array_combine(
  261. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  262. array('iTangram2', 'http://www.matematica.br/itangram', '0.4.6', 'Java', '{"en":"interactive Tangram (by LInE)","pt_br":"Tangram interativo (do LInE)"}', 'itg2', 'ilm/iTangram2/0.4.6/iTangram2.jar', 'ilm.line.itangram2.Tangram', 800, 600, 1, time(), $USER->id, time(), 1)),
  263. // iHanoi 3.1.0
  264. array_combine(
  265. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  266. array('iHanoi', 'http://www.matematica.br/ihanoi', '3.1.0', 'Java', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}', 'ihn', 'ilm/iHanoi/3.1.0/iHanoi.jar', 'ihanoi.iHanoi', 730, 450, 1, time(), $USER->id, time(), 1)),
  267. // Risco 2
  268. array_combine(
  269. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  270. array('Risko', 'http://risko.pcc.usp.br/', '2.2.23', 'Java', '{"en":"Technical drawing with triangle and ruler","pt_br":"Desenho Geomẽtrico com esquadro"}', 'rsk', 'ilm/Risko/2.2.23/Risko.jar', 'RiskoApplet.class', 800, 600, 1, time(), $USER->id, time(), 0)),
  271. // iVProg4 1.0.20190717 - HTML5 - 2019
  272. array_combine(
  273. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  274. array('iVProg4', 'http://www.usp.br/line/ivprog/', '1.0.20190717', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/iVProg4/1.0.20190717/ivprog4/', 'index.html', 800, 600, 1, time(), $USER->id, time(), 1)),
  275. // iVProgH 0.0.2 - HTML5 - 2014
  276. array_combine(
  277. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  278. array('iVProgH', 'http://www.matematica.br/ivprogh', '0.0.2', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/iVProgH/0.0.2/ivprogh/', 'main.html', 800, 600, 1, time(), $USER->id, time(), 1)),
  279. // fractions 0.1.2017.11.22 - HTML5
  280. array_combine(
  281. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  282. array('iFractions', 'http://www.matematica.br/ifractions', '0.1.2017.11.22', 'HTML5', '{"en":"Interactive Fractions game","pt_br":"Jogo interativa de frações"}', 'frc', 'ilm/iFractions/0.1.2017.11.22/ifractions/', 'index.html', 1000, 600, 1, time(), $USER->id, time(), 1))
  283. );
  284. foreach ($records as $record) {
  285. if ($record['type'] == 'HTML5') {
  286. //D echo " * iMA versao HTML<br/>\n";
  287. // Verify if there is a HTML5 iLM register => update it
  288. $iassign_ilm = $DB->get_records('iassign_ilm', array('name' => $record['name']));
  289. if ($iassign_ilm) {
  290. // Update file_jar and file_class
  291. foreach ($iassign_ilm as $iassign) {
  292. $iassign->name = trim($iassign->name);
  293. $iassign->version = trim($iassign->version);
  294. //D echo " &nbsp;&nbsp;&nbsp;" . $iassign->id . ", " . $iassign->name . "<br/>\n";
  295. // If HTML5 iLM is the same version, only update the path
  296. if ($iassign->version == $record['version']) {
  297. //D echo " &nbsp;&nbsp;&nbsp;&nbsp; mesma versao " . $iassign->version . "<br/>\n";
  298. $newentry = new stdClass();
  299. $newentry->id = $iassign->id;
  300. $newentry->file_jar = $record['file_jar'];
  301. $newentry->file_class = $record['file_class'];
  302. $DB->update_record("iassign_ilm", $newentry);
  303. }
  304. else { // If HTML5 iLM is NOT the same version, make a copy of the iLM
  305. $dest = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign->name . '/' . $iassign->version . '/';
  306. mkdir($dest, 0755); // permissions "drwxr-xr-x"
  307. $source = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign->name . '/' . $record['version'] . '/';
  308. foreach (
  309. $iterator = new \RecursiveIteratorIterator(
  310. new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
  311. \RecursiveIteratorIterator::SELF_FIRST) as $item) {
  312. if ($item->isDir()) {
  313. mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  314. }
  315. else { // copy or move?
  316. copy($item, $dest . $iterator->getSubPathName());
  317. // copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  318. // rename($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  319. }
  320. }
  321. $newentry = new stdClass();
  322. $newentry->id = $iassign->id;
  323. $newentry->file_jar = 'ilm/' . $iassign->name . '/' . $iassign->version . '/' . basename($record['file_jar']) . '/';
  324. $newentry->file_class = $record['file_class'];
  325. $DB->update_record("iassign_ilm", $newentry);
  326. }
  327. } // foreach ($iassign_ilm as $iassign)
  328. }
  329. else { // if ($iassign_ilm)
  330. // If not found a iLM with the same name
  331. $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm'
  332. }
  333. } // if ($record['type'] == 'HTML5')
  334. else {
  335. // Verify if there is a Java iLM register to update it
  336. $iassign_ilm = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'version' => $record['version']));
  337. if ($iassign_ilm) {
  338. // Update file_jar and file_class
  339. $newentry = new stdClass();
  340. $newentry->id = $iassign_ilm->id;
  341. $newentry->file_jar = $record['file_jar'];
  342. $newentry->file_class = $record['file_class'];
  343. $DB->update_record("iassign_ilm", $newentry);
  344. }
  345. else { // if ($iassign_ilm) - I couldn't find an iLM with this name ($record['name']) and under this version ($record['version'])
  346. // If not found a Java iLM with the same name and version, search a
  347. // different version, to use as parent of new version
  348. $iassign_ilm_parent = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'parent' => 0));
  349. if ($iassign_ilm_parent) {
  350. $record['parent'] = $iassign_ilm_parent->id;
  351. $DB->insert_record('iassign_ilm', $record, false); // insert with parent
  352. // Download the JAR file of parent from MoodleData and put it in iassign/ilm/
  353. $dest = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign_ilm_parent->name . '/' . $iassign_ilm_parent->version . '/';
  354. mkdir($dest, 0777);
  355. //D echo " &nbsp;&nbsp;&nbsp;&nbsp; mover para " . $dest . "<br/>\n";
  356. $fs = get_file_storage();
  357. $file = $fs->get_file_by_id($iassign_ilm_parent->file_jar);
  358. $file->copy_content_to($dest . $file->get_filename());
  359. // Update file_jar of iLM parent
  360. $update_parent = new stdClass();
  361. $update_parent->id = $iassign_ilm_parent->id;
  362. $update_parent->file_jar = 'ilm/' . $iassign_ilm_parent->name . '/' . $iassign_ilm_parent->version . '/' . $file->get_filename();
  363. $DB->update_record("iassign_ilm", $update_parent);
  364. }
  365. else {
  366. $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm' without a parent
  367. }
  368. } // else if ($iassign_ilm)
  369. } // else if ($record['type'] == 'HTML5')
  370. } // foreach ($records as $record)
  371. } // if ($oldversion < 2018031000)
  372. if ($oldversion < 2019112219) {
  373. $table = new xmldb_table('iassign_submission');
  374. $field = new xmldb_field('previous_grade', XMLDB_TYPE_FLOAT, null, null, null, null, null);
  375. if (!$dbman->field_exists($table, $field)) {
  376. $dbman->add_field($table, $field);
  377. }
  378. $records = array(
  379. // iGeom 5.9.22
  380. array_combine(
  381. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  382. 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)),
  383. // iGraf 4.4.0.10
  384. array_combine(
  385. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  386. 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)),
  387. // iHanoi 0.1.20200115
  388. array_combine(
  389. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  390. array('iHanoi', 'http://www.matematica.br/ihanoi', '0.1.20200115', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}', 'ihn', 'ilm/iHanoi/0.1.20200115/ihanoi/', 'index.html', 730, 450, 1, time(), $USER->id, time(), 1)),
  391. // iVProg 1.0.20190717 - HTML5 - 2019
  392. array_combine(
  393. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  394. array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20190717', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/iVProg/1.0.20190717/ivprog/', 'index.html', 800, 600, 1, time(), $USER->id, time(), 1)),
  395. // iFractions 0.1.20200221 - HTML5
  396. array_combine(
  397. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  398. 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))
  399. );
  400. $iassign_ilm = $DB->get_records('iassign_ilm');
  401. foreach ($records as $record) {
  402. $newentry = new stdClass();
  403. $newentry->name = $record['name'];
  404. $newentry->version = $record['version'];
  405. $newentry->type = $record['type'];
  406. $newentry->url = $record['url'];
  407. $newentry->description = $record['description'];
  408. $newentry->extension = $record['extension'];
  409. $newentry->file_jar = $record['file_jar'];
  410. $newentry->file_class = $record['file_class'];
  411. $newentry->width = $record['width'];
  412. $newentry->height = $record['height'];
  413. $newentry->enable = $record['enable'];
  414. $newentry->timemodified = time();
  415. $newentry->author = $USER->id;
  416. $newentry->timecreated = time();
  417. $newentry->evaluate = $record['evaluate'];
  418. if ($iassign_ilm) {
  419. // Search if there is any iLM of this with this version
  420. $exist1 = $exist2 = 0;
  421. foreach ($iassign_ilm as $iassign)
  422. if ($iassign->name == $record['name'] && $iassign->type == $record['type']) {
  423. $exist1 = 1; // iLM found - exit with the last one,
  424. if ($iassign->version == $record['version']) { // or with the one with the same version
  425. $exist2 = 1; // same version
  426. break;
  427. }
  428. }
  429. if ($exist1 == 1) { // the iLM has been found
  430. if ($exist2 == 0 && $iassign->file_class != $record['file_class']) { // not the same version
  431. $updateentry = new stdClass();
  432. $updateentry->id = $iassign->id;
  433. $updateentry->file_jar = $record['file_jar'];
  434. $updateentry->file_class = $record['file_class'];
  435. $updateentry->version = $record['version'];
  436. $updateentry->timemodified = time();
  437. $DB->update_record("iassign_ilm", $updateentry);
  438. }
  439. elseif ($exist2 == 1 && $iassign->file_class != $record['file_class']) { // same version
  440. $updateentry = new stdClass();
  441. $updateentry->id = $iassign->id;
  442. $updateentry->file_jar = $record['file_jar'];
  443. $updateentry->file_class = $record['file_class'];
  444. $updateentry->timemodified = time();
  445. $DB->update_record("iassign_ilm", $updateentry);
  446. }
  447. } // if ($exist1 == 1)
  448. }
  449. else {
  450. $DB->insert_record("iassign_ilm", $newentry, false);
  451. }
  452. } // foreach ($records as $record)
  453. $not_found = '';
  454. if ($iassign_ilm) {
  455. foreach ($iassign_ilm as $iassign) {
  456. $found = false;
  457. foreach ($records as $record) {
  458. if ($iassign->name == $record['name']) {
  459. $found = true;
  460. break;
  461. }
  462. }
  463. if (!$found) {
  464. $not_found .= '<li>' . $iassign->name . ' - <a href="' . $iassign->url . '" target="_blank">' . $iassign->url . '</a></li>';
  465. $updateentry = new stdClass();
  466. $updateentry->id = $iassign->id;
  467. $updateentry->enable = 0;
  468. $updateentry->timemodified = time();
  469. $DB->update_record("iassign_ilm", $updateentry);
  470. }
  471. }
  472. }
  473. if ($not_found != '') {
  474. print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >';
  475. print get_string('upgrade_alert_iMA_msg', 'iassign');
  476. print '<ul style="margin-top: 1rem;">';
  477. print $not_found;
  478. print '</ul>';
  479. print get_string('upgrade_alert_iMA_solution_pt1', 'iassign');
  480. print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.';
  481. print '</div>';
  482. }
  483. $iassign_ilm = $DB->get_records('iassign_ilm');
  484. foreach ($records as $record) {
  485. $newentry = new stdClass();
  486. $newentry->name = $record['name'];
  487. $newentry->version = $record['version'];
  488. $newentry->type = $record['type'];
  489. $newentry->url = $record['url'];
  490. $newentry->description = $record['description'];
  491. $newentry->extension = $record['extension'];
  492. $newentry->file_jar = $record['file_jar'];
  493. $newentry->file_class = $record['file_class'];
  494. $newentry->width = $record['width'];
  495. $newentry->height = $record['height'];
  496. $newentry->enable = $record['enable'];
  497. $newentry->timemodified = time();
  498. $newentry->author = $USER->id;
  499. $newentry->timecreated = time();
  500. $newentry->evaluate = $record['evaluate'];
  501. $found = false;
  502. foreach ($iassign_ilm as $iassign) {
  503. if ($iassign->name == $newentry->name) {
  504. $found = true;
  505. break;
  506. }
  507. }
  508. if (!$found) {
  509. $DB->insert_record("iassign_ilm", $newentry, false);
  510. }
  511. }
  512. } // if ($oldversion < 2019112200)
  513. // log event -----------------------------------------------------
  514. if (class_exists('plugin_manager'))
  515. $pluginman = plugin_manager::instance();
  516. else
  517. $pluginman = core_plugin_manager::instance();
  518. $plugins = $pluginman->get_plugins();
  519. iassign_log::add_log('upgrade', 'version: ' . $plugins['mod']['iassign']->versiondisk);
  520. // log event -----------------------------------------------------
  521. return true;
  522. }