Эх сурвалжийг харах

Fixed classes functions that were improperly defined after notice via PHP 7.2 upgrade.

Stephen Ficklin 7 жил өмнө
parent
commit
abfa405e63

+ 50 - 0
tests/TripalEntityCollection.test

@@ -0,0 +1,50 @@
+<?php
+
+// Bootstrap Drupal.
+$_SERVER['HTTP_HOST'] = 'localhost';
+$_SERVER['SCRIPT_NAME'] = '/index.php';
+$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
+$_SERVER['REQUEST_METHOD'] = 'GET';
+$_SERVER['SERVER_NAME'] = NULL;
+$_SERVER['SERVER_SOFTWARE'] = NULL;
+$_SERVER['HTTP_USER_AGENT'] = NULL;
+define('DRUPAL_ROOT', '/var/www/html');
+require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
+drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+
+use PHPUnit\Framework\TestCase;
+
+class TripalEntityCollectionTest extends TestCase {
+
+  protected $collection = NULL;
+
+
+  public function setUp() {
+    $details = ['uid' => 1, 'collection_name' => "test_collection_name"];
+    $collection = new TripalEntityCollection();
+    $collection->create($details);
+    $this->collection = $collection;
+  }
+
+  public function testCreateCollectionAndBaseGetters() {
+
+    $collection = $this->collection;
+
+    $name = $collection->getName();
+    $collection_id = $collection->getCollectionID();
+    $this->assertEquals($name, "test_collection_name");
+    $this->assertNotNull($collection_id);
+    $this->assertInternalType("int", (int) $collection_id);
+  }
+
+  public function testAddBundle() {
+//create two entities, AND their fields.  annoying.
+
+    $details = ['bundle_name' => 'organism'];
+
+  }
+
+  public function tearDown() {
+    $this->collection->delete();
+  }
+}

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

@@ -45,6 +45,7 @@
  * @ingroup tripal_data_collections_api
  */
 function tripal_create_collection($details) {
+
   global $user;
 
   try {
@@ -53,7 +54,7 @@ function tripal_create_collection($details) {
     $collection_id = $collection->getCollectionID();
     $collection->addBundle($details);
 
-    drupal_set_message(t("Collection '%name' created with %num_recs record(s). Check the !view for generate file links.",
+    drupal_set_message(t("Collection '%name' created with %num_recs record(s). Check the !view to generate file links.",
       array(
         '%name' => $details['collection_name'],
         '%num_recs' => count($details['ids']),

+ 1 - 1
tripal/includes/TripalEntityCollection.inc

@@ -165,7 +165,7 @@ class TripalEntityCollection {
     }
 
 
-    // Before inserting the new collection make sure we don't violote the unique
+    // Before inserting the new collection make sure we don't violate the unique
     // constraint that a user can only have one collection of the give name.
     $has_match = db_select('tripal_collection', 'tc')
       ->fields('tc', array('collection_id'))

+ 2 - 2
tripal/includes/TripalEntityController.inc

@@ -322,7 +322,7 @@ class TripalEntityController extends EntityAPIController {
    * @return
    *   The saved entity object with updated properties.
    */
-  public function save($entity) {
+  public function save($entity, DatabaseTransaction $transaction = NULL) {
     global $user;
     $pkeys = array();
 
@@ -348,7 +348,7 @@ class TripalEntityController extends EntityAPIController {
       }
     }
 
-    $transaction  = db_transaction();
+    $transaction = isset($transaction) ? $transaction : db_transaction();
     try {
       // If our entity has no id, then we need to give it a
       // time of creation.

+ 17 - 9
tripal/includes/TripalTermController.inc

@@ -18,16 +18,24 @@ class TripalTermController extends EntityAPIController {
   /**
    * Delete a single entity.
    */
-  public function delete($entity) {
-    $transaction = db_transaction();
+  public function delete($ids, DatabaseTransaction $transaction = NULL) {
+    $entities = $ids ? $this->load($ids) : FALSE;
+    if (!$entities) {
+      // Do nothing, in case invalid or no ids have been passed.
+      return;
+    }
+    $transaction = isset($transaction) ? $transaction : db_transaction();
     try {
       // Invoke hook_entity_delete().
-      module_invoke_all('entity_delete', $entity, 'TripalTerm');
-      field_attach_delete('TripalTerm', $entity);
+      $ids = array_keys($entities);
+      foreach ($entities as $id => $entity) {
+        module_invoke_all('entity_delete', $entity, 'TripalTerm');
+        field_attach_delete('TripalTerm', $entity);
 
-      db_delete('tripal_term')
-        ->condition('accession', $entity->accession)
-        ->execute();
+        db_delete('tripal_term')
+          ->condition('accession', $entity->accession)
+          ->execute();
+      }
     }
     catch (Exception $e) {
       $transaction->rollback();
@@ -41,11 +49,11 @@ class TripalTermController extends EntityAPIController {
   /**
    * Saves the custom fields using drupal_write_record().
    */
-  public function save($entity) {
+  public function save($entity, DatabaseTransaction $transaction = NULL) {
     global $user;
     $pkeys = array();
 
-    $transaction  = db_transaction();
+    $transaction = isset($transaction) ? $transaction : db_transaction();
     try {
       // If our entity has no id, then we need to give it a
       // time of creation.

+ 16 - 8
tripal/includes/TripalVocabController.inc

@@ -21,15 +21,23 @@ class TripalVocabController extends EntityAPIController {
    *
    * Really a convenience function for deleteMultiple().
    */
-  public function delete($entity) {
-    $transaction = db_transaction();
+  public function delete($ids, DatabaseTransaction $transaction = NULL) {
+    $entities = $ids ? $this->load($ids) : FALSE;
+    if (!$entities) {
+      // Do nothing, in case invalid or no ids have been passed.
+      return;
+    }
+    $transaction = isset($transaction) ? $transaction : db_transaction();
     try {
-      // Invoke hook_entity_delete().
-      module_invoke_all('entity_delete', $entity, 'TripalTerm');
-      field_attach_delete('TripalVocab', $entity);
+      $ids = array_keys($entities);
+      foreach ($entities as $id => $entity) {
+        // Invoke hook_entity_delete().
+        module_invoke_all('entity_delete', $entity, 'TripalTerm');
+        field_attach_delete('TripalVocab', $entity);
+      }
 
       db_delete('tripal_term')
-        ->condition('id', $entity->id)
+        ->condition('id', $ids)
         ->execute();
     }
     catch (Exception $e) {
@@ -44,11 +52,11 @@ class TripalVocabController extends EntityAPIController {
   /**
    * Saves the custom fields using drupal_write_record().
    */
-  public function save($entity) {
+  public function save($entity, DatabaseTransaction $transaction = NULL) {
     global $user;
     $pkeys = array();
 
-    $transaction  = db_transaction();
+    $transaction = isset($transaction) ? $transaction : db_transaction();
     try {
       // If our entity has no id, then we need to give it a
       // time of creation.