Browse Source

Added checks to prevent errors in the chado_create_custom_table() function, and fixes for PHP 7.2 compatibility

Stephen Ficklin 6 years ago
parent
commit
00cb9f3cfc

+ 12 - 0
tripal_chado/api/tripal_chado.custom_tables.api.inc

@@ -128,6 +128,18 @@ function chado_edit_custom_table($table_id, $table_name, $schema, $skip_if_exist
  */
 function chado_create_custom_table($table, $schema, $skip_if_exists = TRUE,
     $mview_id = NULL, $redirect = TRUE) {
+  
+  if (!$table) {
+    throw new Exception('Please provide a value for the $table argument to the chado_create_custom_table() function'); 
+  }
+  if (!$schema) {
+    throw new Exception('Please provide a value for the $schema argument to the chado_create_custom_table() function');
+  }
+  if ($schema and !is_array($schema)) {
+    throw new Exception('Please provide an array for the $schema argument to the chado_create_custom_table() function');
+  }
+  // TODO: make sure the schema is valid by adding extra checks.
+  
 
   global $databases;
   $created = 0;

+ 1 - 1
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -142,7 +142,7 @@ class sbo__database_cross_reference extends ChadoField {
     $linker_table = $base_table . '_dbxref';
     $options = array('return_array' => 1);
     $record = chado_expand_var($record, 'table', $linker_table, $options);
-    if (count($record->$linker_table) > 0) {
+    if (property_exists($record, $linker_table) and is_array($record->$linker_table) and count($record->$linker_table) > 0) {
       $i = 0;
       foreach ($record->$linker_table as $index => $linker) {
         $dbxref = $linker->dbxref_id;

+ 1 - 1
tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc

@@ -103,7 +103,7 @@ class schema__publication extends ChadoField {
       'return_array' => 1,
     );
     $record = chado_expand_var($record, 'table', $linker_table, $options);
-    if (count($record->$linker_table) > 0) {
+    if (property_exists($record, $linker_table) and is_array($record->$linker_table) and count($record->$linker_table) > 0) {
       $i = 0;
       foreach ($record->$linker_table as $index => $linker) {
         $pub = $linker->pub_id;