tripal_core.module 11 KB

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