فهرست منبع

Fixed bugs deleting collections and warnings from PHP 7.2 upgrade

Stephen Ficklin 7 سال پیش
والد
کامیت
1c693d339f

+ 8 - 8
tripal/includes/TripalEntityCollection.inc

@@ -60,6 +60,14 @@ class TripalEntityCollection {
     }
 
     try {
+      // Remove any files that may have been created
+      foreach ($this->formatters as $class_name => $label) {
+        tripal_load_include_downloader_class($class_name);
+        $outfile = $this->getOutfile($class_name);
+        $downloader = new $class_name($this->collection_id, $outfile);
+        $downloader->delete();
+      }
+
       // Delete from the tripal collection table.
       db_delete('tripal_collection')
         ->condition('collection_id', $this->collection_id)
@@ -70,14 +78,6 @@ class TripalEntityCollection {
         ->condition('collection_id', $this->collection_id)
         ->execute();
 
-      // Remove any files that may have been created
-      foreach ($this->formatters as $class_name => $label) {
-        tripal_load_include_downloader_class($class_name);
-        $outfile = $this->getOutfile($class_name);
-        $downloader = new $class_name($this->collection_id, $outfile);
-        $downloader->delete();
-      }
-
       // Reset the class to defaults.
       $this->collection_id = NULL;
       $this->collection_name = '';

+ 12 - 6
tripal/includes/TripalFieldDownloaders/TripalFieldDownloader.inc

@@ -130,12 +130,17 @@ abstract class TripalFieldDownloader {
     }
 
     // Get the collection record and store it.
-    $this->collection = db_select('tripal_collection', 'tc')
+    $collection = db_select('tripal_collection', 'tc')
       ->fields('tc')
       ->condition('collection_id', $collection_id, '=')
       ->execute()
       ->fetchObject();
 
+    if (!$collection) {
+      throw new Exception(t("Cannot find a collection that matches the provided id: !id", array('!id' => $collection_id)));
+    }
+    $this->collection = $collection;
+
     // Make sure the user directory exists
     $user = user_load($this->collection->uid);
     $user_dir = 'public://tripal/users/' . $user->uid;
@@ -143,7 +148,6 @@ abstract class TripalFieldDownloader {
     // Set the collection ID of the collection that this downloader will use.
     $this->collection_id = $collection_id;
     $this->outfile = $user_dir . '/' . $outfile_name;
-    $this->selected_fields = $selected_fields;
 
     // A data collection may have multiple bundles.  We'll need to get
     // them all and store them.
@@ -183,18 +187,19 @@ abstract class TripalFieldDownloader {
   public function isFieldSupported($field, $instance) {
     $field_name = $field['field_name'];
     $field_type = $field['type'];
+    $this_formatter = get_class($this);
 
     // If a field is a TripalField then check its supported downloaders.
     if (tripal_load_include_field_class($field_type)) {
       $formatters = $field_type::$download_formatters;
-      if (in_array($formatter, $settings['download_formatters'])) {
+      if (in_array($this_formatter, $formatters)) {
         return TRUE;
       }
     }
 
-    $is_remote = $field['field']['storage']['type'] == 'tripal_remote_field' ? TRUE : FALSE;
-    if ($is_remote) {
-      if (in_array($formatter, $instance['formatters'])) {
+    // If this is a remote field then check that differently.
+    if ($field['storage']['type'] == 'tripal_remote_field' ) {
+      if (in_array($this_formatter, $instance['formatters'])) {
         return TRUE;
       }
     }
@@ -464,6 +469,7 @@ abstract class TripalFieldDownloader {
     foreach ($this->fields as $site => $bundles) {
       foreach ($bundles as $bundle_name => $bundle_fields) {
         foreach ($bundle_fields as $field_id => $info) {
+          $field = $info['field'];
           $instance = $info['instance'];
           $accession = $instance['settings']['term_vocabulary'] . ':' . $instance['settings']['term_accession'];
           if (!array_key_exists($accession, $this->printable_fields)) {

+ 2 - 1
tripal/includes/tripal.collections.inc

@@ -205,7 +205,8 @@ function tripal_user_collections_delete_form_submit($form, &$form_state) {
       drupal_set_message('The data collection has been deleted.');
     }
     catch (Exception $e) {
-      drupal_set_message('There was a problem deleting the data collection please contact the site to report the error.', 'error');
+      drupal_set_message(t('There was a problem deleting the data collection ' .
+          'please contact the site to report the error: !message', array('!message', $e->getMessage())), 'error');
     }
   }
   drupal_goto('user/' . $user->uid . '/data-collections');

+ 3 - 2
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name.inc

@@ -79,9 +79,10 @@ class schema__alternate_name extends ChadoField {
     $linker_table = $base_table . '_synonym';
     $options = array('return_array' => 1);
     $record = chado_expand_var($record, 'table', $linker_table, $options);
-    if (count($record->$linker_table) > 0) {
+    $synonyms_linker = $record->$linker_table;
+    if (is_array($synonyms_linker) and count($synonyms_linker) > 0) {
       $i = 0;
-      foreach ($record->$linker_table as $index => $linker) {
+      foreach ($synonyms_linker as $index => $linker) {
         $synonym = $linker->synonym_id;
         $entity->{$field_name}['und'][$i] = array(
           'value' => $synonym->name,