tripal_core.module 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. require_once "includes/jobs.php";
  3. require_once "includes/mviews.php";
  4. require_once "includes/chado_install.php";
  5. require_once "api/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. // make sure the current version of chado is set
  58. tripal_core_set_chado_version();
  59. }
  60. /**
  61. * Implements hook_menu().
  62. * Defines all menu items needed by Tripal Core
  63. *
  64. * @ingroup tripal_core
  65. */
  66. function tripal_core_menu() {
  67. $items = array();
  68. // Triapl setting groups
  69. $items['admin/tripal'] = array(
  70. 'title' => 'Tripal Management',
  71. 'description' => "Manage the behavior or Tripal and its various modules.",
  72. 'position' => 'right',
  73. 'weight' => -5,
  74. 'page callback' => 'system_admin_menu_block_page',
  75. 'access arguments' => array('administer site configuration'),
  76. 'file' => 'system.admin.inc',
  77. 'file path' => drupal_get_path('module', 'system'),
  78. );
  79. $items['tripal_toggle_box_menu/%/%/%'] = array(
  80. 'title' => 'Toggle Box',
  81. 'page callback' => 'tripal_toggle_box_menu',
  82. 'page arguments' => array(1, 2, 3),
  83. 'access arguments' => array('access administration pages'),
  84. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  85. );
  86. $items['admin/tripal/chado_install'] = array(
  87. 'title' => 'Install Chado Schema',
  88. 'description' => 'Installs the Chado database tables, views, etc., inside the current Drupal database',
  89. 'page callback' => 'drupal_get_form',
  90. 'page arguments' => array('tripal_core_chado_load_form'),
  91. 'access arguments' => array('access administration pages'),
  92. 'type' => MENU_NORMAL_ITEM,
  93. );
  94. // Jobs Management
  95. $items['admin/tripal/tripal_jobs'] = array(
  96. 'title' => 'Jobs',
  97. 'description' => 'Jobs managed by Tripal',
  98. 'page callback' => 'tripal_jobs_report',
  99. 'access arguments' => array('access administration pages'),
  100. 'type' => MENU_NORMAL_ITEM,
  101. );
  102. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  103. 'title' => 'Jobs',
  104. 'description' => 'Cancel a pending job',
  105. 'page callback' => 'tripal_jobs_cancel',
  106. 'page arguments' => array(4),
  107. 'access arguments' => array('access administration pages'),
  108. 'type' => MENU_CALLBACK,
  109. );
  110. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  111. 'title' => 'Jobs',
  112. 'description' => 'Re-run an existing job.',
  113. 'page callback' => 'tripal_jobs_rerun',
  114. 'page arguments' => array(4),
  115. 'access arguments' => array('access administration pages'),
  116. 'type' => MENU_CALLBACK,
  117. );
  118. $items['admin/tripal/tripal_jobs/view/%'] = array(
  119. 'title' => 'Jobs Details',
  120. 'description' => 'View job details.',
  121. 'page callback' => 'tripal_jobs_view',
  122. 'page arguments' => array(4),
  123. 'access arguments' => array('access administration pages'),
  124. 'type' => MENU_CALLBACK,
  125. );
  126. // Materialized Views
  127. $items['admin/tripal/mviews'] = array(
  128. 'title' => 'MViews',
  129. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  130. 'page callback' => 'tripal_mviews_report',
  131. 'access arguments' => array('access administration pages'),
  132. 'type' => MENU_NORMAL_ITEM,
  133. );
  134. $items['admin/tripal/mviews/report/%'] = array(
  135. 'title' => 'Materialized View',
  136. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  137. 'page callback' => 'tripal_mview_report',
  138. 'page arguments' => array(4),
  139. 'access arguments' => array('access administration pages'),
  140. 'type' => MENU_NORMAL_ITEM,
  141. );
  142. $items['admin/tripal/mviews/new'] = array(
  143. 'title' => 'Create MView',
  144. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  145. 'page callback' => 'drupal_get_form',
  146. 'page arguments' => array('tripal_mviews_form'),
  147. 'access arguments' => array('access administration pages'),
  148. 'type' => MENU_CALLBACK,
  149. );
  150. $items['admin/tripal/mviews/edit/%'] = array(
  151. 'title' => 'Edit MView',
  152. 'page callback' => 'drupal_get_form',
  153. 'page arguments' => array('tripal_mviews_form', 4),
  154. 'access arguments' => array('access administration pages'),
  155. 'type' => MENU_NORMAL_ITEM,
  156. );
  157. $items['admin/tripal/mviews/action/%/%'] = array(
  158. 'title' => 'Create MView',
  159. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  160. 'page callback' => 'tripal_mviews_action',
  161. 'page arguments' => array(4, 5, "1"),
  162. 'access arguments' => array('access administration pages'),
  163. 'type' => MENU_CALLBACK,
  164. );
  165. return $items;
  166. }
  167. /**
  168. * Set the permission types that the chado module uses. Essentially we
  169. * want permissionis that protect creation, editing and deleting of chado
  170. * data objects
  171. *
  172. * @ingroup tripal_core
  173. */
  174. function tripal_core_perm() {
  175. return array();
  176. }
  177. /**
  178. * Check whether chado is installed (either in the same or a different database)
  179. *
  180. * @return
  181. * TRUE/FALSE depending upon whether chado is installed.
  182. *
  183. * @ingroup tripal_chado_api
  184. */
  185. function tripal_core_is_chado_installed() {
  186. global $db_url, $db_type;
  187. // first check if chado is in the db_url of the
  188. // settings.php file
  189. if (is_array($db_url)) {
  190. if (isset($db_url['chado'])) {
  191. return TRUE;
  192. }
  193. }
  194. // check to make sure the chado schema exists
  195. return tripal_core_chado_schema_exists();
  196. }
  197. /**
  198. * Implements hook_theme().
  199. * Registers template files/functions used by this module.
  200. *
  201. * @ingroup tripal_core
  202. */
  203. function tripal_core_theme() {
  204. return array(
  205. 'tripal_core_job_view' => array(
  206. 'arguments' => array('job_id' => NULL),
  207. 'template' => 'tripal_core_job_view',
  208. ),
  209. );
  210. }
  211. /**
  212. * Implements hook_job_describe_args().
  213. * Describes the arguements for the tripal_update_mview job to allow for greater
  214. * readability in the jobs details pages.
  215. *
  216. * @param $callback
  217. * The callback of the current tripal job (this is the function that will be executed
  218. * when tripal_launch_jobs.php is run.
  219. * @param $args
  220. * An array of arguments passed in when the job was registered.
  221. *
  222. * @return
  223. * A more readable $args array
  224. *
  225. * @ingroup tripal_core
  226. */
  227. function tripal_core_job_describe_args($callback, $args) {
  228. $new_args = array();
  229. if ($callback == 'tripal_update_mview') {
  230. // get this mview details
  231. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
  232. $mview = db_fetch_object(db_query($sql, $args[0]));
  233. $new_args['View Name'] = $mview->name;
  234. }
  235. elseif ($callback == 'tripal_core_install_chado') {
  236. $new_args['Action'] = $args[0];
  237. }
  238. return $new_args;
  239. }
  240. /**
  241. * this is just a wrapper for backwards compatibility with a naming mistake.
  242. * it can go away in the future as it only is useful for jobs created by v0.3b
  243. *
  244. * @todo remove this function
  245. */
  246. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  247. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  248. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  249. $update, $refresh, $remove, $job);
  250. }
  251. /**
  252. * Implements hook_coder_ignore().
  253. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  254. */
  255. function tripal_core_coder_ignore() {
  256. return array(
  257. 'path' => drupal_get_path('module', 'tripal_core'),
  258. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  259. );
  260. }