Move database methods to static and document database class (#6474)

* Add new static method to created newly connected database object

* Document database class and clean up and document some of the methods.
This removes the methods that should not be in each instance and places
them in the single instance class as to occupy less resources and be
able to create database objects more efficiently.

* More docs & removed the ability to set any value within the object.

Co-authored-by: Tim Fry <tim@voipstratus.com>
This commit is contained in:
frytimo 2022-09-17 17:44:21 -04:00 committed by GitHub
parent 46e554e2fc
commit ba3b60b07b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 842 additions and 502 deletions

View File

@ -119,7 +119,7 @@ if (!class_exists('contacts')) {
$p = new permissions; $p = new permissions;
$database = new database; $database = new database;
foreach ($this->tables as $table) { foreach ($this->tables as $table) {
$p->add($database->singular($table).'_delete', 'temp'); $p->add(database::singular($table).'_delete', 'temp');
} }
//execute delete //execute delete
@ -132,7 +132,7 @@ if (!class_exists('contacts')) {
//revoke temp permissions //revoke temp permissions
$database = new database; $database = new database;
foreach ($this->tables as $table) { foreach ($this->tables as $table) {
$p->delete($database->singular($table).'_delete', 'temp'); $p->delete(database::singular($table).'_delete', 'temp');
} }
//set message //set message
@ -163,11 +163,11 @@ if (!class_exists('contacts')) {
$x = 0; $x = 0;
foreach ($records as $property_name => $properties) { foreach ($records as $property_name => $properties) {
$database = new database; $database = new database;
if (permission_exists($database->singular($property_name).'_delete')) { if (permission_exists(database::singular($property_name).'_delete')) {
if (is_array($properties) && @sizeof($properties) != 0) { if (is_array($properties) && @sizeof($properties) != 0) {
foreach ($properties as $property) { foreach ($properties as $property) {
if ($property['checked'] == 'true' && is_uuid($property['uuid'])) { if ($property['checked'] == 'true' && is_uuid($property['uuid'])) {
$array[$property_name][$x][$database->singular($property_name).'_uuid'] = $property['uuid']; $array[$property_name][$x][database::singular($property_name).'_uuid'] = $property['uuid'];
$array[$property_name][$x]['contact_uuid'] = $this->contact_uuid; $array[$property_name][$x]['contact_uuid'] = $this->contact_uuid;
$array[$property_name][$x]['domain_uuid'] = $_SESSION['domain_uuid']; $array[$property_name][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
$x++; $x++;

View File

@ -273,7 +273,8 @@
$database = new database; $database = new database;
$database->app_name = 'dialplans'; $database->app_name = 'dialplans';
$database->app_uuid = $app_uuid; $database->app_uuid = $app_uuid;
$database->uuid($dialplan_uuid); if ( strlen($dialplan_uuid)>0 )
$database->uuid($dialplan_uuid);
$database->save($array); $database->save($array);
unset($array); unset($array);

View File

@ -73,6 +73,7 @@ if (!class_exists('user_logs')) {
* add user_logs * add user_logs
*/ */
public static function add($result) { public static function add($result) {
$array = [];
//prepare the array //prepare the array
$array['user_logs'][0]["timestamp"] = 'now()'; $array['user_logs'][0]["timestamp"] = 'now()';
$array['user_logs'][0]["domain_uuid"] = $result['domain_uuid']; $array['user_logs'][0]["domain_uuid"] = $result['domain_uuid'];
@ -97,7 +98,8 @@ if (!class_exists('user_logs')) {
$database = new database; $database = new database;
$database->app_name = 'authentication'; $database->app_name = 'authentication';
$database->app_uuid = 'a8a12918-69a4-4ece-a1ae-3932be0e41f1'; $database->app_uuid = 'a8a12918-69a4-4ece-a1ae-3932be0e41f1';
$database->uuid($user_log_uuid); if (strlen($user_log_uuid)>0)
$database->uuid($user_log_uuid);
$database->save($array, false); $database->save($array, false);
$message = $database->message; $message = $database->message;

File diff suppressed because it is too large Load Diff