tripal_views.install 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. // Add arguments to joins
  73. db_add_field(
  74. $ret,
  75. 'tripal_views_join',
  76. 'arguments',
  77. array(
  78. 'description' => 'arguments that may get passed to the handler',
  79. 'type' => 'text',
  80. 'size' => 'normal'
  81. )
  82. );
  83. return $ret;
  84. }
  85. /**
  86. * Describe the Tripal Views Schema
  87. *
  88. * Tables include:
  89. * - tripal_views: main table for views integration setups
  90. * - tripal_views_field: keeps track of all fields related to a given views integration setup
  91. * - tripal_views_join: keeps track of joins between the current views integration setup
  92. * and other tables.
  93. * - tripal_views_handlers: keeps track of which handlers to use for a given field
  94. *
  95. * @ingroup tripal_views
  96. */
  97. function tripal_views_views_schema() {
  98. $schema = array();
  99. $schema['tripal_views'] = array(
  100. 'description' => 'contains the setups, their materialized view id and base table name that was used.',
  101. 'fields' => array(
  102. 'setup_id' => array(
  103. 'description' => 'the id of the setup',
  104. 'type' => 'serial',
  105. 'unsigned' => TRUE,
  106. 'not null' => TRUE,
  107. ),
  108. 'mview_id' => array(
  109. 'description' => 'the materialized view used for this setup',
  110. 'type' => 'int',
  111. 'unsigned' => TRUE,
  112. ),
  113. 'base_table' => array(
  114. 'description' => 'either TRUE (1) or FALSE (0) depending on whether the current table should be a bast table of a View',
  115. 'type' => 'int',
  116. 'not null ' => TRUE,
  117. 'default' => 1
  118. ),
  119. 'table_name' => array(
  120. 'description' => 'the table name being integrated.',
  121. 'type' => 'varchar',
  122. 'length' => 255,
  123. 'not null' => TRUE,
  124. 'default' => '',
  125. ),
  126. 'priority' => array(
  127. 'description' => 'when there are 2+ entries for the same table, the entry with the lightest (drupal-style) priority is used.',
  128. 'type' => 'int',
  129. ),
  130. 'name' => array(
  131. 'description' => 'Human readable name of this setup',
  132. 'type' => 'varchar',
  133. 'length' => 255,
  134. 'not null' => TRUE,
  135. 'default' => '',
  136. ),
  137. 'comment' => array(
  138. 'description' => 'add notes about this views setup',
  139. 'type' => 'text',
  140. 'size' => 'normal',
  141. 'not null' => FALSE,
  142. 'default' => '',
  143. ),
  144. ),
  145. 'unique_keys' => array(
  146. 'setup_id' => array('setup_id'),
  147. 'priority' => array('table_name', 'priority'),
  148. ),
  149. 'indexes' => array(
  150. 'priority' => array('table_name', 'priority'),
  151. ),
  152. 'primary key' => array('setup_id'),
  153. );
  154. $schema['tripal_views_field'] = array(
  155. 'description' => 'keep track of fields available for a given table',
  156. 'fields' => array(
  157. 'setup_id' => array(
  158. 'description' => 'the id of the setup',
  159. 'type' => 'int',
  160. 'unsigned' => TRUE,
  161. 'not null' => TRUE,
  162. ),
  163. 'column_name' => array(
  164. 'description' => 'the name of the field in the database',
  165. 'type' => 'varchar',
  166. 'length' => '255',
  167. 'not null' => TRUE,
  168. ),
  169. 'name' => array(
  170. 'description' => 'the human-readable name of the field',
  171. 'type' => 'varchar',
  172. 'length' => '255',
  173. 'not null' => TRUE,
  174. ),
  175. 'description' => array(
  176. 'description' => 'A short description of the field -seen under the field in the views UI',
  177. 'type' => 'varchar',
  178. 'length' => '255',
  179. 'not null' => TRUE,
  180. ),
  181. 'type' => array(
  182. 'description' => 'the database type of this field (ie: int, varchar)',
  183. 'type' => 'varchar',
  184. 'length' => '50',
  185. 'not null' => TRUE,
  186. ),
  187. ),
  188. 'primary key' => array('setup_id', 'column_name')
  189. );
  190. $schema['tripal_views_join'] = array(
  191. 'description' => 'coordinate the joining of tables',
  192. 'fields' => array(
  193. 'view_join_id' => array(
  194. 'description' => 'the id of the join',
  195. 'type' => 'serial',
  196. 'unsigned' => TRUE,
  197. 'not null' => TRUE,
  198. ),
  199. 'setup_id' => array(
  200. 'description' => 'setup id from tripal_views table',
  201. 'type' => 'int',
  202. 'unsigned' => TRUE,
  203. 'not null' => TRUE,
  204. ),
  205. 'base_table' => array(
  206. 'description' => 'the name of the base table',
  207. 'type' => 'varchar',
  208. 'length' => '255',
  209. 'not null' => TRUE,
  210. 'default' => '',
  211. ),
  212. 'base_field' => array(
  213. 'description' => 'the name of the base table column that will be joined',
  214. 'type' => 'varchar',
  215. 'length' => '255',
  216. 'not null' => TRUE,
  217. 'default' => '',
  218. ),
  219. 'left_table' => array(
  220. 'description' => 'the table on which to perform a left join',
  221. 'type' => 'varchar',
  222. 'length' => '255',
  223. 'not null' => TRUE,
  224. 'default' => '',
  225. ),
  226. 'left_field' => array(
  227. 'description' => 'the column on which to perform a left join',
  228. 'type' => 'varchar',
  229. 'length' => '255',
  230. 'not null' => TRUE,
  231. 'default' => '',
  232. ),
  233. 'handler' => array(
  234. 'description' => 'the name of the handler',
  235. 'type' => 'varchar',
  236. 'length' => '255',
  237. 'not null' => TRUE,
  238. 'default' => '',
  239. ),
  240. 'arguments' => array(
  241. 'description' => 'arguments that may get passed to the handler',
  242. 'type' => 'text',
  243. 'size' => 'normal',
  244. ),
  245. ),
  246. 'unique_keys' => array(
  247. 'setup_id' => array('view_join_id'),
  248. ),
  249. 'primary key' => array('view_join_id'),
  250. );
  251. $schema['tripal_views_handlers'] = array(
  252. 'description' => 'in formation for views: column and views handler name',
  253. 'fields' => array(
  254. 'handler_id' => array(
  255. 'description' => 'the id of the handler',
  256. 'type' => 'serial',
  257. 'unsigned' => TRUE,
  258. 'not null' => TRUE,
  259. ),
  260. 'setup_id' => array(
  261. 'description' => 'setup id from the tripal_views table',
  262. 'type' => 'int',
  263. 'unsigned' => TRUE,
  264. 'not null' => TRUE,
  265. ),
  266. 'column_name' => array(
  267. 'description' => '',
  268. 'type' => 'varchar',
  269. 'length' => '255',
  270. 'not null' => TRUE,
  271. 'default' => '',
  272. ),
  273. 'handler_type' => array(
  274. 'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
  275. 'type' => 'varchar',
  276. 'length' => '50',
  277. 'not null' => TRUE,
  278. 'default' => '',
  279. ),
  280. 'handler_name' => array(
  281. 'description' => 'the name of the handler',
  282. 'type' => 'varchar',
  283. 'length' => '255',
  284. 'not null' => TRUE,
  285. 'default' => '',
  286. ),
  287. 'arguments' => array(
  288. 'description' => 'arguments that may get passed to the handler',
  289. 'type' => 'text',
  290. 'size' => 'normal',
  291. 'not null' => FALSE,
  292. 'default' => '',
  293. ),
  294. ),
  295. 'unique_keys' => array(
  296. 'setup_id' => array('handler_id'),
  297. ),
  298. 'primary key' => array('handler_id'),
  299. );
  300. return $schema;
  301. }
  302. /**
  303. * Implementation of hook_requirements().
  304. *
  305. */
  306. function tripal_views_requirements($phase) {
  307. $requirements = array();
  308. if ($phase == 'install') {
  309. // make sure chado is installed
  310. $version = tripal_core_set_chado_version();
  311. if ($version == 'not installed') {
  312. $requirements ['tripal_views'] = array(
  313. 'title' => "tripal_views",
  314. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  315. 'severity' => REQUIREMENT_ERROR,
  316. );
  317. }
  318. }
  319. return $requirements;
  320. }