upgrade.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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.4 2021/12/23
  17. * + Added new version of iVProg 2021_11_30_22_06
  18. * - v 1.5.2 2020/08/03
  19. * + Fixed 'ALTER TABLE' of 'iassign_submission.grade' from BIGINT(11) to REAL
  20. * + New version of iHanoi 1.0.20200803
  21. * - v 1.5.1 2020/05/28-30
  22. * + Avoid to update one iLM causing colision with other instance of the same iLM
  23. * - v 1.4 2013/09/19
  24. * + Insert general fields for iassign statement (grade, timeavaliable, timedue, preventlate, test, max_experiment).
  25. * + Change index field 'name' in 'iassign_ilm' table to index field 'name,version'.
  26. * - v 1.2 2013/08/30
  27. * + Change 'filearea' for new concept for files.
  28. * + Change path file for ilm, consider version in pathname.
  29. *
  30. * @author Leônidas O. Brandão
  31. * @author Patricia Alves Rodrigues
  32. * @author Igor Moreira Félix
  33. * @version v 1.5.1 2020/05/28-30
  34. * @version v 1.5 2019/03/13
  35. * @version v 1.4 2013/09/19
  36. * @package mod_iassign_db
  37. * @since 2010/12/21
  38. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  39. *
  40. * <b>License</b>
  41. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42. *
  43. * @param $oldversion Number of the old version.
  44. */
  45. require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
  46. function xmldb_iassign_upgrade ($oldversion) {
  47. global $CFG, $DB, $USER;
  48. $dbman = $DB->get_manager();
  49. // Sequence of updates:
  50. // - 2020070613: structure
  51. // - 2020080300
  52. // - 2020120500
  53. // - 2020122900
  54. // - 2021020700
  55. // - 2021122300: new version iVProg "1.0.20211130"
  56. if ($oldversion < 2020070613) { // < 2020070613
  57. $table = new xmldb_table('iassign_submission');
  58. $field = new xmldb_field('previous_grade', XMLDB_TYPE_FLOAT, null, null, null, null, null);
  59. if (!$dbman->field_exists($table, $field)) {
  60. $dbman->add_field($table, $field);
  61. }
  62. $records = array( // iLM adjusted to iAssign 2020/08/03
  63. array_combine( // iGeom 5.9.22
  64. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
  65. 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)),
  66. array_combine( // iGraf 4.4.0.10
  67. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
  68. 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)),
  69. array_combine( // iHanoi 1.0.20200803
  70. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
  71. 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)),
  72. array_combine( // iVProg 1.0.20211130/ - HTML5 - 2020
  73. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
  74. array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20211130', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/iVProg/1.0.20211130/ivprog/', 'index.html', 800, 600, 1, time(), $USER->id, time(), 1, 1)),
  75. array_combine( // iFractions 0.1.20200221 - HTML5
  76. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
  77. 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))
  78. );
  79. $iassign_ilm = $DB->get_records('iassign_ilm');
  80. $strNot_installed = '';
  81. foreach ($records as $record) { // this version 'iassign_ilm' does not has field 'reevaluate'
  82. $newentry = new stdClass();
  83. $newentry->name = $record['name'];
  84. $newentry->version = $record['version'];
  85. $newentry->type = $record['type'];
  86. $newentry->url = $record['url'];
  87. $newentry->description = $record['description'];
  88. $newentry->extension = $record['extension'];
  89. $newentry->file_jar = $record['file_jar'];
  90. $newentry->file_class = $record['file_class'];
  91. $newentry->width = $record['width'];
  92. $newentry->height = $record['height'];
  93. $newentry->enable = $record['enable'];
  94. $newentry->timemodified = time();
  95. $newentry->author = $USER->id;
  96. $newentry->timecreated = time();
  97. $newentry->evaluate = $record['evaluate'];
  98. $exists = 0;
  99. if ($iassign_ilm) { // Search if there is any iLM of this with this version
  100. $record_type = strtolower($record['type']);
  101. foreach ($iassign_ilm as $iassign) {
  102. if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) {
  103. if ($iassign->version == $record['version']) { // or with the one with the same version
  104. $exists = 1; // iLM found - exit with the last one, same version
  105. $strNot_installed += "\n" + ' <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
  106. break;
  107. }
  108. }
  109. }
  110. }
  111. if ($exists == 0) try { // iLM does not exists or it has old version
  112. $DB->insert_record("iassign_ilm", $newentry, false);
  113. } catch (Exception $e) {
  114. print 'Caught exception: ' . $e->getMessage() . "<br/>\n";
  115. }
  116. } // foreach ($records as $record)
  117. if ($strNot_installed != '') { // ATTENTION: this implies that Moodle administrator updated this iLM, please verify if it is really the current one.
  118. print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
  119. print get_string('upgrade_alert_exists', 'iassign'); // iLM previouly existent
  120. print ' <ul style="margin-top: 1rem;">' + "\n";
  121. print $strNot_installed;
  122. print ' </ul>' + "\n";
  123. print '</div>' + "\n";
  124. }
  125. // Verify if each iLM previously installed is present in fresh new iAssign. This does not means problem, perhaps the admin installed a particular iLM.
  126. $strNot_found = '';
  127. if ($iassign_ilm) { // exists iLM ($DB->get_records('iassign_ilm'))
  128. foreach ($iassign_ilm as $iassign) {
  129. $found = false;
  130. foreach ($records as $record) {
  131. if ($iassign->name == $record['name']) {
  132. $found = true;
  133. break;
  134. }
  135. }
  136. if (!$found) {
  137. $strNot_found .= '<li>' . $iassign->name . ' - <a href="' . $iassign->url . '" target="_blank">' . $iassign->url . '</a></li>' . "\n";
  138. $updateentry = new stdClass();
  139. $updateentry->id = $iassign->id;
  140. $updateentry->enable = 0;
  141. $updateentry->timemodified = time();
  142. $DB->update_record("iassign_ilm", $updateentry); // insert new iLM
  143. }
  144. } // foreach ($iassign_ilm as $iassign)
  145. } // if ($iassign_ilm)
  146. if ($strNot_found != '') {
  147. print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
  148. print get_string('upgrade_alert_iMA_msg', 'iassign'); // Updated but some previous iLM installed are not available in fresh iAssign
  149. print '<ul style="margin-top: 1rem;">' + "\n";
  150. print $strNot_found;
  151. print '</ul>' + "\n";
  152. print get_string('upgrade_alert_iMA_solution_pt1', 'iassign');
  153. print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.' . "\n";
  154. print '</div>' + "\n";
  155. }
  156. } // if ($oldversion < 2020070613)
  157. if ($oldversion < 2020070613) {
  158. $table = new xmldb_table('iassign_ilm');
  159. $field = new xmldb_field('reevaluate');
  160. $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', null, null, null);
  161. if (!$dbman->field_exists($table, $field)) { // if 'iassign_ilm.reevaluate' does not exist, then create this field
  162. $dbman->add_field($table, $field);
  163. }
  164. $iassign_ilm = $DB->get_records('iassign_ilm');
  165. foreach ($iassign_ilm as $iassign) { // If already installed iVProg/JS or iHanoi/JS set it with re-evaluate feature
  166. if ($iassign->type == 'HTML5' && ($iassign->name == 'iVProg' || $iassign->name == 'iHanoi')) {
  167. $updateentry = new stdClass();
  168. $updateentry->id = $iassign->id;
  169. $updateentry->reevaluate = 1;
  170. $updateentry->timemodified = time();
  171. $DB->update_record("iassign_ilm", $updateentry);
  172. break;
  173. }
  174. }
  175. } // if ($oldversion < 2020070612)
  176. if ($oldversion < 2020080300) { // new iHanoi
  177. // iassign_submission . grade : from 'BIGINT(11)' to 'real'
  178. if ($dbman->field_exists('iassign', 'grade')) {
  179. $sql = 'ALTER TABLE {iassign} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
  180. $DB->execute($sql);
  181. }
  182. if ($dbman->field_exists('iassign_statement', 'grade')) {
  183. $sql = 'ALTER TABLE {iassign_statement} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
  184. $DB->execute($sql);
  185. }
  186. if ($dbman->field_exists('iassign_submission', 'grade')) {
  187. $sql = 'ALTER TABLE {iassign_submission} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
  188. $DB->execute($sql);
  189. }
  190. if ($dbman->field_exists('iassign_submission', 'previous_grade')) {
  191. // $sql = 'ALTER TABLE {iassign_submission} CHANGE previous_grade previous_grade REAL NOT NULL DEFAULT 0.0'; // Invalid use of NULL value
  192. $sql = 'ALTER TABLE {iassign_submission} CHANGE previous_grade previous_grade FLOAT DEFAULT 0.0';
  193. $DB->execute($sql);
  194. }
  195. // Update iHanoi
  196. $records = array(
  197. array_combine( // iHanoi 1.0.20200803
  198. array('name', 'url', 'version', 'type', 'description',
  199. 'extension', 'file_jar', 'file_class', 'width', 'height',
  200. 'enable', 'timemodified', 'evaluate', 'reevaluate', 'author', 'timecreated'),
  201. 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)"}',
  202. 'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500,
  203. 1, time(), 1, 1, $USER->id, time()))
  204. );
  205. $iassign_ilm = $DB->get_records('iassign_ilm');
  206. foreach ($records as $record) { // For each iLM in the current version of iAssign
  207. $newentry = new stdClass();
  208. $newentry->name = $record['name'];
  209. $newentry->url = $record['url'];
  210. $newentry->version = $record['version'];
  211. $newentry->type = $record['type'];
  212. $newentry->description = $record['description'];
  213. $newentry->extension = $record['extension'];
  214. $newentry->file_jar = $record['file_jar'];
  215. $newentry->file_class = $record['file_class'];
  216. $newentry->width = $record['width'];
  217. $newentry->height = $record['height'];
  218. $newentry->enable = $record['enable'];
  219. $newentry->timemodified = time();
  220. $newentry->evaluate = $record['evaluate'];
  221. $newentry->reevaluate = $record['reevaluate'];
  222. $newentry->author = $USER->id;
  223. $newentry->timecreated = time();
  224. $exists = 0;
  225. $last_id = -1;
  226. if ($iassign_ilm) { // Search if there is any previous installed iLM that is also in the current version of iAssign
  227. $record_type = strtolower($record['type']);
  228. foreach ($iassign_ilm as $iassign) {
  229. if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) {
  230. if ($iassign->id > $last_id)
  231. $last_id = $iassign->id; // last ID => last version (hopefully)
  232. if ($iassign->version == $record['version']) { // or with the one with the same version
  233. $exists = 1; // iLM found - exit with the last one, same version
  234. $strNot_installed += "\n" + ' <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
  235. break;
  236. }
  237. }
  238. }
  239. }
  240. if ($exists == 0) { // iLM does not exists or it has old version
  241. $newentry->parent = $record['parent'];
  242. $DB->insert_record("iassign_ilm", $newentry, false);
  243. }
  244. } // foreach ($records as $record)
  245. if ($strNot_installed != '') {
  246. print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
  247. print get_string('upgrade_alert_exists', 'iassign'); // iLM previouly existent
  248. print ' <ul style="margin-top: 1rem;">' + "\n";
  249. print $strNot_installed;
  250. print ' </ul>' + "\n";
  251. print '</div>' + "\n";
  252. }
  253. // iassign_ilm: atualizou iHanoi existente, mas nao era isso! Deveria ter inserido novo!
  254. // id name version type ... parent file_jar file_class width height ... evaluate reevaluate
  255. // 53 iHanoi 2 HTML5 ... 0 ilm/iHanoi/2/ihanoi/ index.html 1100 700 ... 1 0
  256. $iassign_ilm = $DB->get_records('iassign_ilm');
  257. foreach ($iassign_ilm as $iassign) { // for iLM iHanoi update the new field 'reevaluate' as 1
  258. if ($iassign->name == 'iHanoi' && $iassign->type == 'HTML5' && $iassign->reevaluate!=1) {
  259. $updateentry = new stdClass();
  260. $updateentry->id = $iassign->id;
  261. $updateentry->reevaluate = 1;
  262. $updateentry->timemodified = time();
  263. $DB->update_record("iassign_ilm", $updateentry);
  264. break;
  265. }
  266. }
  267. // iAssign savepoint reached.
  268. upgrade_mod_savepoint(true, 2020080300, 'iassign');
  269. } // if ($oldversion < 2020080300)
  270. //TODO Codigo do Igor para atualizar 'files.itemid' e 'iassign_statement.filesid':
  271. if ($oldversion < 2020120500) {
  272. // Adding field iassing_statement.filesid
  273. $table = new xmldb_table('iassign_statement');
  274. $field_filesid = new xmldb_field('filesid', XMLDB_TYPE_CHAR, '255', null, null, null, null, null);
  275. if (!$dbman->field_exists($table, $field_filesid))
  276. $dbman->add_field($table, $field_filesid);
  277. // Updating all registers from iassing_statement.filesid
  278. $DB->execute("UPDATE {iassign_statement} SET filesid = file");
  279. // 1. encontrar os contextos dos arquivos do itarefa:
  280. $iassign_contexts_list = $DB->get_records_sql("SELECT DISTINCT contextid FROM {files} f WHERE component='mod_iassign'");
  281. // 2. compor um array com todos os contextos encontrados:
  282. $contexts = array();
  283. foreach ($iassign_contexts_list as $iassign_context_item) {
  284. array_push($contexts, $iassign_context_item->contextid);
  285. }
  286. // 3. encontrar todas as atividades do itarefa, em que o arquivo não tenha o mesmo id do statement:
  287. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s WHERE s.id != s.file");
  288. $fs = get_file_storage();
  289. // 4. percorrer o conjunto de atividades:
  290. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  291. // 5. encontrar o arquivo, considerando os possíveis contextos:
  292. $files = array();
  293. foreach ($contexts as $context) {
  294. $files = $fs->get_area_files($context, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  295. // 6. se o arquivo for encontrado, fazer uma cópia do conteúdo,
  296. // com o itemid novo, atualizar o iassign_statement, e apagar o arquivo antigo:
  297. if ($files) {
  298. foreach ($files as $value) {
  299. if ($value != null && $value->get_filename() != ".") {
  300. // 6.A. Fazer uma cópia:
  301. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement_activity_item->id), $value);
  302. // 6.B. Atualizar o registro da atividade para o arquivo novo:
  303. $update_entry = new stdClass();
  304. $update_entry->id = $iassign_statement_activity_item->id;
  305. $update_entry->file = $newfile->get_itemid();
  306. $update_entry->filesid = $newfile->get_itemid();
  307. $DB->update_record("iassign_statement", $update_entry);
  308. // 6.C. Remover o arquivo antigo:
  309. $value->delete();
  310. }
  311. else if ($value != null && $value->get_filename() == ".") {
  312. // 6.C.I. Remover também os indicadores de diretório:
  313. $value->delete();
  314. }
  315. }
  316. break;
  317. } // if ($files)
  318. } // foreach ($contexts as $context)
  319. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  320. } // if ($oldversion < 2020120500)
  321. /// @Igor - adicionar a tabela iassign_allsubmissions
  322. if ($oldversion < 2020122900) { // < 2020122900
  323. // Define table iassign_allsubmissions to be created.
  324. $table = new xmldb_table('iassign_allsubmissions');
  325. // Adding fields to table iassign_allsubmissions.
  326. $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
  327. $table->add_field('iassign_statementid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
  328. $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
  329. $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '16', null, XMLDB_NOTNULL, null, null);
  330. $table->add_field('grade', XMLDB_TYPE_FLOAT, null, null, null, null, null, null);
  331. $table->add_field('answer', XMLDB_TYPE_TEXT, 'long', null, null, null, null, null);
  332. // Adding keys to table iassign_allsubmissions.
  333. $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
  334. // Conditionally launch create table for iassign_allsubmissions.
  335. if (!$dbman->table_exists($table)) {
  336. $dbman->create_table($table);
  337. }
  338. // Adding fields to table iassign_ilm.
  339. $table = new xmldb_table('iassign_ilm');
  340. $field_editingbehavior = new xmldb_field('editingbehavior', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
  341. if (!$dbman->field_exists($table, $field_editingbehavior))
  342. $dbman->add_field($table, $field_editingbehavior);
  343. $field_submissionbehavior = new xmldb_field('submissionbehavior', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
  344. if (!$dbman->field_exists($table, $field_submissionbehavior))
  345. $dbman->add_field($table, $field_submissionbehavior);
  346. $field_action_buttons = new xmldb_field('action_buttons', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', null);
  347. if (!$dbman->field_exists($table, $field_action_buttons))
  348. $dbman->add_field($table, $field_action_buttons);
  349. // Adding field to table iassign_statement:
  350. $table = new xmldb_table('iassign_statement');
  351. $field_store_all_submissions = new xmldb_field('store_all_submissions', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
  352. if (!$dbman->field_exists($table, $field_store_all_submissions))
  353. $dbman->add_field($table, $field_store_all_submissions);
  354. // Update new fields for previous installed iLM:
  355. $iassign_ilm = $DB->get_records('iassign_ilm');
  356. foreach ($iassign_ilm as $iassign) {
  357. $updateentry = new stdClass();
  358. $updateentry->id = $iassign->id;
  359. if (($iassign->name == 'iHanoi' && $iassign->type == 'HTML5')) {
  360. $updateentry->editingbehavior = 0;
  361. $updateentry->submissionbehavior = 0;
  362. }
  363. if (($iassign->name == 'iGeom' && $iassign->type == 'Java')) {
  364. $updateentry->editingbehavior = 0;
  365. $updateentry->submissionbehavior = 0;
  366. }
  367. if (($iassign->name == 'iVProg' && $iassign->type == 'HTML5')) {
  368. $updateentry->editingbehavior = 1;
  369. $updateentry->submissionbehavior = 0;
  370. }
  371. if (($iassign->name == 'iFractions' && $iassign->type == 'HTML5')) {
  372. $updateentry->editingbehavior = 0;
  373. $updateentry->submissionbehavior = 1;
  374. }
  375. if (($iassign->name == 'Risko' && $iassign->type == 'Java')) {
  376. $updateentry->editingbehavior = 1;
  377. $updateentry->submissionbehavior = 0;
  378. }
  379. if (isset($updateentry->editingbehavior)) {
  380. $updateentry->timemodified = time();
  381. $DB->update_record("iassign_ilm", $updateentry);
  382. }
  383. }
  384. // Add iassign_allsubmissions table
  385. $table = new xmldb_table('iassign_allsubmissions');
  386. if (!$dbman->table_exists($table)) {
  387. $field1 = new xmldb_field('id');
  388. $field1->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
  389. $field2 = new xmldb_field('iassign_statementid');
  390. $field2->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
  391. $field3 = new xmldb_field('userid');
  392. $field3->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
  393. $field4 = new xmldb_field('timecreated');
  394. $field4->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
  395. $field5 = new xmldb_field('grade');
  396. $field5->set_attributes(XMLDB_TYPE_FLOAT, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
  397. $field6 = new xmldb_field('answer');
  398. $field6->set_attributes(XMLDB_TYPE_TEXT, 'long', null, null, null, null, 'type');
  399. $table->addIndex($field1);
  400. $table->addField($field2);
  401. $table->addField($field3);
  402. $table->addField($field4);
  403. $table->addField($field5);
  404. $table->addField($field6);
  405. $dbman->create_table($table);
  406. } // if (!$dbman->table_exists($table))
  407. // Update file_jar field:
  408. try {
  409. $DB->execute("ALTER TABLE {iassign_ilm} DROP INDEX {iassilm_fil_uix}");
  410. } catch (Exception $ex) {}
  411. // Create $CFG->dataroot/temp/iassign_files
  412. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  413. if (!file_exists($tempfilespath)) {
  414. mkdir($tempfilespath, 0777, true);
  415. }
  416. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  417. if (!file_exists($iassignfilespath)) {
  418. mkdir($iassignfilespath, 0777, true);
  419. }
  420. } // if ($oldversion < 2020122900)
  421. if ($oldversion < 2021020700) {
  422. // Update SAW iVProg to inform reevalute is enabled:
  423. $updateentry = new stdClass();
  424. $updateentry->id = 57;
  425. $updateentry->reevaluate = 1;
  426. $updateentry->timemodified = time();
  427. $DB->update_record("iassign_ilm", $updateentry); // insert new iLM
  428. }
  429. $strNot_installed = '';
  430. if ($oldversion < 2021122300) {
  431. // Update iHanoi
  432. $records = array(
  433. array_combine( // iVProg 1.0.20211130/ - HTML5 - 2021/12/30
  434. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
  435. array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20211130', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}',
  436. 'ivph', 'ilm/iVProg/1.0.20211130/ivprog/', 'index.html', 800, 600, 1, time(), $USER->id, time(), 1, 1))
  437. );
  438. $iassign_ilm = $DB->get_records('iassign_ilm');
  439. foreach ($records as $record) { // For each iLM in the current version of iAssign
  440. $newentry = new stdClass();
  441. $newentry->name = $record['name'];
  442. $newentry->url = $record['url'];
  443. $newentry->version = $record['version'];
  444. $newentry->type = $record['type'];
  445. $newentry->description = $record['description'];
  446. $newentry->extension = $record['extension'];
  447. $newentry->file_jar = $record['file_jar'];
  448. $newentry->file_class = $record['file_class'];
  449. $newentry->width = $record['width'];
  450. $newentry->height = $record['height'];
  451. $newentry->enable = $record['enable'];
  452. $newentry->timemodified = time();
  453. $newentry->author = $USER->id;
  454. $newentry->timecreated = time();
  455. $newentry->evaluate = $record['evaluate'];
  456. $newentry->reevaluate = $record['reevaluate'];
  457. $exists = 0;
  458. $last_id = -1;
  459. if ($iassign_ilm) { // Search if there is any previous installed iLM that is also in the current version of iAssign
  460. $record_type = strtolower($record['type']);
  461. foreach ($iassign_ilm as $iassign) {
  462. if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) {
  463. if ($iassign->id > $last_id)
  464. $last_id = $iassign->id; // last ID => last version (hopefully)
  465. if ($iassign->version == $record['version']) { // or with the one with the same version
  466. $exists = 1; // iLM found - exit with the last one, same version
  467. $strNot_installed += "\n" + ' <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
  468. break;
  469. }
  470. }
  471. }
  472. $newentry->parent = $last_id; // parent is the last iLM found (corresponde to the smallest ID)
  473. }
  474. else
  475. $newentry->parent = -1; // first iLM of this one
  476. if ($exists == 0) { // iLM does not exists or it has old version
  477. // $newentry->parent = $record['parent'];
  478. $DB->insert_record("iassign_ilm", $newentry, false);
  479. }
  480. } // foreach ($records as $record)
  481. if ($strNot_installed != '') {
  482. print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
  483. print get_string('upgrade_alert_exists', 'iassign'); // iLM previouly existent
  484. print ' <ul style="margin-top: 1rem;">' + "\n";
  485. print $strNot_installed;
  486. print ' </ul>' + "\n";
  487. print '</div>' + "\n";
  488. }
  489. // iassign_ilm: atualizou iHanoi existente, mas nao era isso! Deveria ter inserido novo!
  490. // id name version type ... parent file_jar file_class width height ... evaluate reevaluate
  491. // 53 iHanoi 2 HTML5 ... 0 ilm/iHanoi/2/ihanoi/ index.html 1100 700 ... 1 0
  492. $iassign_ilm = $DB->get_records('iassign_ilm');
  493. foreach ($iassign_ilm as $iassign) { // for iLM iHanoi update the new field 'reevaluate' as 1
  494. if ($iassign->name == 'iHanoi' && $iassign->type == 'HTML5' && $iassign->reevaluate!=1) {
  495. $updateentry = new stdClass();
  496. $updateentry->id = $iassign->id;
  497. $updateentry->reevaluate = 1;
  498. $updateentry->timemodified = time();
  499. $DB->update_record("iassign_ilm", $updateentry);
  500. break;
  501. }
  502. }
  503. // iAssign savepoint reached.
  504. upgrade_mod_savepoint(true, 2021122300, 'iassign');
  505. } // if ($oldversion < 2021122300)
  506. // log event -----------------------------------------------------
  507. if (class_exists('plugin_manager'))
  508. $pluginman = plugin_manager::instance();
  509. else
  510. $pluginman = core_plugin_manager::instance();
  511. $plugins = $pluginman->get_plugins();
  512. iassign_log::add_log('upgrade', 'version: ' . $plugins['mod']['iassign']->versiondisk);
  513. // log event -----------------------------------------------------
  514. return true;
  515. } // function xmldb_iassign_upgrade($oldversion)