Add a few minor changes for code consistency.

This commit is contained in:
FusionPBX 2022-09-18 02:13:33 -06:00 committed by GitHub
parent 5485764c08
commit 2ff62f638b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 1 deletions

View File

@ -38,12 +38,14 @@ include "root.php";
* @var PDO object * @var PDO object
*/ */
private $db; private $db;
/** /**
* Driver to use. * Driver to use.
* @access private * @access private
* @var string Can be pgsql, mysql, sqlite, odbc * @var string Can be pgsql, mysql, sqlite, odbc
*/ */
private $driver; private $driver;
/** /**
* Alias of driver. * Alias of driver.
* @access private * @access private
@ -51,60 +53,70 @@ include "root.php";
* @see $driver * @see $driver
*/ */
private $type; private $type;
/** /**
* Host for database connection * Host for database connection
* @access private * @access private
* @var string host name or IP address. * @var string host name or IP address.
*/ */
private $host; private $host;
/** /**
* Port number * Port number
* @access private * @access private
* @var int 1025 - 65534 * @var int 1025 - 65534
*/ */
private $port; private $port;
/** /**
* Database name * Database name
* @access private * @access private
* @var string * @var string
*/ */
private $db_name; private $db_name;
/** /**
* Database security * Database security
* @access private * @access private
* @var boolean * @var boolean
*/ */
private $db_secure; private $db_secure;
/** /**
* Specifies the file name of the client SSL certificate * Specifies the file name of the client SSL certificate
* @access private * @access private
* @var string full path * @var string full path
*/ */
private $db_cert_authority; private $db_cert_authority;
/** /**
* Username used to connect * Username used to connect
* @access private * @access private
* @var string * @var string
*/ */
private $username; private $username;
/** /**
* Password used to connect * Password used to connect
* @access private * @access private
* @var string * @var string
*/ */
private $password; private $password;
/** /**
* Full path to file name. * Full path to file name.
* @access private * @access private
* @var string full path to file name * @var string full path to file name
*/ */
private $path; private $path;
/** /**
* Table name. * Table name.
* @access private * @access private
* @var string sanitized * @var string sanitized
*/ */
private $table; private $table;
/** /**
* Where clause(s) of an SQL statement. * Where clause(s) of an SQL statement.
* <p>Array of arrays must be passed with each having the * <p>Array of arrays must be passed with each having the
@ -123,6 +135,7 @@ include "root.php";
* @see $order_by * @see $order_by
*/ */
private $where; //array private $where; //array
/** /**
* Order By clause(s) of an SQL statement. * Order By clause(s) of an SQL statement.
* <p>Array of arrays must be passed with each having the * <p>Array of arrays must be passed with each having the
@ -141,24 +154,28 @@ include "root.php";
* @see $where * @see $where
*/ */
private $order_by; //array private $order_by; //array
/** /**
* Ascending or Descending order. * Ascending or Descending order.
* @var string * @var string
* @access private * @access private
*/ */
private $order_type; private $order_type;
/** /**
* Numerical value to limit returned results. * Numerical value to limit returned results.
* @var int Used for 'LIMIT' in SQL statement. * @var int Used for 'LIMIT' in SQL statement.
* @access private * @access private
*/ */
private $limit; private $limit;
/** /**
* Numerical value to offset returned results. * Numerical value to offset returned results.
* @var int Used for 'OFFSET' in SQL statement. * @var int Used for 'OFFSET' in SQL statement.
* @access private * @access private
*/ */
private $offset; private $offset;
/** /**
* <p>Array of fields.</p> * <p>Array of fields.</p>
* <p>Fields are specified in 'name'=>'value' format. * <p>Fields are specified in 'name'=>'value' format.
@ -169,24 +186,28 @@ include "root.php";
* @see database::update() * @see database::update()
*/ */
private $fields; private $fields;
/** /**
* Unknown property * Unknown property
* @var unknown * @var unknown
* @access private * @access private
*/ */
private $count; private $count;
/** /**
* Unknown property * Unknown property
* @var unknown * @var unknown
* @access private * @access private
*/ */
private $sql; private $sql;
/** /**
* <p>Stores the result from the most recent query. The type will be based on what was requested.</p> * <p>Stores the result from the most recent query. The type will be based on what was requested.</p>
* <p><b>NOTE:</b> If an error occurred on the last query the result is set to an empty string.</p> * <p><b>NOTE:</b> If an error occurred on the last query the result is set to an empty string.</p>
* @var mixed * @var mixed
*/ */
private $result; private $result;
/** /**
* Stores the application name making the request. * Stores the application name making the request.
* @var string App name making database request. * @var string App name making database request.
@ -194,6 +215,7 @@ include "root.php";
* @access private * @access private
*/ */
private $app_name; private $app_name;
/** /**
* Stores the application UUID making the request. * Stores the application UUID making the request.
* @var string * @var string
@ -201,6 +223,7 @@ include "root.php";
* @access private * @access private
*/ */
private $app_uuid; private $app_uuid;
/** /**
* <p>Stores the domain UUID making the request.</p> * <p>Stores the domain UUID making the request.</p>
* <p>This is defaulted to the Session domain UUID.</p> * <p>This is defaulted to the Session domain UUID.</p>
@ -610,6 +633,7 @@ include "root.php";
} }
$prep_statement = $this->db->prepare($sql); $prep_statement = $this->db->prepare($sql);
$prep_statement->execute(); $prep_statement->execute();
//set the result array //set the result array
return $prep_statement->fetchAll(PDO::FETCH_ASSOC); return $prep_statement->fetchAll(PDO::FETCH_ASSOC);
} }
@ -628,6 +652,7 @@ include "root.php";
trigger_error('Table Name must be sanitized', E_USER_WARNING); trigger_error('Table Name must be sanitized', E_USER_WARNING);
return false; return false;
} }
//connect to the database if needed //connect to the database if needed
if (!$this->db) { if (!$this->db) {
$this->connect(); $this->connect();
@ -666,7 +691,10 @@ include "root.php";
//public $type; //public $type;
//public $table; //public $table;
//public $name; //public $name;
//initialize the array
$result = []; $result = [];
//get the table info //get the table info
$table_info = $this->table_info(); $table_info = $this->table_info();
@ -883,10 +911,13 @@ include "root.php";
if (!$this->db) { if (!$this->db) {
$this->connect(); $this->connect();
} }
//sanitize the table name //sanitize the table name
//$this->table = self::sanitize($this->table); // no longer needed //$this->table = self::sanitize($this->table); // no longer needed
//count the fields //count the fields
$field_count = count($this->fields); $field_count = count($this->fields);
//add data to the database //add data to the database
$sql = "insert into ".$this->table; $sql = "insert into ".$this->table;
$sql .= " ("; $sql .= " (";
@ -968,8 +999,10 @@ include "root.php";
if (!$this->db) { if (!$this->db) {
$this->connect(); $this->connect();
} }
//sanitize the table name //sanitize the table name
//$this->table = self::sanitize($this->table); // no longer needed //$this->table = self::sanitize($this->table); // no longer needed
//udate the database //udate the database
$sql = "update ".$this->table." set "; $sql = "update ".$this->table." set ";
$i = 1; $i = 1;
@ -1047,7 +1080,9 @@ include "root.php";
} }
public function delete(array $array) { public function delete(array $array) {
//set the default value
$retval = true; $retval = true;
//return the array //return the array
if (!is_array($array)) { return false; } if (!is_array($array)) { return false; }
@ -1381,6 +1416,7 @@ include "root.php";
if (!$this->db) { if (!$this->db) {
$this->connect(); $this->connect();
} }
//sanitize the table name //sanitize the table name
//$this->table = self::sanitize($this->table); // no longer needed //$this->table = self::sanitize($this->table); // no longer needed
@ -1516,14 +1552,17 @@ include "root.php";
if (!$this->db) { if (!$this->db) {
$this->connect(); $this->connect();
} }
//set the name //set the name
if (isset($array['name'])) { if (isset($array['name'])) {
$this->name = $array['name']; $this->name = $array['name'];
} }
//set the uuid //set the uuid
if (isset($array['uuid'])) { if (isset($array['uuid'])) {
$this->uuid = $array['uuid']; $this->uuid = $array['uuid'];
} }
//build the query //build the query
$sql = "SELECT * FROM ".self::TABLE_PREFIX . $this->name . " "; $sql = "SELECT * FROM ".self::TABLE_PREFIX . $this->name . " ";
if (isset($this->uuid)) { if (isset($this->uuid)) {
@ -1661,7 +1700,6 @@ include "root.php";
unset($array[$parent_name][$x]); unset($array[$parent_name][$x]);
//loop through the fields //loop through the fields
foreach($row as $field_name => $field_value) { foreach($row as $field_name => $field_value) {
//find the child tables //find the child tables
if (is_array($field_value)) { if (is_array($field_value)) {