tripal_core.module 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Core module
  5. */
  6. /**
  7. * @defgroup tripal_modules Tripal Modules
  8. * @{
  9. * All documented functions for the various Tripal Modules excluding API functions and Views Integration functions.
  10. * @}
  11. */
  12. /**
  13. * @defgroup tripal_api Tripal API
  14. * @{
  15. * Provides an application programming interface (API) for Tripal
  16. *
  17. * The Tripal API currently provides generic insert/update/select functions for all chado content as
  18. * well as some module specific functions that insert/update/delete/select specific chado content.
  19. *
  20. * This API is currently in its infancy and some necessary functions might be missing. If you find
  21. * a missing function that you think should be included go to the sourceforge feature request
  22. * page and request it's inclusion in the API. Such feature requests with a working function
  23. * definition will be given priority.
  24. * @}
  25. */
  26. /**
  27. * @defgroup tripal_core_api Core Module API
  28. * @ingroup tripal_api
  29. */
  30. /**
  31. * @defgroup tripal_core Tripal Core Module
  32. * @ingroup tripal_modules
  33. */
  34. require_once "api/tripal_core_chado.api.inc";
  35. require_once "api/tripal_core_files.api.inc";
  36. require_once "api/tripal_core_ahah.api.inc";
  37. require_once "api/tripal_core_custom_tables.api.inc";
  38. require_once "api/tripal_core_jobs.api.inc";
  39. require_once "api/tripal_core_mviews.api.inc";
  40. require_once "api/tripal_core_misc.api.inc";
  41. require_once "includes/jobs.inc";
  42. require_once "includes/mviews.inc";
  43. require_once "includes/custom_tables.inc";
  44. require_once "includes/chado_install.inc";
  45. require_once "includes/form_elements.inc";
  46. /**
  47. * Implements hook_init().
  48. * Used to set the search_path, create default content and set default variables.
  49. *
  50. * @ingroup tripal_core
  51. */
  52. function tripal_core_init() {
  53. global $base_url;
  54. // add javascript files
  55. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal.ahah.js');
  56. // create the 'tripal' controlled volcabulary in chado but only if it doesn't already exist, and
  57. // only if the chado database is present.
  58. if (tripal_core_is_chado_installed()) {
  59. // make sure the current version of chado is set
  60. tripal_core_set_chado_version();
  61. // if the Tripal cv is missing then add
  62. $results = chado_query("SELECT * FROM {cv} WHERE name = 'tripal'");
  63. $tripal_cv = $results->fetchObject();
  64. if (!$tripal_cv) {
  65. $results = chado_query(
  66. "INSERT INTO {cv} (name,definition) " .
  67. "VALUES ('tripal', 'Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')"
  68. );
  69. }
  70. // if the Tripal db is missing then add it
  71. $results = chado_query("SELECT * FROM {db} WHERE name = 'tripal'");
  72. $tripal_db = $results->fetchObject();
  73. if (!$tripal_db) {
  74. $results = chado_query(
  75. "INSERT INTO {db} (name,description) " .
  76. "VALUES ('tripal', 'Used as a database placeholder for tripal defined objects such as tripal cvterms')"
  77. );
  78. }
  79. }
  80. // add some variables for all javasript to use for building URLs
  81. global $base_url;
  82. $theme_dir = drupal_get_path('theme', 'tripal');
  83. $clean_urls = variable_get('clean_url', 0);
  84. drupal_add_js(
  85. " var baseurl = '$base_url';
  86. var themedir = '$theme_dir';
  87. var isClean = $clean_urls;",
  88. 'inline', 'header');
  89. // make sure the date time settings are the way Tripal will insert them
  90. // otherwise PostgreSQL version that may have a different datestyle setting
  91. // will fail when inserting or updating a date column in a table.
  92. db_query("SET DATESTYLE TO :style", array(':style' => 'MDY'));
  93. // If we want AHAH elements on the node forms (e.g. chado_pub form) then we need to include
  94. // the node.pages file. Otherwise this error message is given:
  95. //
  96. // warning: call_user_func_array() expects parameter 1 to be a valid callback,
  97. // function 'node_form' not found or invalid function name
  98. // in /var/www/includes/form.inc on line 382.
  99. module_load_include('inc', 'node', 'node.pages');
  100. }
  101. /**
  102. * Implements hook_menu().
  103. * Defines all menu items needed by Tripal Core
  104. *
  105. * @ingroup tripal_core
  106. */
  107. function tripal_core_menu() {
  108. $items = array();
  109. // Triapl setting groups
  110. $items['admin/tripal'] = array(
  111. 'title' => 'Tripal',
  112. 'description' => "Manage the behavior or Tripal and its various modules.",
  113. 'weight' => -8,
  114. 'page callback' => 'system_admin_menu_block_page',
  115. 'access arguments' => array('administer site configuration'),
  116. 'file' => 'system.admin.inc',
  117. 'file path' => drupal_get_path('module', 'system'),
  118. );
  119. $items['admin/tripal/schema'] = array(
  120. 'title' => 'Chado Schema',
  121. 'description' => "Tools to extend the chado schema through custom tables & materialized views.",
  122. 'weight' => -2,
  123. 'access arguments' => array('administer site configuration'),
  124. );
  125. $items['admin/tripal/chado'] = array(
  126. 'title' => 'Chado Modules',
  127. 'description' => 'Configuration for specific chado data types such as Vocabularies, Features, etc.',
  128. 'access arguments' => array('access administration pages'),
  129. 'type' => MENU_NORMAL_ITEM,
  130. 'weight' => -6
  131. );
  132. $items['admin/tripal/loaders'] = array(
  133. 'title' => 'Chado Data Loaders',
  134. 'description' => 'Tools facilitating loading data into the chado database. Includes a generic tab-delimited loader (Bulk Loader).',
  135. 'access arguments' => array('access administration pages'),
  136. 'type' => MENU_NORMAL_ITEM,
  137. 'weight' => -4
  138. );
  139. $items['admin/tripal/extension'] = array(
  140. 'title' => 'Extension Modules',
  141. 'description' => 'Configuration for Tripal extension modules.',
  142. 'access arguments' => array('access administration pages'),
  143. 'type' => MENU_NORMAL_ITEM,
  144. 'weight' => 0
  145. );
  146. // Tripal Setup
  147. $items['admin/tripal/setup'] = array(
  148. 'title' => 'Setup Tripal',
  149. 'description' => 'Tools for initial setup of Tripal',
  150. 'access arguments' => array('administer site configuration'),
  151. 'weight' => -8
  152. );
  153. $items['admin/tripal/setup/customize'] = array(
  154. 'title' => 'Customize Tripal',
  155. 'description' => 'Information on how to customize tripal',
  156. 'page callback' => 'theme',
  157. 'page arguments' => array('tripal_core_customize'),
  158. 'access arguments' => array('administer site configuration'),
  159. 'weight' => 10
  160. );
  161. $items['admin/tripal/setup/chado_install'] = array(
  162. 'title' => 'Install Chado Schema',
  163. 'description' => 'Installs the Chado database tables, views, etc., inside the current Drupal database',
  164. 'page callback' => 'drupal_get_form',
  165. 'page arguments' => array('tripal_core_chado_load_form'),
  166. 'access arguments' => array('install chado'),
  167. 'type' => MENU_NORMAL_ITEM,
  168. 'weight' => -10
  169. );
  170. // Jobs Management
  171. $items['admin/tripal/tripal_jobs'] = array(
  172. 'title' => 'Jobs',
  173. 'description' => 'Jobs managed by Tripal',
  174. 'page callback' => 'tripal_jobs_report',
  175. 'access arguments' => array('access administration pages'),
  176. 'type' => MENU_NORMAL_ITEM,
  177. 'weight' => -10
  178. );
  179. $items['admin/tripal/tripal_jobs/cancel/%'] = array(
  180. 'title' => 'Jobs',
  181. 'description' => 'Cancel a pending job',
  182. 'page callback' => 'tripal_jobs_cancel',
  183. 'page arguments' => array(4),
  184. 'access arguments' => array('access administration pages'),
  185. 'type' => MENU_CALLBACK,
  186. );
  187. $items['admin/tripal/tripal_jobs/rerun/%'] = array(
  188. 'title' => 'Jobs',
  189. 'description' => 'Re-run an existing job.',
  190. 'page callback' => 'tripal_jobs_rerun',
  191. 'page arguments' => array(4),
  192. 'access arguments' => array('access administration pages'),
  193. 'type' => MENU_CALLBACK,
  194. );
  195. $items['admin/tripal/tripal_jobs/view/%'] = array(
  196. 'title' => 'Jobs Details',
  197. 'description' => 'View job details.',
  198. 'page callback' => 'tripal_jobs_view',
  199. 'page arguments' => array(4),
  200. 'access arguments' => array('access administration pages'),
  201. 'type' => MENU_CALLBACK,
  202. );
  203. // Materialized Views
  204. $items['admin/tripal/schema/mviews'] = array(
  205. 'title' => 'Materialized Views',
  206. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  207. 'access arguments' => array('access administration pages'),
  208. 'type' => MENU_NORMAL_ITEM,
  209. 'weight' => -10
  210. );
  211. $items['admin/tripal/schema/mviews/list'] = array(
  212. 'title' => 'List Materialized Views',
  213. 'description' => 'A list of existing materialized views with the ability to edit & delete existing materialized views.',
  214. 'page callback' => 'tripal_mviews_report',
  215. 'access arguments' => array('access administration pages'),
  216. 'type' => MENU_NORMAL_ITEM,
  217. 'weight' => -10
  218. );
  219. $items['admin/tripal/schema/mviews/report/%'] = array(
  220. 'title' => 'Materialized View',
  221. 'description' => 'Materialized views are used to improve speed of large or complex queries. These are database views as compared to Drupal views.',
  222. 'page callback' => 'tripal_mview_report',
  223. 'page arguments' => array(5),
  224. 'access arguments' => array('access administration pages'),
  225. 'type' => MENU_NORMAL_ITEM,
  226. );
  227. $items['admin/tripal/schema/mviews/new'] = array(
  228. 'title' => 'Create Materialized View',
  229. 'description' => 'Create a new materialized view.',
  230. 'page callback' => 'drupal_get_form',
  231. 'page arguments' => array('tripal_mviews_form'),
  232. 'access arguments' => array('access administration pages'),
  233. 'type' => MENU_NORMAL_ITEM,
  234. );
  235. $items['admin/tripal/schema/mviews/edit/%'] = array(
  236. 'title' => 'Edit Materialized View',
  237. 'page callback' => 'drupal_get_form',
  238. 'page arguments' => array('tripal_mviews_form', 5),
  239. 'access arguments' => array('access administration pages'),
  240. 'type' => MENU_NORMAL_ITEM,
  241. );
  242. $items['admin/tripal/schema/mviews/action/%/%'] = array(
  243. 'title' => 'Create Materialized View',
  244. 'description' => 'Materialized views are used to improve speed of large or complex queries.',
  245. 'page callback' => 'tripal_mviews_action',
  246. 'page arguments' => array(5, 6, "1"),
  247. 'access arguments' => array('access administration pages'),
  248. 'type' => MENU_CALLBACK,
  249. );
  250. // Custom Tables
  251. $items['admin/tripal/schema/custom_tables'] = array(
  252. 'title' => 'Custom Tables',
  253. 'description' => 'Creation of custom tables that are added to Chado database.',
  254. 'access arguments' => array('access administration pages'),
  255. 'type' => MENU_NORMAL_ITEM,
  256. 'weight' => -10
  257. );
  258. $items['admin/tripal/schema/custom_tables/list'] = array(
  259. 'title' => 'List of Custom Tables',
  260. 'description' => 'Provides a list of all custom tables created by Tripal and allows for editing or removing existing custom tables.',
  261. 'page callback' => 'tripal_custom_tables_list',
  262. 'access arguments' => array('access administration pages'),
  263. 'type' => MENU_NORMAL_ITEM,
  264. 'weight' => -10
  265. );
  266. $items['admin/tripal/schema/custom_tables/view/%'] = array(
  267. 'title' => 'Custom Tables',
  268. 'description' => 'Custom tables are added to Chado.',
  269. 'page callback' => 'tripal_custom_table_view',
  270. 'page arguments' => array(4),
  271. 'access arguments' => array('access administration pages'),
  272. 'type' => MENU_NORMAL_ITEM,
  273. );
  274. $items['admin/tripal/schema/custom_tables/new'] = array(
  275. 'title' => 'Create Custom Table',
  276. 'description' => 'An interface for creating your own custom tables.',
  277. 'page callback' => 'tripal_custom_table_new_page',
  278. 'access arguments' => array('access administration pages'),
  279. 'type' => MENU_NORMAL_ITEM,
  280. );
  281. $items['admin/tripal/schema/custom_tables/edit/%'] = array(
  282. 'title' => 'Edit Custom Table',
  283. 'page callback' => 'drupal_get_form',
  284. 'page arguments' => array('tripal_custom_tables_form', 4),
  285. 'access arguments' => array('access administration pages'),
  286. 'type' => MENU_NORMAL_ITEM,
  287. );
  288. $items['admin/tripal/schema/custom_tables/action/%/%'] = array(
  289. 'title' => 'Create Custom Table',
  290. 'description' => 'Custom tables are added to Chado.',
  291. 'page callback' => 'tripal_custom_tables_action',
  292. 'page arguments' => array(4, 5, "1"),
  293. 'access arguments' => array('access administration pages'),
  294. 'type' => MENU_CALLBACK,
  295. );
  296. return $items;
  297. }
  298. /**
  299. * Set the permission types that the chado module uses. Essentially we
  300. * want permissionis that protect creation, editing and deleting of chado
  301. * data objects
  302. *
  303. * @ingroup tripal_core
  304. */
  305. function tripal_core_permission() {
  306. return array(
  307. 'install chado' => array(
  308. 'title' => t('Install Chado'),
  309. 'description' => t('Allow the user to install or upgrade a Chado database in the existing Drupal database.')
  310. ),
  311. );
  312. }
  313. /**
  314. * Implements hook_theme().
  315. * Registers template files/functions used by this module.
  316. *
  317. * @ingroup tripal_core
  318. */
  319. function tripal_core_theme() {
  320. return array(
  321. 'tripal_core_customize' => array(
  322. 'arguments' => array('job_id' => NULL),
  323. 'template' => 'tripal_core_customize',
  324. 'path' => drupal_get_path('module', 'tripal_core') . '/theme'
  325. ),
  326. 'theme_file_upload_combo' => array(
  327. 'render element' => 'element',
  328. ),
  329. 'theme_sequence_combo' => array(
  330. 'render element' => 'element',
  331. ),
  332. );
  333. }
  334. /**
  335. * Implements hook_job_describe_args().
  336. * Describes the arguements for the tripal_update_mview job to allow for greater
  337. * readability in the jobs details pages.
  338. *
  339. * @param $callback
  340. * The callback of the current tripal job (this is the function that will be executed
  341. * when tripal_launch_jobs.php is run.
  342. * @param $args
  343. * An array of arguments passed in when the job was registered.
  344. *
  345. * @return
  346. * A more readable $args array
  347. *
  348. * @ingroup tripal_core
  349. */
  350. function tripal_core_job_describe_args($callback, $args) {
  351. $new_args = array();
  352. if ($callback == 'tripal_update_mview') {
  353. // get this mview details
  354. $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = :mview_id ";
  355. $results = db_query($sql, array(':mview_id' => $args[0]));
  356. $mview = $results->fetchObject();
  357. $new_args['View Name'] = $mview->name;
  358. }
  359. elseif ($callback == 'tripal_core_install_chado') {
  360. $new_args['Action'] = $args[0];
  361. }
  362. return $new_args;
  363. }
  364. /**
  365. * this is just a wrapper for backwards compatibility with a naming mistake.
  366. * it can go away in the future as it only is useful for jobs created by v0.3b
  367. *
  368. * @todo remove this function
  369. */
  370. function tripal_core_load_gff3($gff_file, $organism_id, $analysis_id, $add_only = 0,
  371. $update = 0, $refresh = 0, $remove = 0, $job = NULL) {
  372. tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_only,
  373. $update, $refresh, $remove, $job);
  374. }
  375. /**
  376. * Implements hook_coder_ignore().
  377. * Defines the path to the file (tripal_core.coder_ignores.txt) where ignore rules for coder are stored
  378. */
  379. function tripal_core_coder_ignore() {
  380. return array(
  381. 'path' => drupal_get_path('module', 'tripal_core'),
  382. 'line prefix' => drupal_get_path('module', 'tripal_core'),
  383. );
  384. }