tripal_views.install 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. return $ret;
  68. }
  69. /**
  70. * Describe the Tripal Views Schema
  71. *
  72. * Tables include:
  73. * - tripal_views: main table for views integration setups
  74. * - tripal_views_field: keeps track of all fields related to a given views integration setup
  75. * - tripal_views_join: keeps track of joins between the current views integration setup
  76. * and other tables.
  77. * - tripal_views_handlers: keeps track of which handlers to use for a given field
  78. *
  79. * @ingroup tripal_views
  80. */
  81. function tripal_views_views_schema() {
  82. $schema = array();
  83. $schema['tripal_views'] = array(
  84. 'description' => 'contains the setupes, their materialized view id and base table name that was used.',
  85. 'fields' => array(
  86. 'setup_id' => array(
  87. 'description' => 'the id of the setup',
  88. 'type' => 'serial',
  89. 'unsigned' => TRUE,
  90. 'not null' => TRUE,
  91. ),
  92. 'mview_id' => array(
  93. 'description' => 'the materialized view used for this setup',
  94. 'type' => 'int',
  95. 'unsigned' => TRUE,
  96. ),
  97. 'table_name' => array(
  98. 'description' => 'the base table name to be used when using this setup. Use this field when not using a materialized view',
  99. 'type' => 'varchar',
  100. 'length' => 255,
  101. 'not null' => TRUE,
  102. 'default' => '',
  103. ),
  104. 'priority' => array(
  105. 'description' => 'when there are 2+ entries for the same table, the entry with the lightest (drupal-style) priority is used.',
  106. 'type' => 'int',
  107. ),
  108. 'name' => array(
  109. 'description' => 'Human readable name of this setup',
  110. 'type' => 'varchar',
  111. 'length' => 255,
  112. 'not null' => TRUE,
  113. 'default' => '',
  114. ),
  115. 'comment' => array(
  116. 'description' => 'add notes about this views setup',
  117. 'type' => 'text',
  118. 'size' => 'normal',
  119. 'not null' => FALSE,
  120. 'default' => '',
  121. ),
  122. ),
  123. 'unique_keys' => array(
  124. 'setup_id' => array('setup_id'),
  125. 'priority' => array('table_name', 'priority'),
  126. ),
  127. 'indexes' => array(
  128. 'priority' => array('table_name', 'priority'),
  129. ),
  130. 'primary key' => array('setup_id'),
  131. );
  132. $schema['tripal_views_field'] = array(
  133. 'description' => 'keep track of fields available for a given table',
  134. 'fields' => array(
  135. 'setup_id' => array(
  136. 'description' => 'the id of the setup',
  137. 'type' => 'int',
  138. 'unsigned' => TRUE,
  139. 'not null' => TRUE,
  140. ),
  141. 'column_name' => array(
  142. 'description' => 'the name of the field in the database',
  143. 'type' => 'varchar',
  144. 'length' => '255',
  145. 'not null' => TRUE,
  146. ),
  147. 'name' => array(
  148. 'description' => 'the human-readable name of the field',
  149. 'type' => 'varchar',
  150. 'length' => '255',
  151. 'not null' => TRUE,
  152. ),
  153. 'description' => array(
  154. 'description' => 'A short description of the field -seen under the field in the views UI',
  155. 'type' => 'varchar',
  156. 'length' => '255',
  157. 'not null' => TRUE,
  158. ),
  159. 'type' => array(
  160. 'description' => 'the database type of this field (ie: int, varchar)',
  161. 'type' => 'varchar',
  162. 'length' => '50',
  163. 'not null' => TRUE,
  164. ),
  165. ),
  166. 'primary key' => array('setup_id', 'column_name')
  167. );
  168. $schema['tripal_views_join'] = array(
  169. 'description' => 'coordinate the joining of tables',
  170. 'fields' => array(
  171. 'view_join_id' => array(
  172. 'description' => 'the id of the join',
  173. 'type' => 'serial',
  174. 'unsigned' => TRUE,
  175. 'not null' => TRUE,
  176. ),
  177. 'setup_id' => array(
  178. 'description' => 'setup id from tripal_views table',
  179. 'type' => 'int',
  180. 'unsigned' => TRUE,
  181. 'not null' => TRUE,
  182. ),
  183. 'base_table' => array(
  184. 'description' => 'the name of the base table',
  185. 'type' => 'varchar',
  186. 'length' => '255',
  187. 'not null' => TRUE,
  188. 'default' => '',
  189. ),
  190. 'base_field' => array(
  191. 'description' => 'the name of the base table column that will be joined',
  192. 'type' => 'varchar',
  193. 'length' => '255',
  194. 'not null' => TRUE,
  195. 'default' => '',
  196. ),
  197. 'left_table' => array(
  198. 'description' => 'the table on which to perform a left join',
  199. 'type' => 'varchar',
  200. 'length' => '255',
  201. 'not null' => TRUE,
  202. 'default' => '',
  203. ),
  204. 'left_field' => array(
  205. 'description' => 'the column on which to perform a left join',
  206. 'type' => 'varchar',
  207. 'length' => '255',
  208. 'not null' => TRUE,
  209. 'default' => '',
  210. ),
  211. 'handler' => array(
  212. 'description' => 'the name of the handler',
  213. 'type' => 'varchar',
  214. 'length' => '255',
  215. 'not null' => TRUE,
  216. 'default' => '',
  217. ),
  218. ),
  219. 'unique_keys' => array(
  220. 'setup_id' => array('view_join_id'),
  221. ),
  222. 'primary key' => array('view_join_id'),
  223. );
  224. $schema['tripal_views_handlers'] = array(
  225. 'description' => 'in formation for views: column and views handler name',
  226. 'fields' => array(
  227. 'handler_id' => array(
  228. 'description' => 'the id of the handler',
  229. 'type' => 'serial',
  230. 'unsigned' => TRUE,
  231. 'not null' => TRUE,
  232. ),
  233. 'setup_id' => array(
  234. 'description' => 'setup id from the tripal_views table',
  235. 'type' => 'int',
  236. 'unsigned' => TRUE,
  237. 'not null' => TRUE,
  238. ),
  239. 'column_name' => array(
  240. 'description' => '',
  241. 'type' => 'varchar',
  242. 'length' => '255',
  243. 'not null' => TRUE,
  244. 'default' => '',
  245. ),
  246. 'handler_type' => array(
  247. 'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
  248. 'type' => 'varchar',
  249. 'length' => '50',
  250. 'not null' => TRUE,
  251. 'default' => '',
  252. ),
  253. 'handler_name' => array(
  254. 'description' => 'the name of the handler',
  255. 'type' => 'varchar',
  256. 'length' => '255',
  257. 'not null' => TRUE,
  258. 'default' => '',
  259. ),
  260. 'arguments' => array(
  261. 'description' => 'arguments that may get passed to the handler',
  262. 'type' => 'text',
  263. 'size' => 'normal',
  264. 'not null' => FALSE,
  265. 'default' => '',
  266. ),
  267. ),
  268. 'unique_keys' => array(
  269. 'setup_id' => array('handler_id'),
  270. ),
  271. 'primary key' => array('handler_id'),
  272. );
  273. return $schema;
  274. }