tripal_core.module 11 KB

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