upgrade.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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.4 2013/09/19
  17. * + Insert general fields for iassign statement (grade, timeavaliable, timedue, preventlate, test, max_experiment).
  18. * + Change index field 'name' in 'iassign_ilm' table to index field 'name,version'.
  19. * - v 1.2 2013/08/30
  20. * + Change 'filearea' for new concept for files.
  21. * + Change path file for ilm, consider version in pathname.
  22. *
  23. * @author Patricia Alves Rodrigues
  24. * @author Leônidas O. Brandão
  25. * @version v 1.5 2019/03/13
  26. * @version v 1.4 2013/09/19
  27. * @package mod_iassign_db
  28. * @since 2010/12/21
  29. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  30. *
  31. * <b>License</b>
  32. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. *
  34. * @param $oldversion Number of the old version.
  35. */
  36. require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
  37. function xmldb_iassign_upgrade ($oldversion) {
  38. global $CFG, $DB, $USER;
  39. $dbman = $DB->get_manager();
  40. if ($oldversion < 2014012100) {
  41. // Define field and index in iLM table to be added
  42. $table = new xmldb_table('iassign_ilm');
  43. $index_name = new xmldb_index('name');
  44. $index_name->set_attributes(XMLDB_INDEX_UNIQUE, array('name'));
  45. if ($dbman->index_exists($table, $index_name)) {
  46. $dbman->drop_index($table, $index_name, $continue = true, $feedback = true);
  47. }
  48. $index_name_version = new xmldb_index('name_version');
  49. $index_name_version->set_attributes(XMLDB_INDEX_UNIQUE, array('name', 'version'));
  50. if (!$dbman->index_exists($table, $index_name_version)) {
  51. $dbman->add_index($table, $index_name_version, $continue = true, $feedback = true);
  52. }
  53. // Fix field name in ilm table to be added.
  54. $table = new xmldb_table('iassign_ilm');
  55. $field_height = new xmldb_field('heigth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '600', 'width');
  56. if ($dbman->field_exists($table, $field_height))
  57. $dbman->rename_field($table, $field_height, 'height');
  58. // Define fields in iassign table to be added.
  59. $table = new xmldb_table('iassign');
  60. $field_intro = new xmldb_field('intro', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'name');
  61. if (!$dbman->field_exists($table, $field_intro))
  62. $dbman->add_field($table, $field_intro);
  63. $field_introformat = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro');
  64. if (!$dbman->field_exists($table, $field_introformat))
  65. $dbman->add_field($table, $field_introformat);
  66. $field_grade = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, '0', 'activity_group');
  67. if (!$dbman->field_exists($table, $field_grade))
  68. $dbman->add_field($table, $field_grade);
  69. $field_timeavailable = new xmldb_field('timeavailable', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'grade');
  70. if (!$dbman->field_exists($table, $field_timeavailable))
  71. $dbman->add_field($table, $field_timeavailable);
  72. $field_timedue = new xmldb_field('timedue', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeavailable');
  73. if (!$dbman->field_exists($table, $field_timedue))
  74. $dbman->add_field($table, $field_timedue);
  75. $field_preventlate = new xmldb_field('preventlate', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, '1', 'timedue');
  76. if (!$dbman->field_exists($table, $field_preventlate))
  77. $dbman->add_field($table, $field_preventlate);
  78. $field_test = new xmldb_field('test', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0', 'preventlate');
  79. if (!$dbman->field_exists($table, $field_test))
  80. $dbman->add_field($table, $field_test);
  81. $field_max_experiment = new xmldb_field('max_experiment', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'test');
  82. if (!$dbman->field_exists($table, $field_max_experiment))
  83. $dbman->add_field($table, $field_max_experiment);
  84. if (!$dbman->table_exists($table)) {
  85. $field_id = new xmldb_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
  86. $field_time = new xmldb_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id');
  87. $field_userid = new xmldb_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'time');
  88. $field_ip = new xmldb_field('ip', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'userid');
  89. $field_course = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'ip');
  90. $field_cmid = new xmldb_field('cmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'course');
  91. $field_ilmid = new xmldb_field('ilmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'cmid');
  92. $field_action = new xmldb_field('action', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'ilmid');
  93. $field_info = new xmldb_field('info', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'action');
  94. $field_language = new xmldb_field('language', XMLDB_TYPE_CHAR, '10', null, null, null, null, 'info');
  95. $field_user_agent = new xmldb_field('user_agent', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, 'language');
  96. $field_javascript = new xmldb_field('javascript', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'user_agent');
  97. $field_java = new xmldb_field('java', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'javascript');
  98. $key = new xmldb_key('primary');
  99. $key->set_attributes(XMLDB_KEY_PRIMARY, array('id'), null, null);
  100. $index = new xmldb_index('course');
  101. $index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
  102. $table->addField($field_id);
  103. $table->addField($field_time);
  104. $table->addField($field_userid);
  105. $table->addField($field_ip);
  106. $table->addField($field_course);
  107. $table->addField($field_cmid);
  108. $table->addField($field_ilmid);
  109. $table->addField($field_action);
  110. $table->addField($field_info);
  111. $table->addField($field_language);
  112. $table->addField($field_user_agent);
  113. $table->addField($field_javascript);
  114. $table->addField($field_java);
  115. $table->addKey($key);
  116. $table->addIndex($index);
  117. $status = $dbman->create_table($table);
  118. } // if (!$dbman->table_exists($table))
  119. // Now update Moodle table '*_files' related to the iAssign: insert new field 'filearea'
  120. $fs = get_file_storage();
  121. $is_delete = true;
  122. $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/";
  123. // All iAssign 'exercises' must get the label 'exercise'
  124. $exercise_files = $DB->get_records('files', array("component" => "mod_iassign", "filearea" => "activity"));
  125. foreach ($exercise_files as $exercise_file) {
  126. $exercise_file->filearea = "exercise";
  127. $DB->update_record('files', $exercise_file);
  128. }
  129. // All iAssign iLM (usually 'JAR package') must get the label 'activity'
  130. $activity_files = $DB->get_records('files', array("component" => "mod_iassign", "filearea" => "ilm"));
  131. foreach ($activity_files as $activity_file) {
  132. $activity_file->filearea = "activity";
  133. $DB->update_record('files', $activity_file);
  134. }
  135. // iAssign savepoint reached
  136. upgrade_mod_savepoint(true, 2014012100, 'iassign');
  137. } // if ($oldversion < 2014012100)
  138. if ($oldversion < 2017021900) { // update to migrate from 2016021300 to 2017021900 (2.2.00)
  139. // iassign_ilm : id; name; version; description; url; extension; parent; file_jar; file_class; width; height; enable; timemodified; author; timecreated; evaluate
  140. $count_iassign_ilm = $DB->count_records_sql('SELECT COUNT(id) FROM {iassign_ilm}'); // count the number of existing iLM in table '*_iassign_ilm'
  141. if ($count_iassign_ilm>0) { // Insert new iLM: iVProgH5 (package in HTML5 technology)
  142. // Insert an entry in the Moodle table '*_files'
  143. $context = context_system::instance();
  144. $file_ilm = array(
  145. 'userid' => $USER->id, // ID of context
  146. 'contextid' => $context->id, // ID of context
  147. 'component' => 'mod_iassign', // usually = table name
  148. 'filearea' => 'ilm', // in table '*_files' all iAssign exercises will have 'filearea="exercise"' and all iLM must be 'ilm'
  149. 'itemid' => 0,
  150. 'filepath' => '/iassign/ilm/', // any path beginning and ending in /
  151. 'filename' => "ivprog-html/main.html"); // any filename: use the starting point of iVProgH5
  152. // Now update Moodle table '*_files' related to the iAssign: insert new field 'filearea'
  153. $fs = get_file_storage();
  154. $is_delete = true;
  155. $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/";
  156. //TODO iLM_HTML5 : What model to implement to HTML5?
  157. //TODO 1. The first version of iLM HTML5 in '/var/www/html/moodle/mod/iassign/ilm/ilm-nome' and others in '/var/moodledata/filedir/'?
  158. //TODO 2. Inserting new iLM HTML5 by ZIP file => explode it and register in '/var/moodledata/filedir/'?
  159. // Create file using the content: the file information is inserted in the Moodle table '*_files'
  160. // The real file will be registered in Moodle data (default '/var/moodledata/filedir/xx/yy' - 'xxyy' is the first 4 char in '*_files.contenthash')
  161. //TODO Keep this even change the model to not insert iLM HTML5 (need this object to connect with '*_iassign_ilm' bellow)
  162. $file_ilm = $fs->create_file_from_string($file_ilm, file_get_contents($ilm_path . "ivprog-html/main.html"));
  163. if ($file_ilm)
  164. $is_delete &= @unlink($ilm_path . "ivprog-html");
  165. // Insert an entry in iAssign table '*_iassign_ilm'
  166. $newentry = new stdClass();
  167. $newentry->name = 'iVProgH5';
  168. $newentry->url = 'http://www.matematica.br/ivprogh5';
  169. $newentry->version = '0.1.1';
  170. $newentry->description = '{"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}';
  171. $newentry->extension = 'ivph';
  172. $newentry->file_jar = 'iVProgH5'; // to JAR this is the '*_files.id' correponding to the iLM storaged in '/var/moodledata/filedir/'
  173. $newentry->file_class = 'ivprog-html/index.html';
  174. $newentry->width = 800;
  175. $newentry->height = 700;
  176. $newentry->enable = 1;
  177. $newentry->timemodified = time();
  178. $newentry->author = $USER->id;
  179. $newentry->timecreated = time();
  180. $newentry->evaluate = 1;
  181. // $DB->insert_records('iassign_ilm', $newentry);
  182. $newentry->id = $DB->insert_record("iassign_ilm", $newentry);
  183. // iAssign savepoint reached
  184. upgrade_mod_savepoint(true, 2017021900, 'iassign');
  185. } // if ($count_iassign_ilm>0)
  186. } // if ($oldversion < 2017021900)
  187. if ($oldversion < 2017120100) { // last one: 2017042800 from 2017/02/19
  188. // Create new field 'type', putting 'Java' if JAR and 'HTML5' if HTML5
  189. // Update fields 'file_jar, file_class' of iLM iVProgH5 (from 'iVProgH5, ivprog-html/main.html' to 'ilm/ivprog-html/, main.html'
  190. //---
  191. // Define new field in iassign table to be added: type varchar(20) in { 'Java' 'HTML5' }
  192. $table = new xmldb_table('iassign_ilm');
  193. $new_field_type = new xmldb_field('type', XMLDB_TYPE_CHAR, '20', null, null, null, null, 'version'); // after field 'version'
  194. if (!$dbman->field_exists($table, $new_field_type))
  195. $dbman->add_field($table, $new_field_type);
  196. //---
  197. // All iAssign iLM (usually 'JAR package') must get the type 'Java'
  198. $list_of_ilm_installed = $DB->get_records('iassign_ilm');
  199. foreach ($list_of_ilm_installed as $ilm_installed) {
  200. $ilm_name = strtolower($ilm_installed->name);
  201. //D echo $ilm_name . " : " . $ilm_installed->file_jar . " : " . $ilm_installed->file_class . " : " . $ilm_installed->extension . "<br/>\n";
  202. if ($ilm_name=="ivprogh5" || $ilm_name=="ifractions" || $ilm_name=="fractions") { // if it is 'iVProgH5' (perhaps 'iFractions' already installed?)
  203. $ilm_installed->type = "HTML5"; // it is HTML5
  204. $file_jar = strtolower($ilm_installed->file_jar);
  205. if ($ilm_name=="ivprogh5" && $file_jar=="ivprogh5") { // fields 'file_jar' and 'file_class' must have: 'ilm/ivprog-html/' and 'main.html'
  206. $ilm_installed->file_jar = "ilm/ivprog-html/"; // iVProgH5 ivprog-html/main.html
  207. $ilm_installed->file_class = "main.html";
  208. }
  209. }
  210. else
  211. $ilm_installed->type = "Java"; // otherwise it is Java
  212. $DB->update_record('iassign_ilm', $ilm_installed);
  213. } // foreach
  214. //---
  215. // Insert in table '{iassign_ilm}' the new iLM iFractions version 0.1.2017.11.22
  216. // Table 'iassign_ilm' : id name version type description url extension parent file_jar file_class width height enable timemodified author timecreated evaluate
  217. /*$new_ilm_ifractions['name'] = 'iFractions';
  218. $new_ilm_ifractions['version'] = '0.1.2017.11.22';
  219. $new_ilm_ifractions['type'] = 'HTML5';
  220. $new_ilm_ifractions['description'] = '{"en":"Visual Interactive Fractions Learning","pt_br":"Aprendizagem visual interativa de frações"}';
  221. $new_ilm_ifractions['url'] = 'http://www.matematica.br/ifractions';
  222. $new_ilm_ifractions['extension'] = 'frc';
  223. $new_ilm_ifractions['parent'] = '0';
  224. $new_ilm_ifractions['file_jar'] = 'ilm/ifractions/';
  225. $new_ilm_ifractions['file_class'] = 'index.html';
  226. $new_ilm_ifractions['width'] = '900';
  227. $new_ilm_ifractions['height'] = '600';
  228. $new_ilm_ifractions['enable'] = '1';
  229. $new_ilm_ifractions['timemodified'] = time();
  230. $new_ilm_ifractions['author'] = $USER->id;
  231. $new_ilm_ifractions['timecreated'] = time();
  232. $new_ilm_ifractions['evaluate'] = 1;
  233. $DB->insert_record('iassign_ilm', $new_ilm_ifractions, false); // insert new iLM in the table '{iassign_ilm}';*/
  234. } // if ($oldversion < 2017120101)
  235. if ($oldversion < 2018031000) {
  236. // Verify if exist iLM with the same name
  237. // then, update the version and file_jar
  238. $records = array(
  239. // iGeom 5.9.22
  240. array_combine(
  241. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  242. 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)),
  243. // iGraf 4.4.0.10
  244. array_combine(
  245. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  246. 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)),
  247. // iComb 0.9.5
  248. array_combine(
  249. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  250. 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)),
  251. // iVProg2 2.1.0
  252. array_combine(
  253. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  254. 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)),
  255. // iTangram2 0.4.6
  256. array_combine(
  257. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  258. 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)),
  259. // iHanoi 3.1.0
  260. array_combine(
  261. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  262. 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)),
  263. // Risco 2
  264. array_combine(
  265. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  266. 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)),
  267. // iVProgH5 0.1.1 - HTML5
  268. array_combine(
  269. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  270. array('iVProgH', 'http://www.matematica.br/ivprogh', '0.1.20190307', 'HTML5', '{"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/iVProgH/0.1.20190307/ivprog-html/', 'index.html', 800, 600, 1, time(), $USER->id, time(), 1)),
  271. // fractions 0.1.2017.11.22 - HTML5
  272. array_combine(
  273. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  274. 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))
  275. );
  276. foreach ($records as $record) {
  277. if ($record['type'] == 'HTML5') {
  278. //D echo " * iMA versao HTML<br/>\n";
  279. // Verify if there is a HTML5 iLM register => update it
  280. $iassign_ilm = $DB->get_records('iassign_ilm', array('name' => $record['name']));
  281. if ($iassign_ilm) {
  282. // Update file_jar and file_class
  283. foreach ($iassign_ilm as $iassign) {
  284. $iassign->name = trim($iassign->name);
  285. $iassign->version = trim($iassign->version);
  286. //D echo " &nbsp;&nbsp;&nbsp;" . $iassign->id . ", " . $iassign->name . "<br/>\n";
  287. // If HTML5 iLM is the same version, only update the path
  288. if ($iassign->version == $record['version']) {
  289. //D echo " &nbsp;&nbsp;&nbsp;&nbsp; mesma versao " . $iassign->version . "<br/>\n";
  290. $newentry = new stdClass();
  291. $newentry->id = $iassign->id;
  292. $newentry->file_jar = $record['file_jar'];
  293. $newentry->file_class = $record['file_class'];
  294. $DB->update_record("iassign_ilm", $newentry);
  295. }
  296. else { // If HTML5 iLM is NOT the same version, make a copy of the iLM
  297. $dest = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign->name . '/' . $iassign->version . '/';
  298. mkdir($dest, 0755); // permissions "drwxr-xr-x"
  299. $source = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign->name . '/' . $record['version'] . '/';
  300. foreach (
  301. $iterator = new \RecursiveIteratorIterator(
  302. new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
  303. \RecursiveIteratorIterator::SELF_FIRST) as $item) {
  304. if ($item->isDir()) {
  305. mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  306. }
  307. else { // copy or move?
  308. copy($item, $dest . $iterator->getSubPathName());
  309. // copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  310. // rename($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  311. }
  312. }
  313. $newentry = new stdClass();
  314. $newentry->id = $iassign->id;
  315. $newentry->file_jar = 'ilm/' . $iassign->name . '/' . $iassign->version . '/' . basename($record['file_jar']) . '/';
  316. $newentry->file_class = $record['file_class'];
  317. $DB->update_record("iassign_ilm", $newentry);
  318. }
  319. } // foreach ($iassign_ilm as $iassign)
  320. }
  321. else { // if ($iassign_ilm)
  322. // If not found a iLM with the same name
  323. $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm'
  324. }
  325. } // if ($record['type'] == 'HTML5')
  326. else {
  327. // Verify if there is a Java iLM register to update it
  328. $iassign_ilm = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'version' => $record['version']));
  329. if ($iassign_ilm) {
  330. // Update file_jar and file_class
  331. $newentry = new stdClass();
  332. $newentry->id = $iassign_ilm->id;
  333. $newentry->file_jar = $record['file_jar'];
  334. $newentry->file_class = $record['file_class'];
  335. $DB->update_record("iassign_ilm", $newentry);
  336. }
  337. else { // if ($iassign_ilm) - I couldn't find an iLM with this name ($record['name']) and under this version ($record['version'])
  338. // If not found a Java iLM with the same name and version, search a
  339. // different version, to use as parent of new version
  340. $iassign_ilm_parent = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'parent' => 0));
  341. if ($iassign_ilm_parent) {
  342. $record['parent'] = $iassign_ilm_parent->id;
  343. $DB->insert_record('iassign_ilm', $record, false); // insert with parent
  344. // Download the JAR file of parent from MoodleData and put it in iassign/ilm/
  345. $dest = $CFG->dirroot . '/mod/iassign/ilm/' . $iassign_ilm_parent->name . '/' . $iassign_ilm_parent->version . '/';
  346. mkdir($dest, 0777);
  347. //D echo " &nbsp;&nbsp;&nbsp;&nbsp; mover para " . $dest . "<br/>\n";
  348. $fs = get_file_storage();
  349. $file = $fs->get_file_by_id($iassign_ilm_parent->file_jar);
  350. $file->copy_content_to($dest . $file->get_filename());
  351. // Update file_jar of iLM parent
  352. $update_parent = new stdClass();
  353. $update_parent->id = $iassign_ilm_parent->id;
  354. $update_parent->file_jar = 'ilm/' . $iassign_ilm_parent->name . '/' . $iassign_ilm_parent->version . '/' . $file->get_filename();
  355. $DB->update_record("iassign_ilm", $update_parent);
  356. }
  357. else {
  358. $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm' without a parent
  359. }
  360. } // else if ($iassign_ilm)
  361. } // else if ($record['type'] == 'HTML5')
  362. } // foreach ($records as $record)
  363. } // if ($oldversion < 2018031000)
  364. // log event -----------------------------------------------------
  365. if (class_exists('plugin_manager'))
  366. $pluginman = plugin_manager::instance();
  367. else
  368. $pluginman = core_plugin_manager::instance();
  369. $plugins = $pluginman->get_plugins();
  370. iassign_log::add_log('upgrade', 'version: ' . $plugins['mod']['iassign']->versiondisk);
  371. // log event -----------------------------------------------------
  372. return true;
  373. }