upgrade.php 23 KB

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