tripal_core.module 11 KB

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