upgrade.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. <?php
  2. require(dirname(__FILE__).'/../lib/db.php');
  3. /**
  4. * Database upgrade script for Moodle's db-independent XMLDB.
  5. * @ignore
  6. * @package sloodle
  7. */
  8. // This file keeps track of upgrades to
  9. // the sloodle module
  10. //
  11. // Sometimes, changes between versions involve
  12. // alterations to database structures and other
  13. // major things that may break installations.
  14. //
  15. // The upgrade function in this file will attempt
  16. // to perform all the necessary actions to upgrade
  17. // your older installation to the current version.
  18. //
  19. // If there's something it cannot do itself, it
  20. // will tell you what you need to do.
  21. //
  22. // The commands in here will all be database-neutral,
  23. // using the functions defined in lib/ddllib.php
  24. function xmldb_sloodle_upgrade($oldversion=0) {
  25. global $CFG, $THEME, $db;
  26. $result = true;
  27. // Note: any upgrade to Sloodle 0.3 is a major process, due to the huge change of architecture.
  28. // As such, the only data worth preserving is the avatar table ('sloodle_users').
  29. // All other tables will be dropped and re-inserted.
  30. // Is this an upgrade from pre-0.3?
  31. if ($result && $oldversion < 2008052800) {
  32. // Drop all other tables
  33. echo "Dropping old tables<br/>";
  34. // (We can ignore failed drops)
  35. /// Drop 'sloodle' table
  36. $table = new XMLDBTable('sloodle');
  37. drop_table($table);
  38. /// Drop 'sloodle_config' table
  39. $table = new XMLDBTable('sloodle_config');
  40. /// Drop 'sloodle_active_object' table
  41. $table = new XMLDBTable('sloodle_active_object');
  42. drop_table($table);
  43. /// Drop 'sloodle_classroom_setup_profile' table
  44. $table = new XMLDBTable('sloodle_classroom_setup_profile');
  45. drop_table($table);
  46. /// Drop 'sloodle_classroom_setup_profile_entry' table
  47. $table = new XMLDBTable('sloodle_classroom_setup_profile_entry');
  48. drop_table($table);
  49. // Insert all the new tables
  50. echo "Inserting new tables...<br/>";
  51. /// Insert 'sloodle' table
  52. echo " - sloodle<br/>";
  53. $table = new XMLDBTable('sloodle');
  54. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  55. $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  56. $table->addFieldInfo('type', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
  57. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  58. $table->addFieldInfo('intro', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
  59. $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  60. $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  61. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  62. $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
  63. $result = $result && create_table($table);
  64. if (!$result) echo "error<br/>";
  65. /// Insert 'sloodle_controller' table
  66. echo " - sloodle_controller<br/>";
  67. $table = new XMLDBTable('sloodle_controller');
  68. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  69. $table->addFieldInfo('sloodleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  70. $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  71. $table->addFieldInfo('password', XMLDB_TYPE_CHAR, '9', null, null, null, null, null, null);
  72. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  73. $table->addIndexInfo('sloodleid', XMLDB_INDEX_UNIQUE, array('sloodleid'));
  74. $result = $result && create_table($table);
  75. if (!$result) echo "error<br/>";
  76. /// Insert 'sloodle_distributor' table
  77. echo " - sloodle_distributor<br/>";
  78. $table = new XMLDBTable('sloodle_distributor');
  79. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  80. $table->addFieldInfo('sloodleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  81. $table->addFieldInfo('channel', XMLDB_TYPE_CHAR, '36', null, XMLDB_NOTNULL, null, null, null, null);
  82. $table->addFieldInfo('timeupdated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  83. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  84. $result = $result && create_table($table);
  85. if (!$result) echo "error<br/>";
  86. /// Insert 'sloodle_distributor_entry' table
  87. echo " - sloodle_distributor_entry<br/>";
  88. $table = new XMLDBTable('sloodle_distributor_entry');
  89. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  90. $table->addFieldInfo('distributorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  91. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  92. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  93. $result = $result && create_table($table);
  94. if (!$result) echo "error<br/>";
  95. /// Insert 'sloodle_course' table
  96. echo " - sloodle_course<br/>";
  97. $table = new XMLDBTable('sloodle_course');
  98. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  99. $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  100. $table->addFieldInfo('autoreg', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  101. $table->addFieldInfo('autoenrol', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  102. $table->addFieldInfo('loginzonepos', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
  103. $table->addFieldInfo('loginzonesize', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
  104. $table->addFieldInfo('loginzoneregion', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
  105. $table->addFieldInfo('loginzoneupdated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  106. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  107. $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
  108. $result = $result && create_table($table);
  109. if (!$result) echo "error<br/>";
  110. /// Insert 'sloodle_pending_avatars' table
  111. echo " - sloodle_pending_avatar<br/>";
  112. $table = new XMLDBTable('sloodle_pending_avatars');
  113. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  114. $table->addFieldInfo('uuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  115. $table->addFieldInfo('avname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  116. $table->addFieldInfo('lst', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  117. $table->addFieldInfo('timeupdated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  118. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  119. $table->addIndexInfo('uuid', XMLDB_INDEX_NOTUNIQUE, array('uuid'));
  120. $result = $result && create_table($table);
  121. if (!$result) echo "error<br/>";
  122. /// Insert 'sloodle_active_object' table
  123. echo " - sloodle_active_object<br/>";
  124. $table = new XMLDBTable('sloodle_active_object');
  125. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  126. $table->addFieldInfo('controllerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  127. $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  128. $table->addFieldInfo('uuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  129. $table->addFieldInfo('password', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  130. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  131. $table->addFieldInfo('type', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
  132. $table->addFieldInfo('timeupdated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  133. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  134. $table->addIndexInfo('uuid', XMLDB_INDEX_UNIQUE, array('uuid'));
  135. $result = $result && create_table($table);
  136. if (!$result) echo "error<br/>";
  137. /// Insert 'sloodle_object_config' table
  138. echo " - sloodle_object_config<br/>";
  139. $table = new XMLDBTable('sloodle_object_config');
  140. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  141. $table->addFieldInfo('object', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  142. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  143. $table->addFieldInfo('value', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  144. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  145. $table->addIndexInfo('object-name', XMLDB_INDEX_UNIQUE, array('object', 'name'));
  146. $result = $result && create_table($table);
  147. if (!$result) echo "error<br/>";
  148. /// Insert 'sloodle_login_notifications' table
  149. echo " - sloodle_login_notifications<br/>";
  150. $table = new XMLDBTable('sloodle_login_notifications');
  151. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  152. $table->addFieldInfo('destination', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  153. $table->addFieldInfo('avatar', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  154. $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  155. $table->addFieldInfo('password', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  156. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  157. $result = $result && create_table($table);
  158. if (!$result) echo "error<br/>";
  159. /// Insert 'sloodle_layout' table
  160. echo " - sloodle_layout<br/>";
  161. $table = new XMLDBTable('sloodle_layout');
  162. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  163. $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  164. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  165. $table->addFieldInfo('timeupdated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  166. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  167. $table->addIndexInfo('course-name', XMLDB_INDEX_UNIQUE, array('course', 'name'));
  168. $result = $result && create_table($table);
  169. if (!$result) echo "error<br/>";
  170. /// Insert 'sloodle_layout_entry' table
  171. echo " - sloodle_layout_entry<br/>";
  172. $table = new XMLDBTable('sloodle_layout_entry');
  173. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  174. $table->addFieldInfo('layout', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  175. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  176. $table->addFieldInfo('position', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  177. $table->addFieldInfo('rotation', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  178. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  179. $table->addIndexInfo('layout', XMLDB_INDEX_NOTUNIQUE, array('layout'));
  180. $result = $result && create_table($table);
  181. if (!$result) echo "error<br/>";
  182. /// Insert 'sloodle_loginzone_allocation' table
  183. echo " - sloodle_loginzone_allocation<br/>";
  184. $table = new XMLDBTable('sloodle_loginzone_allocation');
  185. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  186. $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  187. $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  188. $table->addFieldInfo('position', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  189. $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  190. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  191. $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
  192. $table->addIndexInfo('userid', XMLDB_INDEX_UNIQUE, array('userid'));
  193. $result = $result && create_table($table);
  194. if (!$result) echo "error<br/>";
  195. /// Insert 'sloodle_user_object' table
  196. echo " - sloodle_user_object<br/>";
  197. $table = new XMLDBTable('sloodle_user_object');
  198. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  199. $table->addFieldInfo('avuuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  200. $table->addFieldInfo('objuuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  201. $table->addFieldInfo('objname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  202. $table->addFieldInfo('password', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  203. $table->addFieldInfo('authorised', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  204. $table->addFieldInfo('timeupdated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  205. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  206. $table->addIndexInfo('objuuid', XMLDB_INDEX_UNIQUE, array('objuuid'));
  207. $result = $result && create_table($table);
  208. if (!$result) echo "error<br/>";
  209. /// Upgrade sloodle_users table
  210. echo "Upgrading sloodle_users table...<br/>";
  211. $table = new XMLDBTable('sloodle_users');
  212. echo " - dropping old fields<br/>";
  213. // Drop the loginzone fields (we don't care about success or otherwise... not all fields will be present in all versions)
  214. $field = new XMLDBField('loginposition');
  215. drop_field($table, $field);
  216. $field = new XMLDBField('loginpositionexpires');
  217. drop_field($table, $field);
  218. $field = new XMLDBField('loginpositionregion');
  219. drop_field($table, $field);
  220. $field = new XMLDBField('loginsecuritytoken');
  221. drop_field($table, $field);
  222. // Drop the old 'online' field (was going to be a boolean, but was never used)
  223. $field = new XMLDBField('online');
  224. drop_field($table, $field);
  225. // Add the new 'lastactive' field
  226. echo " - adding lastactive field<br/>";
  227. $field = new XMLDBField('lastactive');
  228. $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'avname');
  229. $result = $result && add_field($table, $field);
  230. if (!$result) echo "error<br/>";
  231. /// Purge redundant avatar entries
  232. echo "Purging redundant avatar entries...<br/>";
  233. $sql = " DELETE FROM {$CFG->prefix}sloodle_users
  234. WHERE userid = 0 OR uuid = '' OR avname = ''
  235. ";
  236. execute_sql($sql);
  237. }
  238. if ($result && $oldversion < 2009020201) {
  239. /// Define table sloodle_presenter_entry to be created
  240. $table = new XMLDBTable('sloodle_presenter_entry');
  241. /// Adding fields to table sloodle_presenter_entry
  242. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  243. $table->addFieldInfo('sloodleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  244. $table->addFieldInfo('source', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
  245. $table->addFieldInfo('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, 'web');
  246. $table->addFieldInfo('ordering', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  247. /// Adding keys to table sloodle_presenter_entry
  248. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  249. /// Adding indexes to table sloodle_presenter_entry
  250. $table->addIndexInfo($CFG->prefix.'sloopresentr_slo_ix', XMLDB_INDEX_NOTUNIQUE, array('sloodleid'));
  251. $table->addIndexInfo($CFG->prefix.'sloopresentr_typ_ix', XMLDB_INDEX_NOTUNIQUE, array('type'));
  252. /// Launch create table for sloodle_presenter_entry
  253. $result = $result && create_table($table);
  254. }
  255. if ($result && $oldversion < 2009020701) {
  256. /// Define table sloodle_layout_entry_config to be created
  257. $table = new XMLDBTable('sloodle_layout_entry_config');
  258. /// Adding fields to table sloodle_layout_entry_config
  259. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  260. $table->addFieldInfo('layout_entry', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
  261. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
  262. $table->addFieldInfo('value', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
  263. /// Adding keys to table sloodle_layout_entry_config
  264. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  265. /// Launch create table for sloodle_layout_entry_config
  266. $result = $result && create_table($table);
  267. }
  268. // Add a name field to the Presenter entries.
  269. if ($result && $oldversion < 2009031002) {
  270. /// Define field name to be added to sloodle_presenter_entry
  271. $table = new XMLDBTable('sloodle_presenter_entry');
  272. $field = new XMLDBField('name');
  273. $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'sloodleid');
  274. /// Launch add field name
  275. $result = $result && add_field($table, $field);
  276. }
  277. // Add the SLOODLE Presenter table (we previously only had entries, but no data about the Presenter itself.)
  278. if ($result && $oldversion < 2009031003) {
  279. /// Define table sloodle_presenter to be created
  280. $table = new XMLDBTable('sloodle_presenter');
  281. /// Adding fields to table sloodle_presenter
  282. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  283. $table->addFieldInfo('sloodleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
  284. $table->addFieldInfo('framewidth', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '512');
  285. $table->addFieldInfo('frameheight', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, '512');
  286. /// Adding keys to table sloodle_presenter
  287. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  288. $table->addKeyInfo('sloodleid', XMLDB_KEY_UNIQUE, array('sloodleid'));
  289. /// Launch create table for sloodle_presenter
  290. $result = $result && create_table($table);
  291. if (!$result) return $result;
  292. // For sake of people who installed a test version of SLOODLE 0.4, we need to automatically create secondary Presenter instances.
  293. // These would normally be created when creating an instance of the module, but this table didn't exist during test versions.
  294. // Go through all SLOODLE modules with type "Presenter" and add an empty secondary entry on their behalf, with default values.
  295. $sloodlerecords = sloodle_get_records('sloodle', 'type', 'presenter');
  296. if (!$sloodlerecords) $sloodlerecords = array();
  297. foreach ($sloodlerecords as $sr) {
  298. // Construct a default presenter instance for it
  299. $presenterrecord = new stdClass();
  300. $presenterrecord->sloodleid = $sr->id;
  301. sloodle_insert_record('sloodle_presenter', $presenterrecord);
  302. }
  303. }
  304. if ($result && $oldversion < 2009110500) {
  305. echo "Converting Presenter slide type IDs... ";
  306. // Standardize any Presenter slides to use type names "image", "web", and "video".
  307. // The slide plugins for 1.0 initially used class names, like SloodlePluginPresenterSlideImage.
  308. // That's laborious and necessary, so we're reverting back to the original type names.
  309. $allslides = sloodle_get_records('sloodle_presenter_entry');
  310. $numupdated = 0;
  311. if ($allslides) {
  312. foreach ($allslides as $slide) {
  313. // Update the type name if necessary
  314. $updated = true;
  315. switch (strtolower($slide->type)) {
  316. // Image slides
  317. case 'sloodlepluginpresenterslideimage': case 'presenterslideimage':
  318. $slide->type = 'image';
  319. break;
  320. // Web slides
  321. case 'sloodlepluginpresenterslideweb': case 'presenterslideweb':
  322. $slide->type = 'web';
  323. break;
  324. // Video slides
  325. case 'sloodlepluginpresenterslidevideo': case 'presenterslidevideo':
  326. $slide->type = 'video';
  327. break;
  328. // Unrecognised type
  329. default:
  330. $updated = false;
  331. break;
  332. }
  333. // Update the database record
  334. if ($updated) {
  335. sloodle_update_record('sloodle_presenter_entry', $slide);
  336. $numupdated++;
  337. }
  338. }
  339. }
  340. echo "{$numupdated} slide(s) updated.<br/>";
  341. }
  342. if ($result && !table_exists(new XMLDBTable('sloodle_currency_types'))) {
  343. $table = new XMLDBTable('sloodle_currency_types');
  344. echo "creating new currency table for site wide virtual currency<br/>";
  345. $field = new XMLDBField('id');
  346. $field->setAttributes(XMLDB_TYPE_INTEGER, '11', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null);
  347. $table->addField($field);
  348. $field = new XMLDBField('name');
  349. $field->setAttributes(XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null, 'id');
  350. $table->addField($field);
  351. $field = new XMLDBField('timemodified');
  352. $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'units');
  353. $table->addField($field);
  354. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  355. $result = $result && create_table($table);
  356. $newCurrency = new stdClass();
  357. $newCurrency->name="Credits";
  358. if (sloodle_insert_record('sloodle_currency_types',$newCurrency))echo "Added Credits currency: OK<br>";
  359. }
  360. if ($result && $oldversion < 2010110311) {
  361. $table = new XMLDBTable('sloodle_users');
  362. // Add the new 'profilepic' field
  363. echo " - adding \'profilepic\' field<br/>";
  364. $field = new XMLDBField('profilepic');
  365. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, '', 'avname');
  366. $result = $result && add_field($table,$field);
  367. }
  368. if ($result && $oldversion < 2010110501) {
  369. /// Define field httpinurl to be added to sloodle_active_object
  370. $table = new XMLDBTable('sloodle_active_object');
  371. $field = new XMLDBField('httpinurl');
  372. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'timeupdated');
  373. /// Launch add field httpinurl
  374. $result = $result && add_field($table, $field);
  375. }
  376. if ($result && $oldversion < 2010121703) {
  377. /// Define field layoutentryid to be added to sloodle_active_object
  378. $table = new XMLDBTable('sloodle_active_object');
  379. $field = new XMLDBField('layoutentryid');
  380. $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'httpinurl');
  381. /// Launch add field layoutentryid
  382. $result = $result && add_field($table, $field);
  383. /// Define field rezzeruuid to be added to sloodle_active_object
  384. $table = new XMLDBTable('sloodle_active_object');
  385. $field = new XMLDBField('rezzeruuid');
  386. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'layoutentryid');
  387. /// Launch add field rezzeruuid
  388. $result = $result && add_field($table, $field);
  389. /// Define field position to be added to sloodle_active_object
  390. $table = new XMLDBTable('sloodle_active_object');
  391. $field = new XMLDBField('position');
  392. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'rezzeruuid');
  393. /// Launch add field position
  394. $result = $result && add_field($table, $field);
  395. /// Define field rotation to be added to sloodle_active_object
  396. $table = new XMLDBTable('sloodle_active_object');
  397. $field = new XMLDBField('rotation');
  398. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'position');
  399. /// Launch add field rotation
  400. $result = $result && add_field($table, $field);
  401. /// Define field region to be added to sloodle_active_object
  402. $table = new XMLDBTable('sloodle_active_object');
  403. $field = new XMLDBField('region');
  404. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'rotation');
  405. /// Launch add field region
  406. $result = $result && add_field($table, $field);
  407. /// Define index rezzeruuid (not unique) to be added to sloodle_active_object
  408. $table = new XMLDBTable('sloodle_active_object');
  409. $index = new XMLDBIndex('rezzeruuid');
  410. $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('rezzeruuid'));
  411. /// Launch add index rezzeruuid
  412. $result = $result && add_index($table, $index);
  413. /// Define index layoutentryid (not unique) to be added to sloodle_active_object
  414. $table = new XMLDBTable('sloodle_active_object');
  415. $index = new XMLDBIndex('layoutentryid');
  416. $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('layoutentryid'));
  417. /// Launch add index layoutentryid
  418. $result = $result && add_index($table, $index);
  419. }
  420. if ($result && $oldversion < 2011062700) {
  421. /// Define table sloodle_award_rounds to be created
  422. $table = new XMLDBTable('sloodle_award_rounds');
  423. /// Adding fields to table sloodle_award_rounds
  424. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  425. $table->addFieldInfo('timestarted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  426. $table->addFieldInfo('timeended', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  427. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);
  428. $table->addFieldInfo('controllerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);
  429. /// Adding keys to table sloodle_award_rounds
  430. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  431. /// Launch create table for sloodle_award_rounds
  432. $result = $result && create_table($table);
  433. }
  434. if ($result && $oldversion < 2011062700) {
  435. /// Define table sloodle_award_points to be created
  436. $table = new XMLDBTable('sloodle_award_points');
  437. /// Adding fields to table sloodle_award_points
  438. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  439. $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  440. $table->addFieldInfo('currencyid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  441. $table->addFieldInfo('amount', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null);
  442. $table->addFieldInfo('timeawarded', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  443. $table->addFieldInfo('roundid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  444. /// Adding keys to table sloodle_award_points
  445. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  446. /// Launch create table for sloodle_award_points
  447. $result = $result && create_table($table);
  448. }
  449. if ($result && $oldversion < 2011070500 ) {
  450. /// Define field description to be added to sloodle_award_points
  451. $table = new XMLDBTable('sloodle_award_points');
  452. $field = new XMLDBField('description');
  453. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'roundid');
  454. /// Launch add field description
  455. $result = $result && add_field($table, $field);
  456. /// Define key poiroufk (foreign) to be added to sloodle_award_points
  457. $table = new XMLDBTable('sloodle_award_points');
  458. $key = new XMLDBKey('poiroufk');
  459. $key->setAttributes(XMLDB_KEY_FOREIGN, array('roundid'), 'sloodle_award_rounds', array('id'));
  460. /// Launch add key poiroufk
  461. $result = $result && add_key($table, $key);
  462. /// Define key poiusefk (foreign) to be added to sloodle_award_points
  463. $table = new XMLDBTable('sloodle_award_points');
  464. $key = new XMLDBKey('poiusefk');
  465. $key->setAttributes(XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
  466. /// Launch add key poiusefk
  467. $result = $result && add_key($table, $key);
  468. /// Define key poicurfk (foreign) to be added to sloodle_award_points
  469. $table = new XMLDBTable('sloodle_award_points');
  470. $key = new XMLDBKey('poicurfk');
  471. $key->setAttributes(XMLDB_KEY_FOREIGN, array('currencyid'), 'sloodle_award_currency', array('id'));
  472. /// Launch add key poicurfk
  473. $result = $result && add_key($table, $key);
  474. /// Define field courseid to be added to sloodle_award_rounds
  475. $table = new XMLDBTable('sloodle_award_rounds');
  476. $field = new XMLDBField('courseid');
  477. $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'controllerid');
  478. /// Launch add field courseid
  479. $result = $result && add_field($table, $field);
  480. }
  481. if ($result && $oldversion < 2011070501) {
  482. /// Define field imageurl to be added to sloodle_currency_types
  483. $table = new XMLDBTable('sloodle_currency_types');
  484. $field = new XMLDBField('imageurl');
  485. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'timemodified');
  486. /// Launch add field imageurl
  487. $result = $result && add_field($table, $field);
  488. /// Define field displayorder to be added to sloodle_currency_types
  489. $table = new XMLDBTable('sloodle_currency_types');
  490. $field = new XMLDBField('displayorder');
  491. $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'imageurl');
  492. /// Launch add field displayorder
  493. $result = $result && add_field($table, $field);
  494. }
  495. if ($result && $oldversion < 2011070900) {
  496. /// Define field mediakey to be added to sloodle_active_object
  497. $table = new XMLDBTable('sloodle_active_object');
  498. $field = new XMLDBField('mediakey');
  499. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'httpinurl');
  500. /// Launch add field mediakey
  501. $result = $result && add_field($table, $field);
  502. /// Define field lastmessagetimestamp to be added to sloodle_active_object
  503. $table = new XMLDBTable('sloodle_active_object');
  504. $field = new XMLDBField('lastmessagetimestamp');
  505. $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'mediakey');
  506. /// Launch add field lastmessagetimestamp
  507. $result = $result && add_field($table, $field);
  508. /// Define field httpinpassword to be added to sloodle_active_object
  509. $table = new XMLDBTable('sloodle_active_object');
  510. $field = new XMLDBField('httpinpassword');
  511. $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null, 'lastmessagetimestamp');
  512. /// Launch add field httpinpassword
  513. $result = $result && add_field($table, $field);
  514. }
  515. // Basic SLOODLE Tracker tables
  516. // Sloodle 1.2 snuck in in the middle of development and messed up the normal order.
  517. // This should be OK as long as we don't get another release in between...
  518. // If we absolutely have to, leaving the space up to 2009073000 to denote 1.2-series releases.
  519. if ( $result && !table_exists(new XMLDBTable('sloodle_activity_tool')) ) {
  520. /// Insert 'sloodle_activity_tool' table
  521. echo " - sloodle_activity_tool<br/>";
  522. $table = new XMLDBTable('sloodle_activity_tool');
  523. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  524. $table->addFieldInfo('trackerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  525. $table->addFieldInfo('uuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  526. $table->addFieldInfo('description', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  527. $table->addFieldInfo('taskname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  528. $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  529. $table->addFieldInfo('type', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null);
  530. $table->addFieldInfo('timeupdated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  531. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  532. $table->addIndexInfo('uuid', XMLDB_INDEX_UNIQUE, array('uuid'));
  533. $result = $result && create_table($table);
  534. if (!$result) echo "error<br/>";
  535. }
  536. /// Insert 'sloodle_activity_tracker' table
  537. if ( $result && !table_exists(new XMLDBTable('sloodle_activity_tracker')) ) {
  538. echo " - sloodle_activity_tracker<br/>";
  539. $table = new XMLDBTable('sloodle_activity_tracker');
  540. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  541. $table->addFieldInfo('trackerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  542. $table->addFieldInfo('objuuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  543. $table->addFieldInfo('avuuid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
  544. $table->addFieldInfo('timeupdated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
  545. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  546. $result = $result && create_table($table);
  547. if (!$result) echo "error<br/>";
  548. }
  549. if ( $result && !table_exists(new XMLDBTable('sloodle_tracker')) ) {
  550. /// Define table sloodle_tracker to be created
  551. $table = new XMLDBTable('sloodle_tracker');
  552. /// Adding fields to table sloodle_tracker
  553. $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
  554. $table->addFieldInfo('sloodleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
  555. /// Adding keys to table sloodle_tracker
  556. $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
  557. $table->addKeyInfo('sloodleid', XMLDB_KEY_UNIQUE, array('sloodleid'));
  558. /// Launch create table for sloodle_tracker
  559. $result = $result && create_table($table);
  560. }
  561. if ($result && $oldversion < 2011071101) {
  562. // needed by moodle 2 (but should already have been in <=1.9)
  563. // see http://docs.moodle.org/dev/Text_formats_2.0
  564. $table = new XMLDBTable('sloodle');
  565. $field = new XMLDBField('introformat');
  566. $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, null, 'intro');
  567. if (!field_exists($table, $field)) {
  568. add_field($table, $field);
  569. }
  570. }
  571. if ($result && $oldversion < 2011072301) {
  572. /// Define field controllerid to be added to sloodle_layout
  573. $table = new XMLDBTable('sloodle_layout');
  574. $field = new XMLDBField('controllerid');
  575. $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'timeupdated');
  576. /// Launch add field controllerid
  577. $result = $result && add_field($table, $field);
  578. }
  579. return $result;
  580. }
  581. ?>