Browse Source

Merge pull request #352 from statonlab/fix-350

Fix issue #350
Stephen Ficklin 6 years ago
parent
commit
693d02789e
1 changed files with 24 additions and 15 deletions
  1. 24 15
      tripal_chado/api/modules/tripal_chado.cv.api.inc

+ 24 - 15
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -739,21 +739,30 @@ function tripal_update_cvtermpath_loop_increment(
         }
       }
 
-      $query = db_insert('cvtermpath')
-        ->fields([
-          'object_id' => $origin,
-          'subject_id' => $child_id,
-          'cv_id' => $cv_id,
-          'type_id' => $type_id,
-          'pathdistance' => $depth,
-        ]);
-
-      try {
-        $rows = $query->execute();
-      } catch (Exception $e) {
-        $error = $e->getMessage();
-        tripal_report_error('tripal_chado', TRIPAL_ERROR, "Could not fill cvtermpath term: @error", array('@error' => $error));
-        return false;
+      $find_query = db_select('chado.cvtermpath', 'CVTP');
+      $find_query->fields('CVTP', ['subject_id']);
+      $find_query->condition('object_id', $origin);
+      $find_query->condition('subject_id', $child_id);
+      $find_query->condition('type_id', $type_id);
+      $find_query->condition('pathdistance', $depth);
+      $exists = $find_query->execute()->fetchObject();
+
+      if(!$exists){
+        $query = db_insert('cvtermpath')
+          ->fields([
+            'object_id' => $origin,
+            'subject_id' => $child_id,
+            'cv_id' => $cv_id,
+            'type_id' => $type_id,
+            'pathdistance' => $depth,
+          ]);
+        try {
+          $rows = $query->execute();
+        } catch (Exception $e) {
+          $error = $e->getMessage();
+          tripal_report_error('tripal_chado', TRIPAL_ERROR, "Could not fill cvtermpath term: @error", array('@error' => $error));
+          return false;
+        }
       }
 
       // Then add that new entry to the $tree_path.