123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- /*******************************************************************************
- * Implementation of hook_install();
- */
- function tripal_cv_install(){
- // create the module's data directory
- tripal_create_moddir('tripal_cv');
- // Add the materialized view needed to keep track of the
- //
- $previous_db = db_set_active('chado');
- if (db_table_exists('cv_root_mview')) {
- $sql = "DROP TABLE cv_root_mview";
- db_query($sql);
- }
- db_set_active($previous_db);
- // Create the MView
- tripal_add_mview(
- // view name
- 'cv_root_mview',
- // module name
- 'tripal_cv',
- // table name
- 'cv_root_mview',
- // table schema
- 'name character varying(1024), cvterm_id integer, cv_id integer,
- cv_name character varying(255)',
- // indexed columns
- 'cvterm_id, cv_id',
- // SQL statement that populates the view
- 'SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
- FROM {cvterm_relationship} CVTR
- INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
- INNER JOIN CV on CV.cv_id = CVT.cv_id
- WHERE CVTR.object_id not in
- (SELECT subject_id FROM {cvterm_relationship}) ',
- // special index
- ''
- );
- // create the tables that correlate OBO files/references with a chado CV
- drupal_install_schema('tripal_cv');
- }
- /*******************************************************************************
- * This update adds the new tripal_obo table. This is an upgrade from
- * Tripal version 0.2
- */
- function tripal_cv_update_6000(){
- drupal_install_schema('tripal_cv');
- $ret = array(
- '#finished' => 1,
- );
-
- return $ret;
- }
- /************************************************************************
- * Implementation of hook_schema().
- */
- function tripal_cv_schema() {
- $schema = tripal_cv_get_schemas();
- return $schema;
- }
- /*******************************************************************************
- * Implementation of hook_uninstall()
- */
- function tripal_cv_uninstall(){
- // remove the materialized view
- $mview = tripal_mviews_get_mview_id('cv_root_mview');
- if($mview){
- tripal_mviews_action('delete',$mview);
- }
- drupal_uninstall_schema('tripal_cv');
- }
- /*******************************************************************************
- * Implementation of hook_requirements(). Make sure 'Tripal Core' is enabled
- * before installation
- */
- function tripal_cv_requirements($phase) {
- $requirements = array();
- if ($phase == 'install') {
- if (!function_exists('tripal_create_moddir')) {
- $requirements ['tripal_cv'] = array(
- 'title' => "tripal_cv",
- 'value' => "Required modules must be installed first before Tripal CV module can be installed",
- 'severity' => REQUIREMENT_ERROR,
- );
- }
- }
- return $requirements;
- }
- /************************************************************************
- * This function simply defines all tables needed for the module to work
- * correctly. By putting the table definitions in a separate function we
- * can easily provide the entire list for hook_install or individual
- * tables for an update.
- */
- function tripal_cv_get_schemas (){
- $schema = array();
- $schema['tripal_obo'] = array(
- 'fields' => array(
- 'cv_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
- 'file' => array('type' => 'varchar','length' => 1024),
- 'url' => array('type' => 'varchar','length' => 1024),
- ),
- 'indexes' => array(
- 'cv_id' => array('cv_id')
- ),
- 'primary key' => array('cv_id'),
- );
- return $schema;
- }
|