| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 | 
							- <?php
 
- /**
 
-  * @file
 
-  * Handles install, uninstall, disable and enable functionality including database tables.
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- /**
 
-  * Implements hook_disable().
 
-  * Disable default views when module is disabled
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- function tripal_contact_disable() {
 
-   // Disable all default views provided by this module
 
-   require_once("tripal_contact.views_default.inc");
 
-   $views = tripal_contact_views_default_views();
 
-   foreach (array_keys($views) as $view_name) {
 
-     tripal_disable_view($view_name,FALSE,array('suppress_error' => TRUE));
 
-   }
 
- }
 
- /**
 
-  * Implementation of hook_requirements().
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- function tripal_contact_requirements($phase) {
 
-   $requirements = array();
 
-   if ($phase == 'install') {
 
-     // make sure chado is installed
 
-     if (!$GLOBALS["chado_is_installed"]) {
 
-       $requirements ['tripal_contact'] = array(
 
-         'title' => "tripal_contact",
 
-         'value' => "ERROR: Chado must be installed before this module can be enabled",
 
-         'severity' => REQUIREMENT_ERROR,
 
-       );
 
-     }
 
-   }
 
-   return $requirements;
 
- }
 
- /**
 
-  * Implementation of hook_install().
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- function tripal_contact_install() {
 
-   // Add the contactprop table to Chado.
 
-   tripal_contact_add_custom_tables();
 
-   // Add loading of the the tripal contact ontology to the job queue.
 
-   $obo_path = '{tripal_contact}/files/tcontact.obo';
 
-   $obo_id = tripal_insert_obo('Tripal Contacts', $obo_path);
 
-   tripal_submit_obo_job(array('obo_id' => $obo_id));
 
-   // Add cvterms for relationship types.
 
-   tripal_contact_add_cvs();
 
-   tripal_contact_add_cvterms();
 
-   // Set the default vocabularies.
 
-   tripal_set_default_cv('contact', 'type_id', 'tripal_contact');
 
-   tripal_set_default_cv('contactprop', 'type_id', 'tripal_contact');
 
-   tripal_set_default_cv('contact_relationship', 'type_id', 'contact_relationship');
 
- }
 
- /**
 
-  * Implementation of hook_uninstall().
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- function tripal_contact_uninstall() {
 
-   /*
 
-   // remove our custom block visibility settings per node type
 
-   db_delete('block_node_type')
 
-     ->condition('module', 'chado_contact')
 
-     ->condition('delta', 'contbase')
 
-     ->execute();
 
-     */
 
- }
 
- /**
 
-  * Adds any cvs needed by this module.
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- function tripal_contact_add_cvs() {
 
-   // Add the cv for contact properties. This is a default vocabulary in the event
 
-   // that a user does not want to use the tripal_contact vocabulary
 
-   tripal_insert_cv(
 
-     'contact_property',
 
-     'Contains properties for contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
 
-   );
 
-   // add the cv for the contact type. This is a default vocabulary in the event
 
-   // that a user does not want to use the tripal_contact vocabulary
 
-   tripal_insert_cv(
 
-     'contact_type',
 
-     'Contains types of contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
 
-   );
 
-   // Add the cv for the tripal_contact vocabulary which is loaded via the OBO
 
-   tripal_insert_cv(
 
-    'tripal_contact',
 
-    'A heirarchical set of terms for describing a contact. It is intended to be used as the default vocabularies in Tripal for contact types and contact properties.'
 
-   );
 
-   // add the cv for contact relationships
 
-   tripal_insert_cv(
 
-     'contact_relationship',
 
-     'Contains types of relationships between contacts.'
 
-   );
 
- }
 
- /**
 
-  * Adds any cvterms needed by this module.
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- function tripal_contact_add_cvterms() {
 
- }
 
- /**
 
-  * Implementation of hook_schema().
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- function tripal_contact_schema() {
 
-   $schema['chado_contact'] = array(
 
-     'fields' => array(
 
-       'vid' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not null' => TRUE,
 
-         'default' => 0
 
-       ),
 
-       'nid' => array(
 
-         'type' => 'int',
 
-         'unsigned' => TRUE,
 
-         'not null' => TRUE,
 
-         'default' => 0
 
-       ),
 
-       'contact_id' => array(
 
-         'type' => 'int',
 
-         'not null' => TRUE,
 
-         'default' => 0
 
-       )
 
-     ),
 
-     'indexes' => array(
 
-       'contact_id' => array('contact_id')
 
-     ),
 
-     'unique keys' => array(
 
-       'nid_vid' => array('nid', 'vid'),
 
-       'vid' => array('vid')
 
-     ),
 
-     'primary key' => array('nid'),
 
-   );
 
-   return $schema;
 
- }
 
- /**
 
-  * Add any custom tables needed by this module.
 
-  * - Contactprop: keep track of properties of contact
 
-  *
 
-  * @ingroup tripal_contact
 
-  */
 
- function tripal_contact_add_custom_tables(){
 
-   $schema = array (
 
-     'table' => 'contactprop',
 
-     'fields' => array (
 
-       'contactprop_id' => array (
 
-         'type' => 'serial',
 
-         'not null' => true,
 
-       ),
 
-       'contact_id' => array (
 
-         'type' => 'int',
 
-         'not null' => true,
 
-       ),
 
-       'type_id' => array (
 
-         'type' => 'int',
 
-         'not null' => true,
 
-       ),
 
-       'value' => array (
 
-         'type' => 'text',
 
-         'not null' => false,
 
-       ),
 
-       'rank' => array (
 
-         'type' => 'int',
 
-         'not null' => true,
 
-         'default' => 0,
 
-       ),
 
-     ),
 
-     'primary key' => array (
 
-       0 => 'contactprop_id',
 
-     ),
 
-     'unique keys' => array (
 
-       'contactprop_c1' => array (
 
-         0 => 'contact_id',
 
-         1 => 'type_id',
 
-         2 => 'rank',
 
-       ),
 
-     ),
 
-     'indexes' => array (
 
-       'contactprop_idx1' => array (
 
-         0 => 'contact_id',
 
-       ),
 
-       'contactprop_idx2' => array (
 
-         0 => 'type_id',
 
-       ),
 
-     ),
 
-     'foreign keys' => array (
 
-       'cvterm' => array (
 
-         'table' => 'cvterm',
 
-         'columns' => array (
 
-           'type_id' => 'cvterm_id',
 
-         ),
 
-       ),
 
-       'contact' => array (
 
-         'table' => 'contact',
 
-         'columns' => array (
 
-           'contact_id' => 'contact_id',
 
-         ),
 
-       ),
 
-     ),
 
-   );
 
-   chado_create_custom_table('contactprop', $schema, TRUE);
 
- }
 
- /**
 
-  * This is the required update for tripal_contact when upgrading from Drupal core API 6.x.
 
-  *
 
-  */
 
- function tripal_contact_update_7200() {
 
-   // Make sure we have the full API loaded this will help during a
 
-   // site upgrade when the tripal_core module is disabled.
 
-   module_load_include('module', 'tripal_core', 'tripal_core');
 
-   tripal_core_import_api();
 
-   module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
 
-   // Add the contact_type CV
 
-   try {
 
-     // First we add the cv.
 
-     // Notice that tripal_insert_cv() will only add it if it doesn't exist already.
 
-     $cv = tripal_insert_cv(
 
-       'tripal_contact',
 
-       'A heirarchical set of terms for describing a contact. It is intended to be used as the default vocabularies in Tripal for contact types and contact properties.'
 
-     );
 
-     if ($cv) {
 
-       $cv_id = $cv->cv_id;
 
-       // Set as Default CV for contact types.
 
-       $is_set = tripal_get_default_cv('contact', 'type_id');
 
-       if (!$is_set) {
 
-         tripal_set_default_cv('contact','type_id', 'tripal_contact', $cv_id);
 
-       }
 
-       // Set as Default CV for contact properties.
 
-       $is_set = tripal_get_default_cv('contactprop', 'type_id');
 
-       if (!$is_set) {
 
-         tripal_set_default_cv('contactprop','type_id', 'tripal_contact', $cv_id);
 
-       }
 
-     }
 
-     else {
 
-       throw new DrupalUpdateException('Failed to add tripal_contact vocabulary.');
 
-     }
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to add tripal_contact vocabulary: '. $error);
 
-   }
 
-   // Add the contact_relationship CV
 
-   try {
 
-     // First we add the cv.
 
-     // Notice that tripal_insert_cv() will only add it if it doesn't exist already.
 
-     $cv = tripal_insert_cv(
 
-       'contact_relationship',
 
-       'Contains types of relationships between contacts.'
 
-     );
 
-     if ($cv) {
 
-       $cv_id = $cv->cv_id;
 
-       // Set as Default CV for contact relationships.
 
-       $is_set = tripal_get_default_cv('contact_relationship', 'type_id');
 
-       if (!$is_set) {
 
-         tripal_set_default_cv('contact_relationship','type_id', 'contact_relationship', $cv_id);
 
-       }
 
-     }
 
-     else {
 
-       throw new DrupalUpdateException('Failed to add contact_relationship vocabulary.');
 
-     }
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to add contact_relationship vocabulary: '. $error);
 
-   }
 
-   // Add the contact_type CV (not default).
 
-   try {
 
-     $cv = tripal_insert_cv(
 
-       'contact_type',
 
-       'Contains types of contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
 
-     );
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to add contact_type vocabulary: '. $error);
 
-   }
 
-   // Add the contact_property CV (not default).
 
-   try {
 
-     $cv = tripal_insert_cv(
 
-       'contact_property',
 
-       'Contains properties for contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
 
-     );
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to add contact_property vocabulary: '. $error);
 
-   }
 
- }
 
- /**
 
-  * Implementation of hook_update_dependencies().
 
-  *
 
-  * It specifies a list of other modules whose updates must be run prior to
 
-  * this one.  It also ensures the the Tripal API is in scope for site
 
-  * upgrades when tripal_core is disabled.
 
-  */
 
- function tripal_contact_update_dependencies() {
 
-   $dependencies = array();
 
-   // the tripal_cv update 7200 must run prior to update 7200 of this module
 
-   $dependencies['tripal_contact'][7200] = array(
 
-     'tripal_cv' => 7200
 
-   );
 
-   return $dependencies;
 
- }
 
- /**
 
-  * Adds missing foreign key constraints
 
-  *
 
-  */
 
- function tripal_contact_update_7201() {
 
-   // Make sure we have the full API loaded this will help during a
 
-   // site upgrade when the tripal_core module is disabled.
 
-   module_load_include('module', 'tripal_core', 'tripal_core');
 
-   tripal_core_import_api();
 
-   // there was a bug in the function for creating a custom table that
 
-   // kept foreign key constraints from being added.  So, we need to add those
 
-   // to keep from error messages appear, we will drop the FK if it already
 
-   // exists and then re-add it.
 
-   try {
 
-     $fkey_exists = db_query('SELECT TRUE FROM pg_constraint WHERE conname = :constraint', array(':constraint' => 'contactprop_type_id_fkey'))->fetchField();
 
-     if ($fkey_exists) {
 
-       chado_query('
 
-         ALTER TABLE {contactprop}
 
-         DROP CONSTRAINT contactprop_type_id_fkey CASCADE
 
-       ');
 
-       chado_query('
 
-         ALTER TABLE {contactprop}
 
-         DROP CONSTRAINT contactprop_contact_id_fkey CASCADE
 
-       ');
 
-     }
 
-     chado_query('
 
-       ALTER TABLE {contactprop}
 
-       ADD CONSTRAINT contactprop_type_id_fkey
 
-       FOREIGN KEY (type_id) REFERENCES {cvterm} (cvterm_id)
 
-       ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
 
-     ');
 
-     chado_query('
 
-       ALTER TABLE {contactprop}
 
-       ADD CONSTRAINT contactprop_contact_id_fkey
 
-       FOREIGN KEY (contact_id) REFERENCES {contact} (contact_id)
 
-       ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
 
-     ');
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to update foriegn key: '. $error);
 
-   }
 
- }
 
- /**
 
-  * Updates path of tripal_contact OBO to be relative.
 
-  */
 
- function tripal_contact_update_7202() {
 
-   // Make sure we have the full API loaded this will help during a
 
-   // site upgrade when the tripal_core module is disabled.
 
-   module_load_include('module', 'tripal_core', 'tripal_core');
 
-   tripal_core_import_api();
 
-   module_load_include('inc', 'tripal_cv', 'api/tripal_cv.api');
 
-   try {
 
-     // Remove duplicates.
 
-     db_delete('tripal_cv_obo')
 
-       ->condition('name', 'Tripal Contacts')
 
-       ->execute();
 
-     // Add in the updated path.
 
-     $obo_path = '{tripal_contact}/files/tcontact.obo';
 
-     $obo_id = tripal_insert_obo('Tripal Contacts', $obo_path);
 
-   }
 
-   catch (\PDOException $e) {
 
-     $error = $e->getMessage();
 
-     throw new DrupalUpdateException('Failed to update tripal_contact OBO path: '. $error);
 
-   }
 
- }
 
 
  |