tripal_core.module 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. require_once "jobs.php";
  3. require_once "mviews.php";
  4. require_once "chado_install.php";
  5. require_once "tripal_core.api.inc";
  6. /**
  7. * @defgroup tripal_modules Tripal Modules
  8. * @{
  9. * All documented functions for the various Tripal Modules
  10. * @}
  11. */
  12. /**
  13. * @defgroup tripal_core Core Tripal Module
  14. * @ingroup tripal_modules
  15. */
  16. /**
  17. *
  18. *
  19. * @ingroup tripal_core
  20. */
  21. function tripal_core_init(){
  22. // the two lines below are necessary to ensure that the search_path
  23. // variable is always set. In the case where a view needs to query the
  24. // chado schema when it is local to the Drupal database. Otherwise the
  25. // search_path isn't set. When tripal_db_set_active is called it
  26. // automatically sets the serach path if chado is local to the
  27. // Drupal database
  28. $previous = tripal_db_set_active('chado');
  29. tripal_db_set_active($previous);
  30. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  31. // only if the chado database is present.
  32. if(tripal_core_is_chado_installed()){
  33. $previous_db = tripal_db_set_active('chado'); // use chado database
  34. if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
  35. $results = db_query("INSERT INTO {cv} (name,definition) ".
  36. "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
  37. }
  38. if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
  39. $results = db_query("INSERT INTO {db} (name,description) ".
  40. "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
  41. }
  42. tripal_db_set_active($previous_db); // now use drupal database
  43. }
  44. // add some variables for all javasript to use for building URLs
  45. global $base_url;
  46. $theme_dir = drupal_get_path('theme', 'tripal');
  47. $clean_urls = variable_get('clean_url', 0);
  48. drupal_add_js("
  49. var baseurl = '$base_url';
  50. var themedir = '$theme_dir';
  51. var isClean = $clean_urls;",'inline');
  52. // make sure the date time settings are the way Tripal will insert them
  53. // otherwise PostgreSQL version that may have a different datestyle setting
  54. // will fail when inserting or updating a date column in a table.
  55. db_query("SET DATESTYLE TO '%s'",'MDY');
  56. }
  57. /**
  58. *
  59. *
  60. * @ingroup tripal_core
  61. */
  62. function tripal_core_menu() {
  63. $items = array();
  64. // Triapl setting groups
  65. $items['admin/tripal'] = array(
  66. 'title' => 'Tripal Management',
  67. 'description' => "Manage the behavior or Tripal and its various modules.",
  68. 'position' => 'right',
  69. 'weight' => -5,
  70. 'page callback' => 'system_admin_menu_block_page',
  71. 'access arguments' => array('administer site configuration'),
  72. 'file' => 'system.admin.inc',
  73. 'file path' => drupal_get_path('module', 'system'),
  74. );
  75. $items['tripal_toggle_box_menu/%/%/%'] = array(
  76. 'title' => t('Toggle Box'),
  77. 'page callback' => 'tripal_toggle_box_menu',
  78. 'page arguments' => array(1,2,3),
  79. 'access arguments' => array('access administration pages'),
  80. 'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
  81. );
  82. $items['admin/tripal/chado_1_11_install'] = array(
  83. 'title' => 'Install Chado v1.11',
  84. 'description' => 'Installs Chado version 1.11 inside the current Drupal database',
  85. 'page callback' => 'drupal_get_form',
  86. 'page arguments' => array('tripal_core_chado_v1_11_load_form'),
  87. 'access arguments' => array('access administration pages'),
  88. 'type' => MENU_NORMAL_ITEM,
  89. );
  90. // Jobs Management
  91. $items['admin/tripal/tripal_jobs'] = array(
  92. 'title' => 'Jobs',
  93. 'description' => 'Jobs managed by Tripal',
  94. 'page callback' => 'tripal_jobs_report',
  95. 'access arguments' => array('access administration pages'),
  96. 'type' => MENU_NORMAL_ITEM,
  97. );
  98. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  99. 'title' => 'Jobs',
  100. 'description' => 'Cancel a pending job',
  101. 'page callback' => 'tripal_jobs_cancel',
  102. 'page arguments' => array(4),
  103. 'access arguments' => array('access administration pages'),
  104. 'type' => MENU_CALLBACK,
  105. );
  106. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  107. 'title' => 'Jobs',
  108. 'description' => 'Re-run an existing job.',
  109. 'page callback' => 'tripal_jobs_rerun',
  110. 'page arguments' => array(4),
  111. 'access arguments' => array('access administration pages'),
  112. 'type' => MENU_CALLBACK,
  113. );
  114. $items['admin/tripal/tripal_jobs/view/%'] = array(
  115. 'title' => 'Jobs Details',
  116. 'description' => 'View job details.',
  117. 'page callback' => 'tripal_jobs_view',
  118. 'page arguments' => array(4),
  119. 'access arguments' => array('access administration pages'),
  120. 'type' => MENU_CALLBACK,
  121. );
  122. // Materialized Views
  123. $items['admin/tripal/mviews'] = array(
  124. 'title' => 'MViews',
  125. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  126. 'page callback' => 'tripal_mviews_report',
  127. 'access arguments' => array('access administration pages'),
  128. 'type' => MENU_NORMAL_ITEM,
  129. );
  130. $items['admin/tripal/mviews/report/%'] = array(
  131. 'title' => 'Materialized View',
  132. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  133. 'page callback' => 'tripal_mview_report',
  134. 'page arguments' => array(4),
  135. 'access arguments' => array('access administration pages'),
  136. 'type' => MENU_NORMAL_ITEM,
  137. );
  138. $items['admin/tripal/mviews/new'] = array(
  139. 'title' => 'Create MView',
  140. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  141. 'page callback' => 'drupal_get_form',
  142. 'page arguments' => array('tripal_mviews_form'),
  143. 'access arguments' => array('access administration pages'),
  144. 'type' => MENU_CALLBACK,
  145. );
  146. $items['admin/tripal/mviews/edit/%'] = array(
  147. 'title' => 'Edit MView',
  148. 'page callback' => 'drupal_get_form',
  149. 'page arguments' => array('tripal_mviews_form',4),
  150. 'access arguments' => array('access administration pages'),
  151. 'type' => MENU_NORMAL_ITEM,
  152. );
  153. $items['admin/tripal/mviews/action/%/%'] = array(
  154. 'title' => 'Create MView',
  155. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  156. 'page callback' => 'tripal_mviews_action',
  157. 'page arguments' => array(4,5,"1"),
  158. 'access arguments' => array('access administration pages'),
  159. 'type' => MENU_CALLBACK,
  160. );
  161. return $items;
  162. }
  163. /**
  164. * Set the permission types that the chado module uses. Essentially we
  165. * want permissionis that protect creation, editing and deleting of chado
  166. * data objects
  167. *
  168. * @ingroup tripal_core
  169. */
  170. function tripal_core_perm(){
  171. return array(
  172. );
  173. }
  174. /**
  175. *
  176. *
  177. * @param $dbname
  178. * The name of the database to switch to as indicated in settings.php
  179. * Should be either default or chado
  180. *
  181. * @return
  182. * The name of the previously set database
  183. *
  184. * @ingroup tripal_chado_api
  185. */
  186. function tripal_core_is_chado_installed(){
  187. global $db_url, $db_type;
  188. // first check if chado is in the db_url of the
  189. // settings.php file
  190. if(is_array($db_url)){
  191. if(isset($db_url['chado'])){
  192. return true;
  193. }
  194. }
  195. // check to make sure the chado schema exists
  196. $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
  197. if(db_fetch_object(db_query($sql))){
  198. return true;
  199. }
  200. return false;
  201. }
  202. /**
  203. *
  204. * @ingroup tripal_core
  205. */
  206. function tripal_core_theme () {
  207. return array(
  208. 'tripal_core_job_view' => array (
  209. 'arguments' => array('job_id'=> null),
  210. 'template' => 'tripal_core_job_view',
  211. ),
  212. );
  213. }
  214. /**
  215. *
  216. * @ingroup tripal_core
  217. */
  218. function tripal_core_job_describe_args($callback,$args){
  219. $new_args = array();
  220. if($callback == 'tripal_update_mview'){
  221. // get this mview details
  222. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
  223. $mview = db_fetch_object(db_query($sql,$args[0]));
  224. $new_args['View Name'] = $mview->name;
  225. }
  226. return $new_args;
  227. }
  228. // this is just a wrapper for backwards compatibility with a naming mistake.
  229. // it can go away in the future as it only is useful for jobs created by v0.3b
  230. function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0,
  231. $update = 0, $refresh = 0, $remove = 0, $job = NULL)
  232. {
  233. tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only,
  234. $update, $refresh, $remove, $job);
  235. }