tripal_views.install 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /**
  3. * @file
  4. * Functions related to installing/uninstalling this module
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal_views
  10. */
  11. function tripal_views_install() {
  12. // create the module's data directory
  13. tripal_create_moddir('tripal_views');
  14. // create the tables that manage materialized views and jobs
  15. drupal_install_schema('tripal_views');
  16. }
  17. /**
  18. * Implementation of hook_schema().
  19. *
  20. * @ingroup tripal_views
  21. */
  22. function tripal_views_schema() {
  23. $schema = tripal_views_get_schemas();
  24. return $schema;
  25. }
  26. /**
  27. * Implementation of hook_uninstall().
  28. *
  29. * @ingroup tripal_views
  30. */
  31. function tripal_views_uninstall() {
  32. drupal_uninstall_schema('tripal_views');
  33. }
  34. /**
  35. * This function simply defines all tables needed for the module to work
  36. * correctly. By putting the table definitions in a separate function we
  37. * can easily provide the entire list for hook_install or individual
  38. * tables for an update.
  39. *
  40. * @ingroup tripal_views
  41. */
  42. function tripal_views_get_schemas() {
  43. $schema = array();
  44. $temp = tripal_views_views_schema();
  45. foreach ($temp as $table => $arr) {
  46. $schema[$table] = $arr;
  47. }
  48. return $schema;
  49. }
  50. /**
  51. * Tripal Views Update for 6.x-0.4
  52. * - Add priority field to tripal_views
  53. * - Add handler field to tripal_views_join
  54. * - Add tripal_views_field table to keep track of fields for views integration
  55. */
  56. function tripal_views_update_6040() {
  57. $ret = array();
  58. // Add Priority to tripal_views
  59. db_add_field($ret, 'tripal_views', 'priority', array('type' => 'int'));
  60. db_add_unique_key($ret, 'tripal_views', 'priority', array('table_name', 'priority'));
  61. db_add_index($ret, 'tripal_views', 'priority', array('table_name', 'priority'));
  62. // Add handler to tripal_views_join
  63. db_add_field($ret, 'tripal_views_join', 'handler', array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''));
  64. // Add tripal_views_field to keep track of fields for views integration
  65. $schema = tripal_views_views_schema();
  66. db_create_table(&$ret, 'tripal_views_field', $schema['tripal_views_field']);
  67. // Add base_table TRUE/FALSE to tripal_views
  68. db_add_field($ret, 'tripal_views', 'base_table', array('type' => 'int', 'not null ' => TRUE,
  69. 'default' => 1));
  70. return $ret;
  71. }
  72. /**
  73. * Describe the Tripal Views Schema
  74. *
  75. * Tables include:
  76. * - tripal_views: main table for views integration setups
  77. * - tripal_views_field: keeps track of all fields related to a given views integration setup
  78. * - tripal_views_join: keeps track of joins between the current views integration setup
  79. * and other tables.
  80. * - tripal_views_handlers: keeps track of which handlers to use for a given field
  81. *
  82. * @ingroup tripal_views
  83. */
  84. function tripal_views_views_schema() {
  85. $schema = array();
  86. $schema['tripal_views'] = array(
  87. 'description' => 'contains the setupes, their materialized view id and base table name that was used.',
  88. 'fields' => array(
  89. 'setup_id' => array(
  90. 'description' => 'the id of the setup',
  91. 'type' => 'serial',
  92. 'unsigned' => TRUE,
  93. 'not null' => TRUE,
  94. ),
  95. 'mview_id' => array(
  96. 'description' => 'the materialized view used for this setup',
  97. 'type' => 'int',
  98. 'unsigned' => TRUE,
  99. ),
  100. 'table_name' => array(
  101. 'description' => 'the base table name to be used when using this setup. Use this field when not using a materialized view',
  102. 'type' => 'varchar',
  103. 'length' => 255,
  104. 'not null' => TRUE,
  105. 'default' => '',
  106. ),
  107. 'priority' => array(
  108. 'description' => 'when there are 2+ entries for the same table, the entry with the lightest (drupal-style) priority is used.',
  109. 'type' => 'int',
  110. ),
  111. 'name' => array(
  112. 'description' => 'Human readable name of this setup',
  113. 'type' => 'varchar',
  114. 'length' => 255,
  115. 'not null' => TRUE,
  116. 'default' => '',
  117. ),
  118. 'comment' => array(
  119. 'description' => 'add notes about this views setup',
  120. 'type' => 'text',
  121. 'size' => 'normal',
  122. 'not null' => FALSE,
  123. 'default' => '',
  124. ),
  125. ),
  126. 'unique_keys' => array(
  127. 'setup_id' => array('setup_id'),
  128. 'priority' => array('table_name', 'priority'),
  129. ),
  130. 'indexes' => array(
  131. 'priority' => array('table_name', 'priority'),
  132. ),
  133. 'primary key' => array('setup_id'),
  134. );
  135. $schema['tripal_views_field'] = array(
  136. 'description' => 'keep track of fields available for a given table',
  137. 'fields' => array(
  138. 'setup_id' => array(
  139. 'description' => 'the id of the setup',
  140. 'type' => 'int',
  141. 'unsigned' => TRUE,
  142. 'not null' => TRUE,
  143. ),
  144. 'column_name' => array(
  145. 'description' => 'the name of the field in the database',
  146. 'type' => 'varchar',
  147. 'length' => '255',
  148. 'not null' => TRUE,
  149. ),
  150. 'name' => array(
  151. 'description' => 'the human-readable name of the field',
  152. 'type' => 'varchar',
  153. 'length' => '255',
  154. 'not null' => TRUE,
  155. ),
  156. 'description' => array(
  157. 'description' => 'A short description of the field -seen under the field in the views UI',
  158. 'type' => 'varchar',
  159. 'length' => '255',
  160. 'not null' => TRUE,
  161. ),
  162. 'type' => array(
  163. 'description' => 'the database type of this field (ie: int, varchar)',
  164. 'type' => 'varchar',
  165. 'length' => '50',
  166. 'not null' => TRUE,
  167. ),
  168. ),
  169. 'primary key' => array('setup_id', 'column_name')
  170. );
  171. $schema['tripal_views_join'] = array(
  172. 'description' => 'coordinate the joining of tables',
  173. 'fields' => array(
  174. 'view_join_id' => array(
  175. 'description' => 'the id of the join',
  176. 'type' => 'serial',
  177. 'unsigned' => TRUE,
  178. 'not null' => TRUE,
  179. ),
  180. 'setup_id' => array(
  181. 'description' => 'setup id from tripal_views table',
  182. 'type' => 'int',
  183. 'unsigned' => TRUE,
  184. 'not null' => TRUE,
  185. ),
  186. 'base_table' => array(
  187. 'description' => 'the name of the base table',
  188. 'type' => 'varchar',
  189. 'length' => '255',
  190. 'not null' => TRUE,
  191. 'default' => '',
  192. ),
  193. 'base_field' => array(
  194. 'description' => 'the name of the base table column that will be joined',
  195. 'type' => 'varchar',
  196. 'length' => '255',
  197. 'not null' => TRUE,
  198. 'default' => '',
  199. ),
  200. 'left_table' => array(
  201. 'description' => 'the table on which to perform a left join',
  202. 'type' => 'varchar',
  203. 'length' => '255',
  204. 'not null' => TRUE,
  205. 'default' => '',
  206. ),
  207. 'left_field' => array(
  208. 'description' => 'the column on which to perform a left join',
  209. 'type' => 'varchar',
  210. 'length' => '255',
  211. 'not null' => TRUE,
  212. 'default' => '',
  213. ),
  214. 'handler' => array(
  215. 'description' => 'the name of the handler',
  216. 'type' => 'varchar',
  217. 'length' => '255',
  218. 'not null' => TRUE,
  219. 'default' => '',
  220. ),
  221. ),
  222. 'unique_keys' => array(
  223. 'setup_id' => array('view_join_id'),
  224. ),
  225. 'primary key' => array('view_join_id'),
  226. );
  227. $schema['tripal_views_handlers'] = array(
  228. 'description' => 'in formation for views: column and views handler name',
  229. 'fields' => array(
  230. 'handler_id' => array(
  231. 'description' => 'the id of the handler',
  232. 'type' => 'serial',
  233. 'unsigned' => TRUE,
  234. 'not null' => TRUE,
  235. ),
  236. 'setup_id' => array(
  237. 'description' => 'setup id from the tripal_views table',
  238. 'type' => 'int',
  239. 'unsigned' => TRUE,
  240. 'not null' => TRUE,
  241. ),
  242. 'column_name' => array(
  243. 'description' => '',
  244. 'type' => 'varchar',
  245. 'length' => '255',
  246. 'not null' => TRUE,
  247. 'default' => '',
  248. ),
  249. 'handler_type' => array(
  250. 'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
  251. 'type' => 'varchar',
  252. 'length' => '50',
  253. 'not null' => TRUE,
  254. 'default' => '',
  255. ),
  256. 'handler_name' => array(
  257. 'description' => 'the name of the handler',
  258. 'type' => 'varchar',
  259. 'length' => '255',
  260. 'not null' => TRUE,
  261. 'default' => '',
  262. ),
  263. 'arguments' => array(
  264. 'description' => 'arguments that may get passed to the handler',
  265. 'type' => 'text',
  266. 'size' => 'normal',
  267. 'not null' => FALSE,
  268. 'default' => '',
  269. ),
  270. ),
  271. 'unique_keys' => array(
  272. 'setup_id' => array('handler_id'),
  273. ),
  274. 'primary key' => array('handler_id'),
  275. );
  276. return $schema;
  277. }