tripal_core.module 11 KB

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