Browse Source

Update schema.php

FusionPBX 6 years ago
parent
commit
af9ef64152
1 changed files with 23 additions and 18 deletions
  1. 23 18
      resources/classes/schema.php

+ 23 - 18
resources/classes/schema.php

@@ -17,7 +17,7 @@
 
 
 	The Initial Developer of the Original Code is
 	The Initial Developer of the Original Code is
 	Mark J Crane <[email protected]>
 	Mark J Crane <[email protected]>
-	Copyright (C) 2013 - 2016
+	Copyright (C) 2013 - 2019
 	All Rights Reserved.
 	All Rights Reserved.
 
 
 	Contributor(s):
 	Contributor(s):
@@ -634,30 +634,35 @@ if (!class_exists('schema')) {
 												//get the field name
 												//get the field name
 													if (is_array($field['name'])) {
 													if (is_array($field['name'])) {
 														$field_name = $field['name']['text'];
 														$field_name = $field['name']['text'];
+														if (!$this->db_column_exists ($db_type, $db_name, $table_name, $field_name)) {
+															$field['exists'] == "false";
+														}
 													}
 													}
 													else {
 													else {
 														$field_name = $field['name'];
 														$field_name = $field['name'];
 													}
 													}
-												//find missing fields and add them
-													if ($field['exists'] == "false") {
-														$sql_update .= "ALTER TABLE ".$table_name." ADD ".$field_name." ".$field_type.";\n";
+
+												//add or rename fields
+													if ($this->db_column_exists ($db_type, $db_name, $table_name, $field['name']['deprecated'])) {
+														if ($db_type == "pgsql") {
+															$sql_update .= "ALTER TABLE ".$table_name." RENAME COLUMN ".$field['name']['deprecated']." to ".$field['name']['text'].";\n";
+														}
+														if ($db_type == "mysql") {
+															$field_type = str_replace("AUTO_INCREMENT PRIMARY KEY", "", $field_type);
+															$sql_update .= "ALTER TABLE ".$table_name." CHANGE ".$field['name']['deprecated']." ".$field['name']['text']." ".$field_type.";\n";
+														}
+														if ($db_type == "sqlite") {
+															//a change has been made to the field name
+															$apps[$x]['db'][$y]['rebuild'] = 'true';
+														}
 													}
 													}
-												//rename fields where the name has changed
-													if (is_array($field['name'])) {
-														if ($this->db_column_exists ($db_type, $db_name, $table_name, $field['name']['deprecated'])) {
-															if ($db_type == "pgsql") {
-																$sql_update .= "ALTER TABLE ".$table_name." RENAME COLUMN ".$field['name']['deprecated']." to ".$field['name']['text'].";\n";
-															}
-															if ($db_type == "mysql") {
-																$field_type = str_replace("AUTO_INCREMENT PRIMARY KEY", "", $field_type);
-																$sql_update .= "ALTER TABLE ".$table_name." CHANGE ".$field['name']['deprecated']." ".$field['name']['text']." ".$field_type.";\n";
-															}
-															if ($db_type == "sqlite") {
-																//a change has been made to the field name
-																$apps[$x]['db'][$y]['rebuild'] = 'true';
-															}
+													else {
+														//find missing fields and add them
+														if ($field['exists'] == "false") {
+															$sql_update .= "ALTER TABLE ".$table_name." ADD ".$field_name." ".$field_type.";\n";
 														}
 														}
 													}
 													}
+
 												//change the data type if it has been changed
 												//change the data type if it has been changed
 													//if the data type in the app db array is different than the type in the database then change the data type
 													//if the data type in the app db array is different than the type in the database then change the data type
 													if ($upgrade_data_types) {
 													if ($upgrade_data_types) {