From ec65ab905de42fe90a567e0fe961aaa4265ba34f Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Fri, 24 Jul 2020 10:15:30 -0600 Subject: [PATCH] Fix the database copy method. --- resources/classes/database.php | 37 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/resources/classes/database.php b/resources/classes/database.php index 0b0ce81a7c..31fad75c1b 100644 --- a/resources/classes/database.php +++ b/resources/classes/database.php @@ -1314,36 +1314,36 @@ include "root.php"; $checked = true; //copy the child data - $copy_array[$parent_name][$x][$parent_key_name] = $row[$parent_key_name]; + if (is_uuid($row[$parent_key_name])) { + $copy_array[$parent_name][$x][$parent_key_name] = $row[$parent_key_name]; + } //remove the row from the main array unset($array[$parent_name][$x]); - } - //loop through the fields - foreach($row as $field_name => $field_value) { + //loop through the fields - //find the child tables - $y = 0; - if (is_array($field_value)) { - //prepare the variables - $child_name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $field_name); - $child_key_name = $this->singular($child_name)."_uuid"; + foreach($row as $field_name => $field_value) { + //find the child tables + if (is_array($field_value)) { - //loop through the child rows - foreach ($field_value as $sub_row) { + //prepare the variables + $child_name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $field_name); + $child_key_name = $this->singular($child_name)."_uuid"; + + //loop through the child rows + $y = 0; + foreach ($field_value as $sub_row) { - //build the delete array - if ($sub_row['checked'] == 'true') { //delete the child data - $copy_array[$child_name][$y][$child_key_name] = $sub_row[$child_key_name]; + $copy_array[$child_name][][$child_key_name] = $sub_row[$child_key_name]; //remove the row from the main array unset($array[$parent_name][$x][$child_name][$y]); - } - //increment the value - $y++; + //increment the value + $y++; + } } } } @@ -1358,6 +1358,7 @@ include "root.php"; //get the current data if (is_array($copy_array) && count($copy_array) > 0) { + //build an array of tables, fields, and values foreach($copy_array as $table_name => $rows) { foreach($rows as $row) {