From d34d709e37a3270a3d58dbaa0e4856c0ab0f144d Mon Sep 17 00:00:00 2001 From: markjcrane Date: Thu, 14 Apr 2016 21:51:11 -0600 Subject: [PATCH] Schema use $this->$db instead of $db. --- .../resources/classes/install_fusionpbx.php | 1 + resources/classes/schema.php | 50 +++++++++---------- resources/switch.php | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/core/install/resources/classes/install_fusionpbx.php b/core/install/resources/classes/install_fusionpbx.php index d0c8adb998..54a16f76a0 100644 --- a/core/install/resources/classes/install_fusionpbx.php +++ b/core/install/resources/classes/install_fusionpbx.php @@ -836,6 +836,7 @@ include "root.php"; } protected function app_defaults() { + //write a progress message $this->write_progress("\tRunning app_defaults"); diff --git a/resources/classes/schema.php b/resources/classes/schema.php index 282d7dde05..dc04da9f8f 100644 --- a/resources/classes/schema.php +++ b/resources/classes/schema.php @@ -196,9 +196,9 @@ include "root.php"; } //database table exists alternate - private function db_table_exists_alternate ($db, $db_type, $table_name) { + private function db_table_exists_alternate ($db_type, $table_name) { $sql = "select count(*) from $table_name "; - $result = $db->query($sql); + $result = $this->db->query($sql); if ($result > 0) { return true; //table exists } @@ -208,7 +208,7 @@ include "root.php"; } //database table exists - private function db_table_exists ($db, $db_type, $db_name, $table_name) { + private function db_table_exists ($db_type, $db_name, $table_name) { $sql = ""; if ($db_type == "sqlite") { $sql .= "SELECT * FROM sqlite_master WHERE type='table' and name='$table_name' "; @@ -219,7 +219,7 @@ include "root.php"; if ($db_type == "mysql") { $sql .= "SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = '$db_name' and TABLE_NAME = '$table_name' "; } - $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (count($result) > 0) { @@ -231,7 +231,7 @@ include "root.php"; } //database table information - private function db_table_info($db, $db_name, $db_type, $table_name) { + private function db_table_info($db_name, $db_type, $table_name) { if (strlen($table_name) == 0) { return false; } if ($db_type == "sqlite") { $sql = "PRAGMA table_info(".$table_name.");"; @@ -252,7 +252,7 @@ include "root.php"; if ($db_type == "mysql") { $sql = "describe ".$table_name.";"; } - $prep_statement = $db->prepare($sql); + $prep_statement = $this->db->prepare($sql); $prep_statement->execute(); return $prep_statement->fetchAll(PDO::FETCH_ASSOC); } @@ -293,11 +293,11 @@ include "root.php"; } //database column exists - private function db_column_exists ($db, $db_type, $db_name, $table_name, $column_name) { + private function db_column_exists ($db_type, $db_name, $table_name, $column_name) { global $display_type; if ($db_type == "sqlite") { - $table_info = $this->db_table_info($db, $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)) { return true; } @@ -313,7 +313,7 @@ include "root.php"; $sql = "show columns from $table_name where field = '$column_name' "; } if ($sql) { - $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (!$result) { @@ -330,8 +330,8 @@ include "root.php"; } //database column data type - private function db_column_data_type ($db, $db_type, $db_name, $table_name, $column_name) { - $table_info = $this->db_table_info($db, $db_name, $db_type, $table_name); + private function db_column_data_type ($db_type, $db_name, $table_name, $column_name) { + $table_info = $this->db_table_info($db_name, $db_type, $table_name); return $this->db_data_type($db_type, $table_info, $column_name); } @@ -375,7 +375,7 @@ include "root.php"; //database insert private function db_insert_into ($apps, $db_type, $table) { - global $db, $db_name; + global $db_name; foreach ($apps as $x => &$app) { foreach ($app['db'] as $y => $row) { if ($row['table'] == $table) { @@ -410,7 +410,7 @@ include "root.php"; if (is_array($field['name']['deprecated'])) { $found = false; foreach ($field['name']['deprecated'] as $row) { - if ($this->db_column_exists ($db, $db_type, $db_name, 'tmp_'.$table, $row)) { + if ($this->db_column_exists ($db_type, $db_name, 'tmp_'.$table, $row)) { $sql .= $row; $found = true; break; @@ -419,7 +419,7 @@ include "root.php"; if (!$found) { $sql .= "''"; } } else { - if ($this->db_column_exists ($db, $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']; } else { @@ -448,7 +448,7 @@ include "root.php"; public function schema ($format) { //set the global variable - global $db, $upgrade_data_types, $text; + global $upgrade_data_types, $text; //get the db variables $config = new config; @@ -518,7 +518,7 @@ include "root.php"; } if (strlen($table_name) > 0) { //check if the table exists - if ($this->db_table_exists($db, $db_type, $db_name, $table_name)) { + if ($this->db_table_exists($db_type, $db_name, $table_name)) { $apps[$x]['db'][$y]['exists'] = 'true'; } else { @@ -537,7 +537,7 @@ include "root.php"; $field_name = $field['name']; } if (strlen(field_name) > 0) { - if ($this->db_column_exists ($db, $db_type, $db_name, $table_name, $field_name)) { + if ($this->db_column_exists ($db_type, $db_name, $table_name, $field_name)) { //found $apps[$x]['db'][$y]['fields'][$z]['exists'] = 'true'; } @@ -563,9 +563,9 @@ include "root.php"; foreach ($app['db'] as $y => &$row) { if (is_array($row['table'])) { $table_name = $row['table']['text']; - if (!$this->db_table_exists($db, $db_type, $db_name, $row['table']['text'])) { + if (!$this->db_table_exists($db_type, $db_name, $row['table']['text'])) { $row['exists'] = "true"; //testing - //if (db_table_exists($db, $db_type, $db_name, $row['table']['deprecated'])) { + //if (db_table_exists($db_type, $db_name, $row['table']['deprecated'])) { if ($db_type == "pgsql") { $sql_update .= "ALTER TABLE ".$row['table']['deprecated']." RENAME TO ".$row['table']['text'].";\n"; } @@ -616,7 +616,7 @@ include "root.php"; } //rename fields where the name has changed if (is_array($field['name'])) { - if ($this->db_column_exists ($db, $db_type, $db_name, $table_name, $field['name']['deprecated'])) { + 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"; } @@ -633,7 +633,7 @@ include "root.php"; //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 ($upgrade_data_types) { - $db_field_type = $this->db_column_data_type ($db, $db_type, $db_name, $table_name, $field_name); + $db_field_type = $this->db_column_data_type ($db_type, $db_name, $table_name, $field_name); $field_type_array = explode("(", $field_type); $field_type = $field_type_array[0]; if (trim($db_field_type) != trim($field_type) && strlen($db_field_type) > 0) { @@ -656,7 +656,7 @@ include "root.php"; //field type has not changed } else { - //$sql_update .= "-- $db_type, $db_name, $table_name, $field_name ".db_column_data_type ($db, $db_type, $db_name, $table_name, $field_name)."
"; + //$sql_update .= "-- $db_type, $db_name, $table_name, $field_name ".db_column_data_type ($db_type, $db_name, $table_name, $field_name)."
"; $sql_update .= "ALTER TABLE ".$table_name." ALTER COLUMN ".$field_name." TYPE ".$field_type.";\n"; } } @@ -836,12 +836,12 @@ include "root.php"; if ($format == "text") { $response .= " ".$text['label-schema']."\n"; } - //$db->beginTransaction(); + //$this->db->beginTransaction(); $update_array = explode(";", $sql_update); foreach($update_array as $sql) { if (strlen(trim($sql))) { try { - $db->query(trim($sql)); + $this->db->query(trim($sql)); if ($format == "text") { $response .= " $sql\n"; } @@ -851,7 +851,7 @@ include "root.php"; } } } - //$db->commit(); + //$this->db->commit(); $response .= "\n"; unset ($file_contents, $sql_update, $sql); } diff --git a/resources/switch.php b/resources/switch.php index c0c8dcf4af..835c32cb85 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -50,7 +50,7 @@ require_once "resources/require.php"; function load_extensions() { global $db; if (file_exists($_SERVER["PROJECT_ROOT"]."/app/extensions/app_config.php")) { - if (strlen($_SESSION["domain_uuid"]) > 0 && strlen($_SESSION["user_uuid"]) > 0 && count($_SESSION['user']['extension']) == 0) { + if ($db && strlen($_SESSION["domain_uuid"]) > 0 && strlen($_SESSION["user_uuid"]) > 0 && count($_SESSION['user']['extension']) == 0) { //get the user extension list unset($_SESSION['user']['extension']); $sql = "select ";