Browse Source

edits to ugprade code

Stephen Ficklin 9 years ago
parent
commit
5e664b919e

+ 10 - 5
README.txt

@@ -53,20 +53,25 @@ occurs to find where deprecated functions may be used.
 Upgrade Instructions:
 
 Step 1: Put the site in maintenance mode.
-Step 2: Remove old Tripal v2 package and replace with Tripal v3 package
-Step 3: Enable the tripal module
+
+Step 3: Disable tripal modules
+
+  drush pm-disable tripal_core
+  
+Step 3: Remove old Tripal v2 package and replace with Tripal v3 package
+Step 4: Enable the tripal module
 
   drush pm-enable tripal
  
-Step 4: Enable the tripal_chado module  
+Step 5: Enable the tripal_chado module  
 
   drush pm-enable tripal_chado
   
-Step 5:  Apply updates
+Step 6:  Apply updates
 
   drush updatedb
   
-Step 6:  Return to your Tripal site, and click the link that appears for
+Step 7:  Return to your Tripal site, and click the link that appears for
 preparing Chado and launch the job.
 
 

+ 4 - 1
tripal/api/tripal.entities.api.inc

@@ -131,7 +131,10 @@ function tripal_create_bundle($namespace, $accession, $term_name, &$error = '')
   }
 
   // Next create the TripalTerm if it doesn't already exist.
-  $term = tripal_load_term_entity(array('namespace' => $namespace, 'accession' => $accession));
+  $term = tripal_load_term_entity(array(
+    'namespace' => $namespace,
+    'accession' => $accession
+  ));
   if (!$term) {
     $args = array('vocab_id' => $vocab->id, 'accession' => $accession, 'name' => $term_name);
     $term = entity_get_controller('TripalTerm')->create($args);

+ 11 - 10
tripal_chado/api/tripal_chado.api.inc

@@ -6,8 +6,6 @@
  * @param $values
  *   A key/value associative array that supports the following keys:
  *   - bundle_name:  The name of the the TripalBundle (e.g. bio_data-12345).
- *   - nid: (optional) The node ID from Tripal v2. This argument is used
- *   for miration of Tripal v2 nodes to Tripal v3 entities.
  * @param $job_id
  *   (Optional) The numeric job ID as provided by the Tripal jobs system. There
  *   is no need to specify this argument if this function is being called
@@ -41,12 +39,15 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
     $where .= "AND $column = $cvterm_id";
   }
 
-  $sql = "
-  SELECT $pkey_field as record_id
-  FROM {" . $table . "} T
-    LEFT JOIN public.chado_entity CE on CE.record_id = T.$pkey_field
-  AND CE.data_table = '$table'
-  WHERE CE.record_id IS NUll $where
+  $select = "SELECT $pkey_field as record_id ";
+  $from = "FROM {" . $table . "} T
+      LEFT JOIN public.chado_entity CE on CE.record_id = T.$pkey_field
+    AND CE.data_table = '$table'
+  "
+  $where = "WHERE CE.record_id IS NUll $where ";
+  if (table_exists('chado_' . $table)) {
+    $from .= "LEFT JOIN public.chado_$table
+  }
   ";
   $records = chado_query($sql);
   $num_published = 0;
@@ -63,7 +64,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
       $entity->save();
 
       // Next save the chado_entity record.
-      $record = array(
+      $entity_record = array(
         'entity_id' => $entity->id,
         'record_id' => $record_id,
         'data_table' => $table,
@@ -76,7 +77,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
       if ($nid) {
         // $record['nid'] = $nid;
       }
-      $success = drupal_write_record('chado_entity', $record);
+      $success = drupal_write_record('chado_entity', $entity_record);
 
       $entity = entity_load('TripalEntity', array($entity->id));
       $entity = reset($entity);

+ 49 - 48
tripal_chado/includes/tripal_chado.migrate.inc

@@ -2,9 +2,9 @@
 
 /**
  * Implements hook_form()
- * 
+ *
  * Provide a form to select Tripal v2 content types for migration
- * 
+ *
  * @param $form
  * @param $form_state
  */
@@ -14,7 +14,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
   if (array_key_exists('values', $form_state)) {
     $tv2_content_type = $form_state['values']['tv2_content_type'];
   }
-  
+
   $options = tripal_chado_get_tripal_v2_content_type_options(TRUE);
   $form['tv2_content_type'] = array(
     '#type' => 'select',
@@ -32,7 +32,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
 
   // Add a review button that allows reviewing migratable content types
   if ($tv2_content_type != 'all') {
-    
+
     $table = str_replace('chado_', '', $tv2_content_type);
     $schema = chado_get_schema($table);
     $pkey = $schema['primary key'][0];
@@ -41,9 +41,9 @@ function tripal_chado_migrate_form($form, &$form_state) {
     $form['tv3_content_type'] = array(
       '#type' => 'fieldset',
       '#title' => 'Tripal v3 Content Type',
-      '#description' => "Click the 'Get Tripal v3 Types' button to retrieve a list of Tripal v3 
-        content types to which this Tripal v2 type can be converted. This may take a while 
-        depending on the size of your database.  The number of items to be converted is 
+      '#description' => "Click the 'Get Tripal v3 Types' button to retrieve a list of Tripal v3
+        content types to which this Tripal v2 type can be converted. This may take a while
+        depending on the size of your database.  The number of items to be converted is
         shown beside the type."
     );
     $form['tv3_content_type']['get_v3_type_btn'] = array(
@@ -68,7 +68,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
       // Migrate selection only
       if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
         // Get all Tripal v2 node types from the chad_* linking table
-        $sql = 
+        $sql =
           "SELECT V.name AS type, X.accession, db.name AS namespace , count(*) AS num
               FROM chado.$table T
               INNER JOIN $tv2_content_type CT ON T.$pkey = CT.$pkey
@@ -78,7 +78,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
               GROUP BY V.name, X.accession, db.name";
         $tv3_content_types = db_query($sql);
         while($tv3_content_type = $tv3_content_types->fetchObject()) {
-          $form['tv3_content_type']['tv3_content_type--' . $tv3_content_type->namespace . 
+          $form['tv3_content_type']['tv3_content_type--' . $tv3_content_type->namespace .
               '--' . $tv3_content_type->accession . '--' . $tv3_content_type->type] = array(
             '#type' => 'checkbox',
             '#title' => $tv3_content_type->type . ' (' . $tv3_content_type->num . ')',
@@ -87,7 +87,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
       }
       else if ($table == 'organism') {
         $sql =
-          "SELECT count(*) 
+          "SELECT count(*)
               FROM chado.organism O
               INNER JOIN chado_organism CO ON O.organism_id = CO.organism_id";
         $org_count = db_query($sql)->fetchField();
@@ -109,7 +109,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
       }
     }
   }
-  
+
   // Submit button
   if ($tv2_content_type == 'all' || key_exists('tv3_migrate_all', $form['tv3_content_type'])) {
     $form['migrate_btn'] = array(
@@ -126,7 +126,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
 
 /**
  * Implements hook_validate()
- * 
+ *
  * @param $form
  * @param $form_state
  */
@@ -136,9 +136,9 @@ function tripal_chado_migrate_form_validate($form, &$form_state) {
 
 /**
  * Implements hook_submit()
- * 
+ *
  * By submiting the form, a Tripal job to migrate Tripal v2 content is submitted
- * 
+ *
  * @param $form
  * @param $form_state
  */
@@ -153,7 +153,7 @@ function tripal_chado_migrate_form_submit($form, &$form_state) {
         if (preg_match('/^tv3_content_type--(.+)--(.+)--(.+)/', $key, $matches) &&
             ($value == 1 || $values['tv3_migrate_all'] == 1)) {
           $namespace = $matches[1];
-          $accession = $matches[2];          
+          $accession = $matches[2];
           $type = $matches[3];
           $tv3_content_type [] = array(
             'namespace' => $namespace,
@@ -163,7 +163,7 @@ function tripal_chado_migrate_form_submit($form, &$form_state) {
         }
       }
     }
-    
+
     // Submit a job to migrate content
     global $user;
     $args = array(
@@ -176,7 +176,7 @@ function tripal_chado_migrate_form_submit($form, &$form_state) {
       module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.migrate'),
     );
     if ($tv2_content_type == 'all' || count($tv3_content_type) != 0) {
-      return tripal_add_job("Migrate $tv2_content_type Tripal v2 content.", 
+      return tripal_add_job("Migrate $tv2_content_type Tripal v2 content.",
         'tripal_chado', 'tripal_chado_migrate_records', $args, $user->uid, 10, $includes);
     }
     else {
@@ -187,27 +187,27 @@ function tripal_chado_migrate_form_submit($form, &$form_state) {
 
 /**
  * Ajax call back that returns the entire form
- * 
- * The callback is triggered by ajax elements on the form which leads to the update of 
+ *
+ * The callback is triggered by ajax elements on the form which leads to the update of
  * entire form according to the values set on the form
- * 
+ *
  * @param $form
  * @param $form_state
  * @return $form
- */ 
+ */
 function tripal_chado_migrate_form_ajax_callback($form, $form_state) {
   return $form;
 }
 
 /**
  * Get available Tripal v2 content types
- * 
+ *
  * @param boolean $all_option
  *   Include an 'all' option in the returned array
  * @return string[]
  *  Return a string array keyed by the node type
  */
-function tripal_chado_get_tripal_v2_content_type_options ($all_option = FALSE) {
+function tripal_chado_get_tripal_v2_content_type_options($all_option = FALSE) {
   // Get all available Tripal v2 chado tables
   $sql =
   "SELECT table_name
@@ -221,12 +221,12 @@ function tripal_chado_get_tripal_v2_content_type_options ($all_option = FALSE) {
       array_push($tables, $field);
     }
   }
-  
+
   // List all available Tripal v2 content types
   $result = db_select('node_type', 'nt')
-  ->fields('nt', array('type', 'name', 'description'))
-  ->condition('type', 'chado_%', 'LIKE')
-  ->execute();
+    ->fields('nt', array('type', 'name', 'description'))
+    ->condition('type', 'chado_%', 'LIKE')
+    ->execute();
   $options = array();
   if ($all_option) {
     $options['all'] = 'All';
@@ -241,50 +241,51 @@ function tripal_chado_get_tripal_v2_content_type_options ($all_option = FALSE) {
 
 /**
  * Tripal job callback to migrate Tripal v2 content into Tripal v3 content
- * 
+ *
  * @param $migration
  * @param $job_id
  */
  function tripal_chado_migrate_records($migration, $job_id = NULL) {
   $tv2_content_type = $migration['tv2_content_type'];
   $tv3_content_type = $migration['tv3_content_type'];
-  
+
   // If tv2_content_type is 'all', migrate all existing Tripal v2 content
   if ($tv2_content_type == 'all') {
     print "Migrating all Tripal v2 content...\n";
-    tripal_chado_migrate_all_types ();
+    tripal_chado_migrate_all_types();
   }
   // Otherwise, migrate only selected Tripal v2 content
   else {
     print "Migrating selected Tripal v2 content...\n";
-    tripal_chado_migrate_selected_types ($tv3_content_type);
+    tripal_chado_migrate_selected_types($tv3_content_type);
   }
 }
 
 /**
  * Migrate all Tripal v2 content types
  */
-function tripal_chado_migrate_all_types () {
+function tripal_chado_migrate_all_types() {
   // Get all available Tripal v2 content types
   $tv2_content_types = tripal_chado_get_tripal_v2_content_type_options();
-  
+
   $types = array();
   foreach($tv2_content_types AS $tv2_content_type => $value) {
     $table = str_replace('chado_', '', $tv2_content_type);
     $schema = chado_get_schema($table);
     $pkey = $schema['primary key'][0];
     $fkeys = $schema['foreign keys'];
-    
+
     if (key_exists('cvterm', $fkeys) && key_exists('type_id', $fkeys['cvterm']['columns'])) {
       // Get all Tripal v2 node types from the chad_* linking table
-      $sql =
-      "SELECT V.name AS type, X.accession, db.name AS namespace
-      FROM chado.$table T
-      INNER JOIN $tv2_content_type CT ON T.$pkey = CT.$pkey
-      INNER JOIN chado.cvterm V ON V.cvterm_id = T.type_id
-      INNER JOIN chado.dbxref X ON X.dbxref_id = V.dbxref_id
-      INNER JOIN chado.db ON db.db_id = X.db_id
-      GROUP BY V.name, X.accession, db.name";
+      $sql = "
+        SELECT V.name AS type, X.accession, db.name AS namespace
+        FROM chado.$table T
+          INNER JOIN $tv2_content_type CT ON T.$pkey = CT.$pkey
+          INNER JOIN chado.cvterm V ON V.cvterm_id = T.type_id
+          INNER JOIN chado.dbxref X ON X.dbxref_id = V.dbxref_id
+          INNER JOIN chado.db ON db.db_id = X.db_id
+        GROUP BY V.name, X.accession, db.name
+      ";
       $tv3_content_types = db_query($sql);
       while($tv3_content_type = $tv3_content_types->fetchObject()) {
         array_push($types, array(
@@ -309,7 +310,7 @@ function tripal_chado_migrate_all_types () {
       ));
     }
   }
-  
+
   tripal_chado_migrate_selected_types($types);
 }
 
@@ -318,12 +319,12 @@ function tripal_chado_migrate_all_types () {
  *
  * @param unknown $tv3_content_type
  */
-function tripal_chado_migrate_selected_types ($tv3_content_types) {
-  
-  foreach($tv3_content_types AS $tv3_content_type) {
+function tripal_chado_migrate_selected_types($tv3_content_types) {
+
+  foreach ($tv3_content_types AS $tv3_content_type) {
     // Check if the term already exists
     $term = tripal_load_term_entity($tv3_content_type);
-    
+
     // If term doesn't exist, create a new bundle for this term
     if (!$term) {
       print("Creating bundle for term '" . $tv3_content_type['term_name'] . "'...\n");
@@ -332,7 +333,7 @@ function tripal_chado_migrate_selected_types ($tv3_content_types) {
     }
     // Create bundle name
     $bundle_name = 'bio-data_' . $term->id;
-    
+
     // Publish records for the bundle
     tripal_chado_publish_records (array('bundle_name' => $bundle_name));
   }

+ 28 - 37
tripal_chado/tripal_chado.install

@@ -9,6 +9,34 @@ function tripal_chado_install() {
 //       FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
 //       ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
 //   ');
+
+  // For an upgraded site we need to move some vocabulary terms over
+  // to the new 'local' vocabulary:
+  tripal_insert_db(array(
+    'name' => 'local',
+    'description' => variable_get('site_name', 'This site.'),
+  ));
+
+  // Move the library properties out of the tripal database and into the
+  // local database.
+  $sql = "
+    UPDATE {dbxref}
+      SET db_id = (SELECT db_id FROM {db} WHERE name = 'local')
+    WHERE dbxref_id IN (
+      SELECT DISTINCT CVT.dbxref_id
+      FROM {cvterm} CVT
+        INNER JOIN {cv} CV ON CV.cv_id = CVT.cv_id
+      WHERE CV.name IN (
+        'library_property',
+        'library_type',
+        'project_property',
+        'nd_experiment_types',
+        'nd_geolocation_property',
+        'tripal_analysis'
+      )
+    )
+  ";
+  chado_query($sql);
 }
 
 /**
@@ -499,40 +527,3 @@ function tripal_chado_chado_entity_schema() {
   );
   return $schema;
 }
-
-/**
- * Moves vocabulary terms from the 'tripal' vocabulary to the 'local' vocabulary.
- */
-function tripal_chado_update_7300() {
-  try {
-
-    tripal_insert_db(array(
-      'name' => 'local',
-      'description' => variable_get('site_name', 'This site.'),
-    ));
-
-    // Move the library properties out of the tripal database and into the
-    // local database.
-    $sql = "
-      UPDATE {dbxref}
-        SET db_id = (SELECT db_id FROM {db} WHERE name = 'local')
-      WHERE dbxref_id IN (
-        SELECT DISTINCT CVT.dbxref_id
-        FROM {cvterm} CVT
-          INNER JOIN {cv} CV ON CV.cv_id = CVT.cv_id
-        WHERE CV.name IN (
-          'library_property',
-          'library_type',
-          'project_property',
-          'nd_experiment_types',
-          'nd_geolocation_property',
-          'tripal_analysis'
-        )
-      )
-    ";
-    chado_query($sql);
-  }
-  catch (\PDOException $e) {
-    $error = $e->getMessage();
-    throw new DrupalUpdateException('Failed to complete update' . $error);
-  }}