Update schema.php

This commit is contained in:
FusionPBX
2017-02-16 00:03:33 -07:00
committed by GitHub
parent f1af0e7fa5
commit 2d68fa9118
+37 -26
View File
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Copyright (C) 2013 - 2014 Copyright (C) 2013 - 2016
All Rights Reserved. All Rights Reserved.
Contributor(s): Contributor(s):
@@ -63,8 +63,8 @@ if (!class_exists('schema')) {
if (isset($app['db']) && count($app['db'])) { if (isset($app['db']) && count($app['db'])) {
foreach ($app['db'] as $row) { foreach ($app['db'] as $row) {
//create the sql string //create the sql string
$table_name = $row['table']; $table_name = $row['table']['name'];
$sql = "CREATE TABLE " . $row['table'] . " (\n"; $sql = "CREATE TABLE " . $row['table']['name'] . " (\n";
$field_count = 0; $field_count = 0;
foreach ($row['fields'] as $field) { foreach ($row['fields'] as $field) {
if (isset($field['deprecated']) and ($field['deprecated'] == "true")) { if (isset($field['deprecated']) and ($field['deprecated'] == "true")) {
@@ -350,8 +350,8 @@ if (!class_exists('schema')) {
public function db_create_table ($apps, $db_type, $table) { public function db_create_table ($apps, $db_type, $table) {
if (is_array($apps)) foreach ($apps as $x => &$app) { if (is_array($apps)) foreach ($apps as $x => &$app) {
if (is_array($app['db'])) foreach ($app['db'] as $y => $row) { if (is_array($app['db'])) foreach ($app['db'] as $y => $row) {
if ($row['table'] == $table) { if ($row['table']['name'] == $table) {
$sql = "CREATE TABLE " . $row['table'] . " (\n"; $sql = "CREATE TABLE " . $row['table']['name'] . " (\n";
$field_count = 0; $field_count = 0;
if (is_array($row['fields'])) foreach ($row['fields'] as $field) { if (is_array($row['fields'])) foreach ($row['fields'] as $field) {
if ($field['deprecated'] == "true") { if ($field['deprecated'] == "true") {
@@ -389,8 +389,8 @@ if (!class_exists('schema')) {
global $db_name; global $db_name;
foreach ($apps as $x => &$app) { foreach ($apps as $x => &$app) {
foreach ($app['db'] as $y => $row) { foreach ($app['db'] as $y => $row) {
if ($row['table'] == $table) { if ($row['table']['name'] == $table) {
$sql = "INSERT INTO " . $row['table'] . " ("; $sql = "INSERT INTO " . $row['table']['name'] . " (";
$field_count = 0; $field_count = 0;
foreach ($row['fields'] as $field) { foreach ($row['fields'] as $field) {
if ($field['deprecated'] == "true") { if ($field['deprecated'] == "true") {
@@ -523,11 +523,22 @@ if (!class_exists('schema')) {
$sql = ''; $sql = '';
foreach ($apps as $x => &$app) { foreach ($apps as $x => &$app) {
if (isset($app['db'])) foreach ($app['db'] as $y => &$row) { if (isset($app['db'])) foreach ($app['db'] as $y => &$row) {
if (is_array($row['table'])) { if (isset($row['table']['name'])) {
$table_name = $row['table']['text']; if (is_array($row['table']['name'])) {
$table_name = $row['table']['name']['text'];
}
else {
$table_name = $row['table']['name'];
}
} }
else { else {
$table_name = $row['table']; //old array syntax
if (is_array($row['table'])) {
$table_name = $row['table']['text'];
}
else {
$table_name = $row['table'];
}
} }
if (strlen($table_name) > 0) { if (strlen($table_name) > 0) {
//check if the table exists //check if the table exists
@@ -574,25 +585,25 @@ if (!class_exists('schema')) {
//add missing tables and fields //add missing tables and fields
foreach ($apps as $x => &$app) { foreach ($apps as $x => &$app) {
if (isset($app['db'])) foreach ($app['db'] as $y => &$row) { if (isset($app['db'])) foreach ($app['db'] as $y => &$row) {
if (is_array($row['table'])) { if (is_array($row['table']['name'])) {
$table_name = $row['table']['text']; $table_name = $row['table']['name']['text'];
if (!$this->db_table_exists($db_type, $db_name, $row['table']['text'])) { if (!$this->db_table_exists($db_type, $db_name, $row['table']['name']['text'])) {
$row['exists'] = "true"; //testing $row['exists'] = "true"; //testing
//if (db_table_exists($db_type, $db_name, $row['table']['deprecated'])) { //if (db_table_exists($db_type, $db_name, $row['table']['name']['deprecated'])) {
if ($db_type == "pgsql") { if ($db_type == "pgsql") {
$sql_update .= "ALTER TABLE ".$row['table']['deprecated']." RENAME TO ".$row['table']['text'].";\n"; $sql_update .= "ALTER TABLE ".$row['table']['name']['deprecated']." RENAME TO ".$row['table']['name']['text'].";\n";
} }
if ($db_type == "mysql") { if ($db_type == "mysql") {
$sql_update .= "RENAME TABLE ".$row['table']['deprecated']." TO ".$row['table']['text'].";\n"; $sql_update .= "RENAME TABLE ".$row['table']['name']['deprecated']." TO ".$row['table']['name']['text'].";\n";
} }
if ($db_type == "sqlite") { if ($db_type == "sqlite") {
$sql_update .= "ALTER TABLE ".$row['table']['deprecated']." RENAME TO ".$row['table']['text'].";\n"; $sql_update .= "ALTER TABLE ".$row['table']['name']['deprecated']." RENAME TO ".$row['table']['name']['text'].";\n";
} }
//} //}
} }
} }
else { else {
$table_name = $row['table']; $table_name = $row['table']['name'];
} }
//check if the table exists //check if the table exists
if ($row['exists'] == "true") { if ($row['exists'] == "true") {
@@ -701,8 +712,8 @@ if (!class_exists('schema')) {
} }
else { else {
//create table //create table
if (!is_array($row['table'])) { if (!is_array($row['table']['name'])) {
$sql_update .= $this->db_create_table($apps, $db_type, $row['table']); $sql_update .= $this->db_create_table($apps, $db_type, $row['table']['name']);
} }
} }
} }
@@ -710,11 +721,11 @@ if (!class_exists('schema')) {
//rebuild and populate the table //rebuild and populate the table
foreach ($apps as $x => &$app) { foreach ($apps as $x => &$app) {
if (isset($app['db'])) foreach ($app['db'] as $y => &$row) { if (isset($app['db'])) foreach ($app['db'] as $y => &$row) {
if (is_array($row['table'])) { if (is_array($row['table']['name'])) {
$table_name = $row['table']['text']; $table_name = $row['table']['name']['text'];
} }
else { else {
$table_name = $row['table']; $table_name = $row['table']['name'];
} }
if ($row['rebuild'] == "true") { if ($row['rebuild'] == "true") {
if ($db_type == "sqlite") { if ($db_type == "sqlite") {
@@ -767,11 +778,11 @@ if (!class_exists('schema')) {
$sql = ''; $sql = '';
foreach ($apps as &$app) { foreach ($apps as &$app) {
if (isset($app['db'])) foreach ($app['db'] as $row) { if (isset($app['db'])) foreach ($app['db'] as $row) {
if (is_array($row['table'])) { if (is_array($row['table']['name'])) {
$table_name = $row['table']['text']; $table_name = $row['table']['name']['text'];
} }
else { else {
$table_name = $row['table']; $table_name = $row['table']['name'];
} }
$response .= "<tr>\n"; $response .= "<tr>\n";