1
0

upgrade.php 25 KB

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