tripal_core.module 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. require_once "jobs.php";
  3. require_once "mviews.php";
  4. require_once "chado_install.php";
  5. require_once "tripal_core.api.inc";
  6. /**
  7. * @defgroup tripal_modules Tripal Modules
  8. * @{
  9. * All documented functions for the various Tripal Modules
  10. * @}
  11. *
  12. * @defgroup tripal_core Core Tripal Module
  13. * @ingroup tripal_modules
  14. */
  15. /**
  16. * Implements hook_init().
  17. * Used to set the search_path, create default content and set default variables.
  18. *
  19. * @ingroup tripal_core
  20. */
  21. function tripal_core_init() {
  22. // the two lines below are necessary to ensure that the search_path
  23. // variable is always set. In the case where a view needs to query the
  24. // chado schema when it is local to the Drupal database. Otherwise the
  25. // search_path isn't set. When tripal_db_set_active is called it
  26. // automatically sets the serach path if chado is local to the
  27. // Drupal database
  28. $previous = tripal_db_set_active('chado');
  29. tripal_db_set_active($previous);
  30. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  31. // only if the chado database is present.
  32. if (tripal_core_is_chado_installed()) {
  33. $previous_db = tripal_db_set_active('chado'); // use chado database
  34. if (!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))) {
  35. $results = db_query("INSERT INTO {cv} (name,definition) ".
  36. "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  37. }
  38. if (!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))) {
  39. $results = db_query("INSERT INTO {db} (name,description) ".
  40. "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  41. }
  42. tripal_db_set_active($previous_db); // now use drupal database
  43. }
  44. // add some variables for all javasript to use for building URLs
  45. global $base_url;
  46. $theme_dir = drupal_get_path('theme', 'tripal');
  47. $clean_urls = variable_get('clean_url', 0);
  48. drupal_add_js(
  49. "var baseurl = '$base_url';
  50. var themedir = '$theme_dir';
  51. var isClean = $clean_urls;",
  52. 'inline');
  53. // make sure the date time settings are the way Tripal will insert them
  54. // otherwise PostgreSQL version that may have a different datestyle setting
  55. // will fail when inserting or updating a date column in a table.
  56. db_query("SET DATESTYLE TO '%s'", 'MDY');
  57. }
  58. /**
  59. * Implements hook_menu().
  60. * Defines all menu items needed by Tripal Core
  61. *
  62. * @ingroup tripal_core
  63. */
  64. function tripal_core_menu() {
  65. $items = array();
  66. // Triapl setting groups
  67. $items['admin/tripal'] = array(
  68. 'title' => 'Tripal Management',
  69. 'description' => "Manage the behavior or Tripal and its various modules.",
  70. 'position' => 'right',
  71. 'weight' => -5,
  72. 'page callback' => 'system_admin_menu_block_page',
  73. 'access arguments' => array('administer site configuration'),
  74. 'file' => 'system.admin.inc',
  75. 'file path' => drupal_get_path('module', 'system'),
  76. );
  77. $items['tripal_toggle_box_menu/%/%/%'] = array(
  78. 'title' => 'Toggle Box',
  79. 'page callback' => 'tripal_toggle_box_menu',
  80. 'page arguments' => array(1, 2, 3),
  81. 'access arguments' => array('access administration pages'),
  82. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  83. );
  84. $items['admin/tripal/chado_1_11_install'] = array(
  85. 'title' => 'Install Chado v1.11',
  86. 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
  87. 'page callback' => 'drupal_get_form',
  88. 'page arguments' => array('tripal_core_chado_v1_11_load_form'),
  89. 'access arguments' => array('access administration pages'),
  90. 'type' => MENU_NORMAL_ITEM,
  91. );
  92. // Jobs Management
  93. $items['admin/tripal/tripal_jobs'] = array(
  94. 'title' => 'Jobs',
  95. 'description' => 'Jobs managed by Tripal',
  96. 'page callback' => 'tripal_jobs_report',
  97. 'access arguments' => array('access administration pages'),
  98. 'type' => MENU_NORMAL_ITEM,
  99. );
  100. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  101. 'title' => 'Jobs',
  102. 'description' => 'Cancel a pending job',
  103. 'page callback' => 'tripal_jobs_cancel',
  104. 'page arguments' => array(4),
  105. 'access arguments' => array('access administration pages'),
  106. 'type' => MENU_CALLBACK,
  107. );
  108. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  109. 'title' => 'Jobs',
  110. 'description' => 'Re-run an existing job.',
  111. 'page callback' => 'tripal_jobs_rerun',
  112. 'page arguments' => array(4),
  113. 'access arguments' => array('access administration pages'),
  114. 'type' => MENU_CALLBACK,
  115. );
  116. $items['admin/tripal/tripal_jobs/view/%'] = array(
  117. 'title' => 'Jobs Details',
  118. 'description' => 'View job details.',
  119. 'page callback' => 'tripal_jobs_view',
  120. 'page arguments' => array(4),
  121. 'access arguments' => array('access administration pages'),
  122. 'type' => MENU_CALLBACK,
  123. );
  124. // Materialized Views
  125. $items['admin/tripal/mviews'] = array(
  126. 'title' => 'MViews',
  127. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  128. 'page callback' => 'tripal_mviews_report',
  129. 'access arguments' => array('access administration pages'),
  130. 'type' => MENU_NORMAL_ITEM,
  131. );
  132. $items['admin/tripal/mviews/report/%'] = array(
  133. 'title' => 'Materialized View',
  134. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  135. 'page callback' => 'tripal_mview_report',
  136. 'page arguments' => array(4),
  137. 'access arguments' => array('access administration pages'),
  138. 'type' => MENU_NORMAL_ITEM,
  139. );
  140. $items['admin/tripal/mviews/new'] = array(
  141. 'title' => 'Create MView',
  142. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  143. 'page callback' => 'drupal_get_form',
  144. 'page arguments' => array('tripal_mviews_form'),
  145. 'access arguments' => array('access administration pages'),
  146. 'type' => MENU_CALLBACK,
  147. );
  148. $items['admin/tripal/mviews/edit/%'] = array(
  149. 'title' => 'Edit MView',
  150. 'page callback' => 'drupal_get_form',
  151. 'page arguments' => array('tripal_mviews_form', 4),
  152. 'access arguments' => array('access administration pages'),
  153. 'type' => MENU_NORMAL_ITEM,
  154. );
  155. $items['admin/tripal/mviews/action/%/%'] = array(
  156. 'title' => 'Create MView',
  157. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  158. 'page callback' => 'tripal_mviews_action',
  159. 'page arguments' => array(4, 5, "1"),
  160. 'access arguments' => array('access administration pages'),
  161. 'type' => MENU_CALLBACK,
  162. );
  163. return $items;
  164. }
  165. /**
  166. * Set the permission types that the chado module uses. Essentially we
  167. * want permissionis that protect creation, editing and deleting of chado
  168. * data objects
  169. *
  170. * @ingroup tripal_core
  171. */
  172. function tripal_core_perm() {
  173. return array();
  174. }
  175. /**
  176. * Check whether chado is installed (either in the same or a different database)
  177. *
  178. * @return
  179. * TRUE/FALSE depending upon whether chado is installed.
  180. *
  181. * @ingroup tripal_chado_api
  182. */
  183. function tripal_core_is_chado_installed() {
  184. global $db_url, $db_type;
  185. // first check if chado is in the db_url of the
  186. // settings.php file
  187. if (is_array($db_url)) {
  188. if (isset($db_url['chado'])) {
  189. return TRUE;
  190. }
  191. }
  192. // check to make sure the chado schema exists
  193. return tripal_core_chado_schema_exists();
  194. }
  195. /**
  196. * Implements hook_theme().
  197. * Registers template files/functions used by this module.
  198. *
  199. * @ingroup tripal_core
  200. */
  201. function tripal_core_theme() {
  202. return array(
  203. 'tripal_core_job_view' => array(
  204. 'arguments' => array('job_id' => NULL),
  205. 'template' => 'tripal_core_job_view',
  206. ),
  207. );
  208. }
  209. /**
  210. * Implements hook_job_describe_args().
  211. * Describes the arguements for the tripal_update_mview job to allow for greater
  212. * readability in the jobs details pages.
  213. *
  214. * @param $callback
  215. * The callback of the current tripal job (this is the function that will be executed
  216. * when tripal_launch_jobs.php is run.
  217. * @param $args
  218. * An array of arguments passed in when the job was registered.
  219. *
  220. * @return
  221. * A more readable $args array
  222. *
  223. * @ingroup tripal_core
  224. */
  225. function tripal_core_job_describe_args($callback, $args) {
  226. $new_args = array();
  227. if ($callback == 'tripal_update_mview') {
  228. // get this mview details
  229. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
  230. $mview = db_fetch_object(db_query($sql, $args[0]));
  231. $new_args['View Name'] = $mview->name;
  232. }
  233. return $new_args;
  234. }
  235. /**
  236. * this is just a wrapper for backwards compatibility with a naming mistake.
  237. * it can go away in the future as it only is useful for jobs created by v0.3b
  238. *
  239. * @todo remove this function
  240. */
  241. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  242. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  243. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  244. $update, $refresh, $remove, $job);
  245. }
  246. /**
  247. * Implements hook_coder_ignore().
  248. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  249. */
  250. function tripal_core_coder_ignore() {
  251. return array(
  252. 'path' => drupal_get_path('module', 'tripal_core'),
  253. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  254. );
  255. }