tripal_views.install 8.8 KB

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