tripal_core.module 11 KB

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