Explorar o código

Merge pull request #428 from tripal/375-Tv3-deleting_fields

Deleting Fields
Stephen Ficklin %!s(int64=6) %!d(string=hai) anos
pai
achega
48e1a690cf

+ 22 - 0
tripal/includes/tripal.field_storage.inc

@@ -76,10 +76,18 @@ function tripal_field_storage_query($query) {
   $select->join('tripal_bundle', 'TB', 'TE.bundle = TB.name');
   $select->fields('TE', array('id'));
   $select->fields('TB', array('name'));
+  
+  // Apply any entity condition filters.
+  if ($query->entityConditions) {
+    if (array_key_exists('bundle', $query->entityConditions)) {
+      $select->condition('TB.name', $query->entityConditions['bundle']['value']);
+    }
+  }
 
   // Add in any filters to the query.
   foreach ($query->fieldConditions as $index => $condition) {
     $field = $condition['field'];
+    
     // Skip conditions that don't belong to this storage type.
     if ($field['storage']['type'] != 'tripal_no_storage') {
       continue;
@@ -107,6 +115,20 @@ function tripal_field_storage_query($query) {
       $select->orderBy('TB.label', $direction);
     }
   }
+  
+  // Add a range of records to retrieve
+  if (isset($query->range)) {
+    $select->range($query->range['start'], $query->range['length']);
+  }
+  
+  // Only include records that are deleted.  Tripal doesn't keep track of
+  // records that are deleted that need purging separately so we can do nothing
+  // with this.
+  if (isset($query->deleted)) {
+    // There won't ever be field data marked as deleted so just created a 
+    // condition that always evaluates to false.
+    $select->where('1=0');
+  }
 
   // Perform the query and return the results.
   $entities = $select->execute();

+ 4 - 1
tripal_chado/api/tripal_chado.variables.api.inc

@@ -788,9 +788,12 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
       }
       $foreign_table_desc = chado_get_schema($foreign_table);
 
-      // TODO: if we don't get a foreign_table (which could happen of a custom 
+      // If we don't get a foreign_table (which could happen of a custom 
       // table is not correctly defined or the table name is mispelled then we 
       // should return gracefully.
+      if(!is_array($foreign_table_desc)) {
+        return $object;
+      }
 
       // BASE CASE: If it's connected to the base table via a FK constraint
       // then we have all the information needed to expand it now.

+ 10 - 0
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -728,6 +728,16 @@ function tripal_chado_field_storage_query($query) {
       } // end foreach ($field['bundles']['TripalEntity'] as $bundle_name) {
     } // end if ($sort['type'] == 'field') {
   } // end foreach ($query->order as $index => $sort) {
+  
+  
+  // Only include records that are deleted.  Tripal doesn't keep track of
+  // records that are deleted that need purging separately so we can do nothing
+  // with this.
+  if (isset($query->deleted)) {
+    // There won't ever be field data marked as deleted so just created a
+    // condition that always evaluates to false.
+    $cquery->where('1=0');
+  }
 
  //dpm($cquery->__toString());
  //dpm($cquery->getArguments());