Browse Source

Fixes to link field creation

Stephen Ficklin 8 years ago
parent
commit
edca5d502a
1 changed files with 31 additions and 34 deletions
  1. 31 34
      tripal_chado/includes/tripal_chado.migrate.inc

+ 31 - 34
tripal_chado/includes/tripal_chado.migrate.inc

@@ -67,7 +67,7 @@ function tripal_chado_migrate_form($form, &$form_state) {
         visitors can continue to visit the Tripal v2 pages. Tripal
         visitors can continue to visit the Tripal v2 pages. Tripal
         v3 content types may remain private while customization is underway.
         v3 content types may remain private while customization is underway.
         Once customization is completed a subsequent step will allow you to
         Once customization is completed a subsequent step will allow you to
-        swap out Tripal v2 pages for the newer Tripal v3 pages. If you would like to 
+        swap out Tripal v2 pages for the newer Tripal v3 pages. If you would like to
         use Trial v3 web services you must migrate content types.'),
         use Trial v3 web services you must migrate content types.'),
   );
   );
 
 
@@ -516,8 +516,8 @@ function tripal_chado_migrate_form_step2_ajax_callback(&$form, &$form_state) {
  * @param boolean $all_option
  * @param boolean $all_option
  *   Include an 'all' option in the returned array
  *   Include an 'all' option in the returned array
  * @param boolean $has_template
  * @param boolean $has_template
- *   Return TV2 content types only if it has a base template. This will exclude TV2 content 
- *   types such as Blast/Kegg/Interpro/Unigene which are all converted into the TV3 
+ *   Return TV2 content types only if it has a base template. This will exclude TV2 content
+ *   types such as Blast/Kegg/Interpro/Unigene which are all converted into the TV3
  *   'Analysis' entity type
  *   'Analysis' entity type
  * @return string[]
  * @return string[]
  *  Return a string array keyed by the node type
  *  Return a string array keyed by the node type
@@ -720,11 +720,11 @@ function tripal_chado_migrate_selected_types($tv3_content_types) {
       'bundle_name' => $bundle_name
       'bundle_name' => $bundle_name
     );
     );
     tripal_chado_publish_records($value);
     tripal_chado_publish_records($value);
-    
+
     // Migrate Resource Titles/Blocks or Resource Links if available
     // Migrate Resource Titles/Blocks or Resource Links if available
     tripal_chado_migrate_resource_blocks($bundle_name);
     tripal_chado_migrate_resource_blocks($bundle_name);
     tripal_chado_migrate_resource_links($bundle_name);
     tripal_chado_migrate_resource_links($bundle_name);
-    
+
     // Migrate organism images
     // Migrate organism images
     if ($term->name == 'organism') {
     if ($term->name == 'organism') {
       tripal_chado_migrate_organism_images($bundle_name);
       tripal_chado_migrate_organism_images($bundle_name);
@@ -825,16 +825,16 @@ function tripal_chado_migrate_url_alias_for_selected_types($tv2_content_types =
 function tripal_chado_migrate_organism_images () {
 function tripal_chado_migrate_organism_images () {
   // Get all organism entities
   // Get all organism entities
   $bio_data_table = array_pop(tripal_chado_migrate_get_biodata_tables('organism'));
   $bio_data_table = array_pop(tripal_chado_migrate_get_biodata_tables('organism'));
-  $results = 
+  $results =
     db_select($bio_data_table, 'ce')
     db_select($bio_data_table, 'ce')
     ->fields('ce', array('entity_id', 'record_id', 'nid'))
     ->fields('ce', array('entity_id', 'record_id', 'nid'))
     ->execute();
     ->execute();
-  
+
   // Iterate through each organism entity
   // Iterate through each organism entity
   while ($organism = $results->fetchObject()) {
   while ($organism = $results->fetchObject()) {
     $nid = $organism->nid;
     $nid = $organism->nid;
     $entity_id = $organism->entity_id;
     $entity_id = $organism->entity_id;
-    
+
     // check if there is a file record for the organism node
     // check if there is a file record for the organism node
     $fid = db_select('file_usage', 'fu')
     $fid = db_select('file_usage', 'fu')
     ->fields('fu', array('fid'))
     ->fields('fu', array('fid'))
@@ -845,13 +845,13 @@ function tripal_chado_migrate_organism_images () {
     ->fetchField();
     ->fetchField();
     // check if the image was added using the old interface.
     // check if the image was added using the old interface.
     if (!$fid) {
     if (!$fid) {
-      $sql = 
-         "SELECT genus,species,nid 
-          FROM {organism} O 
-          INNER JOIN chado_organism CO ON O.organism_id = CO.organism_id 
+      $sql =
+         "SELECT genus,species,nid
+          FROM {organism} O
+          INNER JOIN chado_organism CO ON O.organism_id = CO.organism_id
           WHERE O.organism_id = :organism_id";
           WHERE O.organism_id = :organism_id";
       $chado_org = chado_query($sql, array(':organism_id' => $organism->record_id))->fetchObject();
       $chado_org = chado_query($sql, array(':organism_id' => $organism->record_id))->fetchObject();
-      
+
       if ($chado_org) {
       if ($chado_org) {
         $base_path = realpath('.');
         $base_path = realpath('.');
         $image_dir = tripal_get_files_dir('tripal_organism') . "/images";
         $image_dir = tripal_get_files_dir('tripal_organism') . "/images";
@@ -876,19 +876,19 @@ function tripal_chado_migrate_organism_images () {
         }
         }
         if($file){
         if($file){
           tripal_chado_migrate_organism_image_add_file($file->fid, $entity_id);
           tripal_chado_migrate_organism_image_add_file($file->fid, $entity_id);
-        }        
+        }
       }
       }
     }
     }
     else {
     else {
       // If there is an image, add it to the organism entity
       // If there is an image, add it to the organism entity
       tripal_chado_migrate_organism_image_add_file ($fid, $entity_id);
       tripal_chado_migrate_organism_image_add_file ($fid, $entity_id);
     }
     }
-    
+
   }
   }
 }
 }
 
 
 /**
 /**
- * 
+ *
  * Add image file for the organism entity
  * Add image file for the organism entity
  *
  *
  * @param unknown $fid
  * @param unknown $fid
@@ -911,7 +911,7 @@ function tripal_chado_migrate_organism_image_add_file ($fid, $entity_id) {
     field_attach_update('TripalEntity', $entity);
     field_attach_update('TripalEntity', $entity);
     entity_get_controller('TripalEntity')->resetCache(array($entity_id));
     entity_get_controller('TripalEntity')->resetCache(array($entity_id));
     // Add a record to the field_data_data__image table
     // Add a record to the field_data_data__image table
-    
+
   }
   }
 }
 }
 
 
@@ -940,24 +940,24 @@ function tripal_chado_migrate_get_biodata_tables ($chado_table) {
 }
 }
 
 
 function tripal_chado_migrate_resource_blocks($bundle_name) {
 function tripal_chado_migrate_resource_blocks($bundle_name) {
-  $entites = 
+  $entites =
     db_select('chado_' . $bundle_name, 'B')
     db_select('chado_' . $bundle_name, 'B')
     ->fields('B', array('nid'))
     ->fields('B', array('nid'))
     ->execute();
     ->execute();
   while ($nid = $entites->fetchField()) {
   while ($nid = $entites->fetchField()) {
     // Only the latest revision is migrated
     // Only the latest revision is migrated
     $sql = "
     $sql = "
-      SELECT 
+      SELECT
         entity_id,
         entity_id,
         max(revision_id) AS vid,
         max(revision_id) AS vid,
         delta,
         delta,
-        (SELECT field_resource_titles_value 
+        (SELECT field_resource_titles_value
          FROM field_revision_field_resource_titles
          FROM field_revision_field_resource_titles
          WHERE entity_id = RT.entity_id
          WHERE entity_id = RT.entity_id
          AND revision_id = max(RT.revision_id)
          AND revision_id = max(RT.revision_id)
          AND delta = RT.delta
          AND delta = RT.delta
         ),
         ),
-        (SELECT field_resource_blocks_value 
+        (SELECT field_resource_blocks_value
          FROM field_revision_field_resource_blocks
          FROM field_revision_field_resource_blocks
          WHERE entity_id = RT.entity_id
          WHERE entity_id = RT.entity_id
          AND revision_id = max(RT.revision_id)
          AND revision_id = max(RT.revision_id)
@@ -974,7 +974,7 @@ function tripal_chado_migrate_resource_blocks($bundle_name) {
       $content = $resource->field_resource_blocks_value;
       $content = $resource->field_resource_blocks_value;
       $delta = $resource->delta;
       $delta = $resource->delta;
       $nid = $resource->entity_id;
       $nid = $resource->entity_id;
-      $entity_id = 
+      $entity_id =
         db_select('chado_' . $bundle_name, 'B')
         db_select('chado_' . $bundle_name, 'B')
         ->fields('B', array('entity_id'))
         ->fields('B', array('entity_id'))
         ->condition('nid', $nid)
         ->condition('nid', $nid)
@@ -1043,7 +1043,7 @@ function tripal_chado_migrate_resource_blocks($bundle_name) {
           ':delta' => 0,
           ':delta' => 0,
           ':value' => $content,
           ':value' => $content,
           ':format' => 'full_html'
           ':format' => 'full_html'
-        )  
+        )
       );
       );
       $rsql = "
       $rsql = "
       INSERT INTO $frtable (entity_type, bundle, entity_id, revision_id, language, delta, $fvalue, $fformat)
       INSERT INTO $frtable (entity_type, bundle, entity_id, revision_id, language, delta, $fvalue, $fformat)
@@ -1097,11 +1097,11 @@ function tripal_chado_migrate_resource_links($bundle_name) {
       $nid = $resource->entity_id;
       $nid = $resource->entity_id;
       $entity_id =
       $entity_id =
       db_select('chado_' . $bundle_name, 'B')
       db_select('chado_' . $bundle_name, 'B')
-      ->fields('B', array('entity_id'))
-      ->condition('nid', $nid)
-      ->execute()
-      ->fetchField()
-      ;
+        ->fields('B', array('entity_id'))
+        ->condition('nid', $nid)
+        ->execute()
+        ->fetchField();
+
       // field name: (can not be longer than 32 chars)
       // field name: (can not be longer than 32 chars)
       // bio_data_<i>_resource_<title to lower case/space replaced with _/first 10 chars>
       // bio_data_<i>_resource_<title to lower case/space replaced with _/first 10 chars>
       $field_name = $bundle_name . '_resource_links';
       $field_name = $bundle_name . '_resource_links';
@@ -1116,12 +1116,10 @@ function tripal_chado_migrate_resource_links($bundle_name) {
             'type' => 'field_sql_storage',
             'type' => 'field_sql_storage',
           ),
           ),
           'settings' => array(
           'settings' => array(
-            'max_length' => 10485760,
-            'text_processing' => 1
           )
           )
         ));
         ));
       }
       }
-      // Create field instance for the bundle if it does not exist
+      // Create field instance for the bundle if it does not exist.
       if (!field_info_instance('TripalEntity', $field_name, $bundle_name)) {
       if (!field_info_instance('TripalEntity', $field_name, $bundle_name)) {
         field_create_instance(array(
         field_create_instance(array(
           'field_name' => $field_name,
           'field_name' => $field_name,
@@ -1129,7 +1127,7 @@ function tripal_chado_migrate_resource_links($bundle_name) {
           'bundle' => $bundle_name,
           'bundle' => $bundle_name,
           'label' => 'Links',
           'label' => 'Links',
           'widget' => array(
           'widget' => array(
-            'type' => 'text_textfield',
+            'type' => 'link_field',
           ),
           ),
           'display' => array(
           'display' => array(
             'default' => array(
             'default' => array(
@@ -1137,11 +1135,10 @@ function tripal_chado_migrate_resource_links($bundle_name) {
             ),
             ),
           ),
           ),
           'settings' => array(
           'settings' => array(
-            'text_processing' => 1,
-            'format' => 'full_html',
             'term_vocabulary' => 'schema',
             'term_vocabulary' => 'schema',
             'term_name' => 'url',
             'term_name' => 'url',
             'term_accession' => 'url',
             'term_accession' => 'url',
+            'absolute_url' => 0,
           ),
           ),
         ));
         ));
       }
       }