format schema class (#7145)

- format schema class using autoformat
This commit is contained in:
frytimo 2025-01-28 20:05:00 -04:00 committed by GitHub
parent 77f9161408
commit d6f9b25283
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 799 additions and 810 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
FusionPBX FusionPBX
Version: MPL 1.1 Version: MPL 1.1
@ -26,6 +27,7 @@
//define the schema class //define the schema class
if (!class_exists('schema')) { if (!class_exists('schema')) {
class schema { class schema {
//define variables //define variables
@ -50,8 +52,7 @@ if (!class_exists('schema')) {
foreach ($config_list as $config_path) { foreach ($config_list as $config_path) {
try { try {
include($config_path); include($config_path);
} } catch (Exception $e) {
catch (Exception $e) {
//echo 'Caught exception: ', $e->getMessage(), "\n"; //echo 'Caught exception: ', $e->getMessage(), "\n";
} }
$x++; $x++;
@ -73,19 +74,18 @@ if (!class_exists('schema')) {
foreach ($row['fields'] as $field) { foreach ($row['fields'] as $field) {
if (!empty($field['deprecated']) and ($field['deprecated'] == "true")) { if (!empty($field['deprecated']) and ($field['deprecated'] == "true")) {
//skip this field //skip this field
} else {
if ($field_count > 0) {
$sql .= ",\n";
} }
else {
if ($field_count > 0 ) { $sql .= ",\n"; }
if (is_array($field['name'])) { if (is_array($field['name'])) {
$sql .= $field['name']['text'] . " "; $sql .= $field['name']['text'] . " ";
} } else {
else {
$sql .= $field['name'] . " "; $sql .= $field['name'] . " ";
} }
if (is_array($field['type'])) { if (is_array($field['type'])) {
$sql .= $field['type'][$this->db_type]; $sql .= $field['type'][$this->db_type];
} } else {
else {
$sql .= $field['type']; $sql .= $field['type'];
} }
if (isset($field['key']) && isset($field['key']['type']) && ($field['key']['type'] == "primary")) { if (isset($field['key']) && isset($field['key']['type']) && ($field['key']['type'] == "primary")) {
@ -107,8 +107,7 @@ if (!class_exists('schema')) {
} }
if ($this->db_type == "mysql") { if ($this->db_type == "mysql") {
$sql .= ") ENGINE=INNODB;"; $sql .= ") ENGINE=INNODB;";
} } else {
else {
$sql .= ");"; $sql .= ");";
} }
$this->result['sql'][] = $sql; $this->result['sql'][] = $sql;
@ -126,8 +125,7 @@ if (!class_exists('schema')) {
//execute the sql query //execute the sql query
try { try {
$this->database->query($sql); $this->database->query($sql);
} } catch (PDOException $error) {
catch (PDOException $error) {
echo "error: " . $error->getMessage() . " sql: $sql<br/>"; echo "error: " . $error->getMessage() . " sql: $sql<br/>";
} }
//complete the transaction //complete the transaction
@ -152,8 +150,7 @@ if (!class_exists('schema')) {
$table_info = $this->table_info($db_name, $table_name); $table_info = $this->table_info($db_name, $table_name);
if ($this->sqlite_column_exists($table_info, $column_name)) { if ($this->sqlite_column_exists($table_info, $column_name)) {
return true; return true;
} } else {
else {
return false; return false;
} }
} }
@ -174,8 +171,7 @@ if (!class_exists('schema')) {
} }
if (count($result) > 0) { if (count($result) > 0) {
return true; return true;
} } else {
else {
return false; return false;
} }
unset($prep_statement); unset($prep_statement);
@ -184,7 +180,9 @@ if (!class_exists('schema')) {
//get the table information //get the table information
public function table_info($db_name, $table_name) { public function table_info($db_name, $table_name) {
if (empty($table_name)) { return false; } if (empty($table_name)) {
return false;
}
if ($this->db_type == "sqlite") { if ($this->db_type == "sqlite") {
$sql = "PRAGMA table_info(" . $table_name . ");"; $sql = "PRAGMA table_info(" . $table_name . ");";
} }
@ -215,8 +213,7 @@ if (!class_exists('schema')) {
$result = $this->database->query($sql); $result = $this->database->query($sql);
if ($result > 0) { if ($result > 0) {
return true; //table exists return true; //table exists
} } else {
else {
return false; //table doesn't exist return false; //table doesn't exist
} }
} }
@ -238,15 +235,16 @@ if (!class_exists('schema')) {
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) { if (count($result) > 0) {
return true; //table exists return true; //table exists
} } else {
else {
return false; //table doesn't exist return false; //table doesn't exist
} }
} }
//database table information //database table information
private function db_table_info($db_name, $db_type, $table_name) { private function db_table_info($db_name, $db_type, $table_name) {
if (empty($table_name)) { return false; } if (empty($table_name)) {
return false;
}
if ($db_type == "sqlite") { if ($db_type == "sqlite") {
$sql = "PRAGMA table_info(" . $table_name . ");"; $sql = "PRAGMA table_info(" . $table_name . ");";
} }
@ -313,8 +311,7 @@ if (!class_exists('schema')) {
$table_info = $this->db_table_info($db_name, $db_type, $table_name); $table_info = $this->db_table_info($db_name, $db_type, $table_name);
if ($this->db_sqlite_column_exists($table_info, $column_name)) { if ($this->db_sqlite_column_exists($table_info, $column_name)) {
return true; return true;
} } else {
else {
return false; return false;
} }
} }
@ -331,8 +328,7 @@ if (!class_exists('schema')) {
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (!empty($result)) { if (!empty($result)) {
return true; return true;
} } else {
else {
return false; return false;
} }
unset($prep_statement); unset($prep_statement);
@ -347,34 +343,37 @@ if (!class_exists('schema')) {
//database create table //database create table
public function db_create_table($apps, $db_type, $table) { public function db_create_table($apps, $db_type, $table) {
if (empty($apps)) { return false; } if (empty($apps)) {
if (is_array($apps)) foreach ($apps as $x => $app) { return false;
if (!empty($app['db']) && is_array($app['db'])) foreach ($app['db'] as $y => $row) { }
if (is_array($apps)) {
foreach ($apps as $x => $app) {
if (!empty($app['db']) && is_array($app['db'])) {
foreach ($app['db'] as $y => $row) {
if (!empty($row['table']['name']) && is_array($row['table']['name'])) { if (!empty($row['table']['name']) && is_array($row['table']['name'])) {
$table_name = $row['table']['name']['text']; $table_name = $row['table']['name']['text'];
} } else {
else {
$table_name = $row['table']['name']; $table_name = $row['table']['name'];
} }
if ($table_name == $table) { if ($table_name == $table) {
$sql = "CREATE TABLE " . $table_name . " (\n"; $sql = "CREATE TABLE " . $table_name . " (\n";
(int) $field_count = 0; (int) $field_count = 0;
if (!empty($row['fields']) && is_array($row['fields'])) foreach ($row['fields'] as $field) { if (!empty($row['fields']) && is_array($row['fields'])) {
foreach ($row['fields'] as $field) {
if (!empty($field['deprecated']) && $field['deprecated'] == "true") { if (!empty($field['deprecated']) && $field['deprecated'] == "true") {
//skip this row //skip this row
} else {
if ($field_count > 0) {
$sql .= ",\n";
} }
else {
if ($field_count > 0 ) { $sql .= ",\n"; }
if (!empty($field['name']) && is_array($field['name'])) { if (!empty($field['name']) && is_array($field['name'])) {
$sql .= $field['name']['text'] . " "; $sql .= $field['name']['text'] . " ";
} } else {
else {
$sql .= $field['name'] . " "; $sql .= $field['name'] . " ";
} }
if (!empty($field['type']) && is_array($field['type'])) { if (!empty($field['type']) && is_array($field['type'])) {
$sql .= $field['type'][$db_type]; $sql .= $field['type'][$db_type];
} } else {
else {
$sql .= $field['type']; $sql .= $field['type'];
} }
if (!empty($field['key']['type']) && $field['key']['type'] == "primary") { if (!empty($field['key']['type']) && $field['key']['type'] == "primary") {
@ -383,12 +382,15 @@ if (!class_exists('schema')) {
$field_count++; $field_count++;
} }
} }
}
$sql .= ");\n"; $sql .= ");\n";
return $sql; return $sql;
} }
} }
} }
} }
}
}
//database insert //database insert
private function db_insert_into($apps, $db_type, $table) { private function db_insert_into($apps, $db_type, $table) {
@ -401,13 +403,13 @@ if (!class_exists('schema')) {
foreach ($row['fields'] as $field) { foreach ($row['fields'] as $field) {
if (!empty($field['deprecated']) && $field['deprecated'] == "true") { if (!empty($field['deprecated']) && $field['deprecated'] == "true") {
//skip this field //skip this field
} else {
if ($field_count > 0) {
$sql .= ",";
} }
else {
if ($field_count > 0 ) { $sql .= ","; }
if (is_array($field['name'])) { if (is_array($field['name'])) {
$sql .= $field['name']['text']; $sql .= $field['name']['text'];
} } else {
else {
$sql .= $field['name']; $sql .= $field['name'];
} }
$field_count++; $field_count++;
@ -419,9 +421,10 @@ if (!class_exists('schema')) {
foreach ($row['fields'] as $field) { foreach ($row['fields'] as $field) {
if (!empty($field['deprecated']) && $field['deprecated'] == "true") { if (!empty($field['deprecated']) && $field['deprecated'] == "true") {
//skip this field //skip this field
} else {
if ($field_count > 0) {
$sql .= ",";
} }
else {
if ($field_count > 0 ) { $sql .= ","; }
if (is_array($field['name'])) { if (is_array($field['name'])) {
if ($field['exists'] == "false") { if ($field['exists'] == "false") {
if (is_array($field['name']['deprecated'])) { if (is_array($field['name']['deprecated'])) {
@ -433,22 +436,20 @@ if (!class_exists('schema')) {
break; break;
} }
} }
if (!$found) { $sql .= "''"; } if (!$found) {
$sql .= "''";
} }
else { } else {
if ($this->db_column_exists($db_type, $db_name, 'tmp_' . $table, $field['name']['deprecated'])) { if ($this->db_column_exists($db_type, $db_name, 'tmp_' . $table, $field['name']['deprecated'])) {
$sql .= $field['name']['deprecated']; $sql .= $field['name']['deprecated'];
} } else {
else {
$sql .= "''"; $sql .= "''";
} }
} }
} } else {
else {
$sql .= $field['name']['text']; $sql .= $field['name']['text'];
} }
} } else {
else {
$sql .= $field['name']; $sql .= $field['name'];
} }
$field_count++; $field_count++;
@ -467,7 +468,9 @@ if (!class_exists('schema')) {
//set the global variable //set the global variable
global $text, $output_format; global $text, $output_format;
if ($format == '') $format = $output_format; if ($format == '') {
$format = $output_format;
}
//get the db variables //get the db variables
//require_once "resources/classes/config.php"; //require_once "resources/classes/config.php";
@ -482,7 +485,6 @@ if (!class_exists('schema')) {
//$db_host = $config->db_host; //$db_host = $config->db_host;
//$db_path = $config->db_path; //$db_path = $config->db_path;
//$db_port = $config->db_port; //$db_port = $config->db_port;
//includes files //includes files
require dirname(__DIR__, 2) . "/resources/require.php"; require dirname(__DIR__, 2) . "/resources/require.php";
@ -499,7 +501,6 @@ if (!class_exists('schema')) {
// SELECT * FROM sqlite_master WHERE type='table' AND name='v_cdr' AND sql LIKE '%caller_id_name TEXT,%' // SELECT * FROM sqlite_master WHERE type='table' AND name='v_cdr' AND sql LIKE '%caller_id_name TEXT,%'
//aditional information //aditional information
// http://www.sqlite.org/faq.html#q9 // http://www.sqlite.org/faq.html#q9
//postgresql //postgresql
//list all tables in the database //list all tables in the database
// SELECT table_name FROM pg_tables WHERE schemaname='public'; // SELECT table_name FROM pg_tables WHERE schemaname='public';
@ -517,25 +518,22 @@ if (!class_exists('schema')) {
//oracle //oracle
//check if table exists //check if table exists
// SELECT TABLE_NAME FROM ALL_TABLES // SELECT TABLE_NAME FROM ALL_TABLES
//update the app db array add exists true or false //update the app db array add exists true or false
$sql = ''; $sql = '';
foreach ($this->apps as $x => $app) { foreach ($this->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 (isset($row['table']['name'])) { if (isset($row['table']['name'])) {
if (is_array($row['table']['name'])) { if (is_array($row['table']['name'])) {
$table_name = $row['table']['name']['text']; $table_name = $row['table']['name']['text'];
} } else {
else {
$table_name = $row['table']['name']; $table_name = $row['table']['name'];
} }
} } else {
else {
//old array syntax //old array syntax
if (is_array($row['table'])) { if (is_array($row['table'])) {
$table_name = $row['table']['text']; $table_name = $row['table']['text'];
} } else {
else {
$table_name = $row['table']; $table_name = $row['table'];
} }
} }
@ -544,28 +542,24 @@ if (!class_exists('schema')) {
//check if the table exists //check if the table exists
if ($this->db_table_exists($db_type, $db_name, $table_name)) { if ($this->db_table_exists($db_type, $db_name, $table_name)) {
$this->apps[$x]['db'][$y]['exists'] = 'true'; $this->apps[$x]['db'][$y]['exists'] = 'true';
} } else {
else {
$this->apps[$x]['db'][$y]['exists'] = 'false'; $this->apps[$x]['db'][$y]['exists'] = 'false';
} }
//check if the column exists //check if the column exists
foreach ($row['fields'] as $z => $field) { foreach ($row['fields'] as $z => $field) {
if (!empty($field['deprecated']) && $field['deprecated'] == "true") { if (!empty($field['deprecated']) && $field['deprecated'] == "true") {
//skip this field //skip this field
} } else {
else {
if (is_array($field['name'])) { if (is_array($field['name'])) {
$field_name = $field['name']['text']; $field_name = $field['name']['text'];
} } else {
else {
$field_name = $field['name']; $field_name = $field['name'];
} }
if (!empty($field_name)) { if (!empty($field_name)) {
if ($this->db_column_exists($db_type, $db_name, $table_name, $field_name)) { if ($this->db_column_exists($db_type, $db_name, $table_name, $field_name)) {
//found //found
$this->apps[$x]['db'][$y]['fields'][$z]['exists'] = 'true'; $this->apps[$x]['db'][$y]['fields'][$z]['exists'] = 'true';
} } else {
else {
//not found //not found
$this->apps[$x]['db'][$y]['fields'][$z]['exists'] = 'false'; $this->apps[$x]['db'][$y]['fields'][$z]['exists'] = 'false';
} }
@ -577,13 +571,15 @@ if (!class_exists('schema')) {
} }
} }
} }
}
//prepare the variables //prepare the variables
$sql_update = ''; $sql_update = '';
//add missing tables and fields //add missing tables and fields
foreach ($this->apps as $x => $app) { foreach ($this->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']['name'])) { if (is_array($row['table']['name'])) {
$table_name = $row['table']['name']['text']; $table_name = $row['table']['name']['text'];
if ($this->db_table_exists($db_type, $db_name, $row['table']['name']['deprecated'])) { if ($this->db_table_exists($db_type, $db_name, $row['table']['name']['deprecated'])) {
@ -597,22 +593,18 @@ if (!class_exists('schema')) {
if ($db_type == "sqlite") { if ($db_type == "sqlite") {
$sql_update .= "ALTER TABLE " . $row['table']['name']['deprecated'] . " RENAME TO " . $row['table']['name']['text'] . ";\n"; $sql_update .= "ALTER TABLE " . $row['table']['name']['deprecated'] . " RENAME TO " . $row['table']['name']['text'] . ";\n";
} }
} } else {
else {
if ($this->db_table_exists($db_type, $db_name, $row['table']['name']['text'])) { if ($this->db_table_exists($db_type, $db_name, $row['table']['name']['text'])) {
$row['exists'] = "true"; $row['exists'] = "true";
} } else {
else {
$row['exists'] = "false"; $row['exists'] = "false";
$sql_update .= $this->db_create_table($this->apps, $db_type, $row['table']['name']['text']); $sql_update .= $this->db_create_table($this->apps, $db_type, $row['table']['name']['text']);
} }
} }
} } else {
else {
if ($this->db_table_exists($db_type, $db_name, $row['table']['name'])) { if ($this->db_table_exists($db_type, $db_name, $row['table']['name'])) {
$row['exists'] = "true"; $row['exists'] = "true";
} } else {
else {
$row['exists'] = "false"; $row['exists'] = "false";
} }
$table_name = $row['table']['name']; $table_name = $row['table']['name'];
@ -624,20 +616,17 @@ if (!class_exists('schema')) {
foreach ($row['fields'] as $z => $field) { foreach ($row['fields'] as $z => $field) {
if (!empty($field['deprecated']) && $field['deprecated'] == "true") { if (!empty($field['deprecated']) && $field['deprecated'] == "true") {
//skip this field //skip this field
} } else {
else {
//get the data type //get the data type
if (is_array($field['type'])) { if (is_array($field['type'])) {
$field_type = $field['type'][$db_type]; $field_type = $field['type'][$db_type];
} } else {
else {
$field_type = $field['type']; $field_type = $field['type'];
} }
//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'];
} } else {
else {
$field_name = $field['name']; $field_name = $field['name'];
} }
@ -648,7 +637,6 @@ if (!class_exists('schema')) {
// else { // else {
// $field['exists'] = "false"; // $field['exists'] = "false";
// } // }
//add or rename fields //add or rename fields
if (isset($field['name']['deprecated']) && $this->db_column_exists($db_type, $db_name, $table_name, $field['name']['deprecated'])) { if (isset($field['name']['deprecated']) && $this->db_column_exists($db_type, $db_name, $table_name, $field['name']['deprecated'])) {
if ($db_type == "pgsql") { if ($db_type == "pgsql") {
@ -662,8 +650,7 @@ if (!class_exists('schema')) {
//a change has been made to the field name //a change has been made to the field name
$this->apps[$x]['db'][$y]['rebuild'] = 'true'; $this->apps[$x]['db'][$y]['rebuild'] = 'true';
} }
} } else {
else {
//find missing fields and add them //find missing fields and add them
if ($field['exists'] == "false") { if ($field['exists'] == "false") {
$sql_update .= "ALTER TABLE " . $table_name . " ADD " . $field_name . " " . $field_type . ";\n"; $sql_update .= "ALTER TABLE " . $table_name . " ADD " . $field_name . " " . $field_type . ";\n";
@ -682,23 +669,33 @@ if (!class_exists('schema')) {
$sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE uuid USING\n"; $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE uuid USING\n";
$sql_update .= "CAST(regexp_replace(" . $field_name . ", '([A-Z0-9]{4})([A-Z0-9]{12})', E'\\1-\\2')\n"; $sql_update .= "CAST(regexp_replace(" . $field_name . ", '([A-Z0-9]{4})([A-Z0-9]{12})', E'\\1-\\2')\n";
$sql_update .= "AS uuid);\n"; $sql_update .= "AS uuid);\n";
} } else {
else {
//field type has not changed //field type has not changed
if ($db_field_type == "integer" && strtolower($field_type) == "serial") { } if ($db_field_type == "integer" && strtolower($field_type) == "serial") {
else if ($db_field_type == "timestamp without time zone" && strtolower($field_type) == "timestamp") { }
else if ($db_field_type == "timestamp without time zone" && strtolower($field_type) == "datetime") { } } else if ($db_field_type == "timestamp without time zone" && strtolower($field_type) == "timestamp") {
else if ($db_field_type == "timestamp with time zone" && strtolower($field_type) == "timestamptz") { }
else if ($db_field_type == "integer" && strtolower($field_type) == "numeric") { } } else if ($db_field_type == "timestamp without time zone" && strtolower($field_type) == "datetime") {
else if ($db_field_type == "character" && strtolower($field_type) == "char") { }
} else if ($db_field_type == "timestamp with time zone" && strtolower($field_type) == "timestamptz") {
} else if ($db_field_type == "integer" && strtolower($field_type) == "numeric") {
} else if ($db_field_type == "character" && strtolower($field_type) == "char") {
}
//field type has changed //field type has changed
else { else {
switch ($field_type) { switch ($field_type) {
case 'numeric': $using = $field_name."::numeric"; break; case 'numeric': $using = $field_name . "::numeric";
break;
case 'timestamp': case 'timestamp':
case 'datetime': $using = $field_name."::timestamp without time zone"; break; case 'datetime': $using = $field_name . "::timestamp without time zone";
case 'timestamptz': $using = $field_name."::timestamp with time zone"; break; break;
case 'boolean': $using = $field_name."::boolean"; break; case 'timestamptz': $using = $field_name . "::timestamp with time zone";
break;
case 'boolean': $using = $field_name . "::boolean";
break;
default: unset($using); default: unset($using);
} }
$sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " " . ($using ? "USING " . $using : null) . ";\n"; $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " " . ($using ? "USING " . $using : null) . ";\n";
@ -709,11 +706,9 @@ if (!class_exists('schema')) {
$type = explode("(", $db_field_type); $type = explode("(", $db_field_type);
if ($type[0] == $field_type) { if ($type[0] == $field_type) {
//do nothing //do nothing
} } else if ($field_type == "numeric" && $type[0] == "decimal") {
else if ($field_type == "numeric" && $type[0] == "decimal") {
//do nothing //do nothing
} } else {
else {
$sql_update .= "ALTER TABLE " . $table_name . " modify " . $field_name . " " . $field_type . ";\n"; $sql_update .= "ALTER TABLE " . $table_name . " modify " . $field_name . " " . $field_type . ";\n";
} }
unset($type); unset($type);
@ -727,20 +722,20 @@ if (!class_exists('schema')) {
} }
} }
} }
} } elseif (!is_array($row['table']['name'])) {
elseif (!is_array($row['table']['name'])) {
//create table //create table
$sql_update .= $this->db_create_table($this->apps, $db_type, $row['table']['name']); $sql_update .= $this->db_create_table($this->apps, $db_type, $row['table']['name']);
} }
} }
} }
}
//rebuild and populate the table //rebuild and populate the table
foreach ($this->apps as $x => $app) { foreach ($this->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']['name'])) { if (is_array($row['table']['name'])) {
$table_name = $row['table']['name']['text']; $table_name = $row['table']['name']['text'];
} } else {
else {
$table_name = $row['table']['name']; $table_name = $row['table']['name'];
} }
if (!empty($field['rebuild']) && $row['rebuild'] == "true") { if (!empty($field['rebuild']) && $row['rebuild'] == "true") {
@ -761,6 +756,7 @@ if (!class_exists('schema')) {
} }
} }
} }
}
// initialize response variable // initialize response variable
$response = ''; $response = '';
@ -793,11 +789,11 @@ if (!class_exists('schema')) {
//build the html while looping through the app db array //build the html while looping through the app db array
$sql = ''; $sql = '';
foreach ($this->apps as $app) { foreach ($this->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']['name'])) { if (is_array($row['table']['name'])) {
$table_name = $row['table']['name']['text']; $table_name = $row['table']['name']['text'];
} } else {
else {
$table_name = $row['table']['name']; $table_name = $row['table']['name'];
} }
$response .= "<tr>\n"; $response .= "<tr>\n";
@ -819,18 +815,15 @@ if (!class_exists('schema')) {
foreach ($row['fields'] as $field) { foreach ($row['fields'] as $field) {
if (!empty($field['deprecated']) && $field['deprecated'] == "true") { if (!empty($field['deprecated']) && $field['deprecated'] == "true") {
//skip this field //skip this field
} } else {
else {
if (is_array($field['name'])) { if (is_array($field['name'])) {
$field_name = $field['name']['text']; $field_name = $field['name']['text'];
} } else {
else {
$field_name = $field['name']; $field_name = $field['name'];
} }
if (is_array($field['type'])) { if (is_array($field['type'])) {
$field_type = $field['type'][$db_type]; $field_type = $field['type'][$db_type];
} } else {
else {
$field_type = $field['type']; $field_type = $field['type'];
} }
$response .= "<tr>\n"; $response .= "<tr>\n";
@ -839,8 +832,7 @@ if (!class_exists('schema')) {
if ($field['exists'] == "true") { if ($field['exists'] == "true") {
$response .= "<td class='row_style0' style=''>" . $text['option-true'] . "</td>\n"; $response .= "<td class='row_style0' style=''>" . $text['option-true'] . "</td>\n";
$response .= "<td>&nbsp;</td>\n"; $response .= "<td>&nbsp;</td>\n";
} } else {
else {
$response .= "<td class='row_style1' style='background-color:#444444;color:#CCCCCC;'>" . $text['option-false'] . "</td>\n"; $response .= "<td class='row_style1' style='background-color:#444444;color:#CCCCCC;'>" . $text['option-false'] . "</td>\n";
$response .= "<td>&nbsp;</td>\n"; $response .= "<td>&nbsp;</td>\n";
} }
@ -850,8 +842,7 @@ if (!class_exists('schema')) {
$response .= " </table>\n"; $response .= " </table>\n";
$response .= "</td>\n"; $response .= "</td>\n";
} }
} } else {
else {
$response .= "<td valign='top' class='row_style1'>$table_name</td>\n"; $response .= "<td valign='top' class='row_style1'>$table_name</td>\n";
$response .= "<td valign='top' class='row_style1' style='background-color:#444444;color:#CCCCCC;'><strong>" . $text['label-exists'] . "</strong><br />" . $text['option-false'] . "</td>\n"; $response .= "<td valign='top' class='row_style1' style='background-color:#444444;color:#CCCCCC;'><strong>" . $text['label-exists'] . "</strong><br />" . $text['option-false'] . "</td>\n";
$response .= "<td valign='top' class='row_style1'>&nbsp;</td>\n"; $response .= "<td valign='top' class='row_style1'>&nbsp;</td>\n";
@ -859,18 +850,17 @@ if (!class_exists('schema')) {
$response .= "</tr>\n"; $response .= "</tr>\n";
} }
} }
}
//end the list of tables //end the list of tables
$response .= "</table>\n"; $response .= "</table>\n";
$response .= "<br />\n"; $response .= "<br />\n";
} }
//loop line by line through all the lines of sql code //loop line by line through all the lines of sql code
$x = 0; $x = 0;
if (empty($sql_update) && $format == "text") { if (empty($sql_update) && $format == "text") {
$response .= " " . $text['label-schema'] . ": " . $text['label-no_change'] . "\n"; $response .= " " . $text['label-schema'] . ": " . $text['label-no_change'] . "\n";
} } else {
else {
if ($format == "text") { if ($format == "text") {
$response .= " " . $text['label-schema'] . "\n"; $response .= " " . $text['label-schema'] . "\n";
} }
@ -883,8 +873,7 @@ if (!class_exists('schema')) {
if ($format == "text") { if ($format == "text") {
$response .= " $sql;\n"; $response .= " $sql;\n";
} }
} } catch (PDOException $error) {
catch (PDOException $error) {
$response .= " error: " . $error->getMessage() . " sql: $sql\n"; $response .= " error: " . $error->getMessage() . " sql: $sql\n";
} }
} }
@ -918,6 +907,7 @@ if (!class_exists('schema')) {
//} //}
} //end function } //end function
} }
} }
//example use //example use
@ -927,5 +917,4 @@ if (!class_exists('schema')) {
//$obj->schema(); //$obj->schema();
//$result_array = $schema->obj['sql']; //$result_array = $schema->obj['sql'];
//print_r($result_array); //print_r($result_array);
?> ?>