Define app_name and app_uuid as constants (#7534)

* Set a constant on each class for app_name and app_uuid
* Update the database class to use the app_uuid and app_name
* Update the classes to use the database::new()
* Remove the instances of 'new database'
This commit is contained in:
FusionPBX
2025-09-30 21:37:09 -06:00
committed by GitHub
parent 6485b18822
commit 2fe8b65988
69 changed files with 2571 additions and 2809 deletions

View File

@@ -1291,6 +1291,14 @@ class database {
$x = 0;
foreach ($array as $parent_name => $tables) {
if (is_array($tables)) {
//get the application name and uuid
if (class_exists($parent_name) && defined("$parent_name::$app_name")) {
$this->app_name = $parent_name::app_name;
$this->app_uuid = $parent_name::app_uuid;
}
//process the array
foreach ($tables as $id => $row) {
//prepare the variables
@@ -1454,7 +1462,13 @@ class database {
//delete the current data
foreach($new_array as $table_name => $rows) {
//echo "table: ".$table_name."\n";
//get the application name and uuid
if (class_exists($parent_name)) {
$this->app_name = $table_name::app_name;
$this->app_uuid = $table_name::app_uuid;
}
//build and run the delete SQL statements
foreach($rows as $row) {
if (permission_exists(self::singular($table_name).'_delete')) {
$sql = "delete from ".self::TABLE_PREFIX.$table_name." ";
@@ -2228,7 +2242,7 @@ class database {
/**
* <p>Save an array to the database.</p>
* <p>Usage Example:<br><code>$database = new database();<br>$database->app_name = "MyApp";<br>$database->app_uuid = "12345678-1234-1234-1234-123456789abc";<br>$row = 0;<br>$array['mytable'][$row]['mycolumn'] = "myvalue";<br>if ($database->save($array)) { <br>&nbsp;&nbsp;echo "Saved Successfully.";<br> } else {<br>&nbsp;&nbsp;echo "Save Failed.";<br>}</code></p>
* <p>Usage Example:<br><code><br>$row = 0;<br>$array['mytable'][$row]['mycolumn'] = "myvalue";<br>if ($database->save($array)) { <br>&nbsp;&nbsp;echo "Saved Successfully.";<br> } else {<br>&nbsp;&nbsp;echo "Save Failed.";<br>}</code></p>
* @param array $array Three dimensional Array. The first dimension is the table name without the prefix 'v_'. Second dimension in the row value as int. Third dimension is the column name.
* @param bool $transaction_save
* @return returns and array wih result details
@@ -2273,6 +2287,13 @@ class database {
//loop through the array
if (is_array($array)) foreach ($array as $parent_name => $parent_array) {
//get the application name and uuid
if (class_exists($parent_name) && defined("$parent_name::$app_name")) {
$this->app_name = $parent_name::app_name;
$this->app_uuid = $parent_name::app_uuid;
}
//process the parent array, use it to create insert and update SQL statements
if (is_array($parent_array)) foreach ($parent_array as $row_id => $parent_field_array) {
//set the variables
@@ -3628,7 +3649,6 @@ class database {
/*
//example usage
//find
$database = new database;
$database->domain_uuid = $_SESSION["domain_uuid"];
$database->type = $db_type;
$database->table = "v_extensions";
@@ -3644,7 +3664,6 @@ class database {
$database->find();
print_r($database->result);
//insert
$database = new database;
$database->domain_uuid = $_SESSION["domain_uuid"];
$database->table = "v_ivr_menus";
$fields[0]['name'] = 'domain_uuid';

View File

@@ -26,6 +26,10 @@
//define the directory class
class switch_directory {
/**
* declare public variables
*/
public $domain_uuid;
public $domain_name;
public $db_type;
@@ -60,41 +64,55 @@
public $enabled;
public $description;
/**
* Called when the object is created
*/
public function __construct() {
//connect to the database
if (empty($this->database)) {
$this->database = database::new();
}
}
// get domain_uuid
public function get_domain_uuid() {
return $this->domain_uuid;
}
public function get_domain_uuid() {
return $this->domain_uuid;
}
// set domain_uuid
public function set_domain_uuid($domain_uuid){
$this->domain_uuid = $domain_uuid;
}
public function set_domain_uuid($domain_uuid){
$this->domain_uuid = $domain_uuid;
}
// get domain_name
public function get_domain_name() {
return $this->domain_name;
}
public function get_domain_name() {
return $this->domain_name;
}
// set domain_name
public function set_domain_name($domain_name){
$this->domain_name = $domain_name;
}
public function set_domain_name($domain_name){
$this->domain_name = $domain_name;
}
// get db_type
public function get_db_type() {
return $this->db_type;
}
public function get_db_type() {
return $this->db_type;
}
// set db_type
public function set_db_type($db_type){
$this->db_type = $db_type;
}
public function set_db_type($db_type){
$this->db_type = $db_type;
}
// get extension
public function get_extension() {
return $this->extension;
}
public function get_extension() {
return $this->extension;
}
// set extension
public function set_extension($extension){
$this->extension = $extension;
}
public function set_extension($extension){
$this->extension = $extension;
}
public function add() {
$domain_uuid = $this->domain_uuid;
@@ -183,10 +201,7 @@
$p->add('extension_add', 'temp');
//execute insert
$database = new database;
$database->app_name = 'switch_directory';
$database->app_uuid = 'efc9cdbf-8616-435d-9d21-ae8d4e6b5225';
$database->save($array);
$this->database->save($array);
unset($array);
//revoke temporary permissions
@@ -286,10 +301,7 @@
$p->add('extension_edit', 'temp');
//execute insert
$database = new database;
$database->app_name = 'switch_directory';
$database->app_uuid = 'efc9cdbf-8616-435d-9d21-ae8d4e6b5225';
$database->save($array);
$this->database->save($array);
unset($array);
//revoke temporary permissions
@@ -307,10 +319,7 @@
$p = permissions::new();
$p->add('extension_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = 'switch_directory';
$database->app_uuid = 'efc9cdbf-8616-435d-9d21-ae8d4e6b5225';
$database->delete($array);
$this->database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('extension_delete', 'temp');
@@ -488,8 +497,7 @@
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "order by call_group asc ";
$parameters['domain_uuid'] = $domain_uuid;
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
$rows = $this->database->select($sql, $parameters, 'all');
$i = 0;
$extension_xml_condensed = false;
if ($extension_xml_condensed) {

View File

@@ -31,11 +31,15 @@
*/
class domains {
/**
* declare constant variables
*/
const app_name = 'domains';
const app_uuid = '8b91605b-f6d2-42e6-a56d-5d1ded01bb44';
/**
* declare the variables
*/
private $app_name;
private $app_uuid;
private $name;
private $table;
private $toggle_field;
@@ -53,8 +57,6 @@
*/
public function __construct($setting_array = []) {
//assign the variables
$this->app_name = 'domains';
$this->app_uuid = '8b91605b-f6d2-42e6-a56d-5d1ded01bb44';
$this->name = 'domain';
$this->table = 'domains';
$this->toggle_field = 'domain_enabled';
@@ -271,8 +273,6 @@
//delete the checked rows
if (is_array($domain_array) && @sizeof($domain_array) != 0) {
//execute delete
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->delete($domain_array);
//set message
@@ -338,8 +338,7 @@
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->save($array);
unset($array);
@@ -404,8 +403,7 @@
//save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->save($array);
unset($array);

View File

@@ -31,12 +31,14 @@
class email {
/**
* declare the variables
*/
private $app_name;
private $app_uuid;
private $name;
* declare constant variables
*/
const app_name = 'email';
const app_uuid = '7a4fef67-5bf8-436a-ae25-7e3c03afcf96';
/**
* declare public variables
*/
public $domain_uuid;
public $method;
public $recipients;
@@ -50,6 +52,11 @@
public $read_confirmation;
public $error;
public $response;
/**
* declare private variables
*/
private $name;
private $settings;
/**
@@ -57,9 +64,7 @@
*/
public function __construct($params = []) {
//assign the variables
$this->app_name = 'email';
$this->name = 'email';
$this->app_uuid = '7a4fef67-5bf8-436a-ae25-7e3c03afcf96';
$this->priority = 0;
$this->debug_level = 3;
$this->read_confirmation = false;

View File

@@ -31,14 +31,22 @@
class groups {
/**
* declare the variables
* declare constant variables
*/
const app_name = 'groups';
const app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
/**
* declare public variables
*/
public $group_uuid;
public $group_level;
/**
* declare private variables
*/
private $database;
private $app_name;
private $app_uuid;
public $group_uuid;
private $groups;
public $group_level;
private $name;
private $table;
private $toggle_field;
@@ -51,16 +59,13 @@
* called when the object is created
*/
public function __construct(database $database = null, $domain_uuid = null, $user_uuid = null) {
//assign the variables
$this->app_name = 'groups';
$this->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
//handle the database object
if (isset($database)) {
$this->database = $database;
}
else {
$this->database = new database;
$this->database = database::new();
}
//set the domain_uuid

View File

@@ -30,18 +30,26 @@
class menu {
/**
* declare the variables
* declare constant variables
*/
const app_name = 'menus';
const app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
/**
* declare private variables
*/
public $menu_uuid;
public $menu_language;
public $text;
/**
* declare private variables
*/
private $app_name;
private $app_uuid;
private $name;
private $table;
private $toggle_field;
private $toggle_values;
private $location;
public $menu_uuid;
public $menu_language;
public $text;
/**
* Set in the constructor. Must be a database object and cannot be null.
@@ -72,8 +80,6 @@
*/
public function __construct($setting_array = []) {
//assign the variables
$this->app_name = 'menus';
$this->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7';
$this->location = 'menus.php';
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
@@ -147,8 +153,6 @@
$p->add('menu_language_delete', 'temp');
//execute delete
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->delete($array);
unset($array);
@@ -227,8 +231,6 @@
$p->add('menu_item_group_delete', 'temp');
//execute delete
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->delete($array);
unset($array);
@@ -301,8 +303,7 @@
//save the changes
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//save the array
$this->database->app_name = $this->app_name;
$this->database->app_uuid = $this->app_uuid;
$this->database->save($array);
unset($array);
@@ -389,8 +390,7 @@
$sql = "select group_name, group_uuid from v_groups ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$database = new database;
$group = $database->select($sql, $parameters, 'row');
$group = $this->database->select($sql, $parameters, 'row');
}
//build the delete array
@@ -416,8 +416,7 @@
if (!empty($array) && @sizeof($array) != 0) {
$sql = "select menu_uuid, menu_item_uuid, ";
$sql .= "group_uuid from v_menu_item_groups ";
$database = new database;
$menu_item_groups = $database->select($sql, null, 'all');
$menu_item_groups = $this->database->select($sql, null, 'all');
$array['menu_item_groups'] = array_filter($array['menu_item_groups'], function($ar) use ($menu_item_groups) {
foreach ($menu_item_groups as $existingArrayItem) {
if ($ar['menu_uuid'] == $existingArrayItem['menu_uuid'] && $ar['menu_item_uuid'] == $existingArrayItem['menu_item_uuid'] && $ar['group_uuid'] == $existingArrayItem['group_uuid']) {
@@ -432,10 +431,7 @@
//add the checked rows fro group
if (!empty($array) && is_array($array) && @sizeof($array) != 0) {
//execute save
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
$this->database->save($array);
unset($array);
//set message
message::add($text['message-add']);
@@ -471,8 +467,7 @@
$sql = "select group_name, group_uuid from v_groups ";
$sql .= "where group_uuid = :group_uuid ";
$parameters['group_uuid'] = $group_uuid;
$database = new database;
$group = $database->select($sql, $parameters, 'row');
$group = $this->database->select($sql, $parameters, 'row');
}
//build the delete array
@@ -497,8 +492,7 @@
if (!empty($uuids) && @sizeof($uuids) != 0) {
$sql = "select menu_uuid, menu_item_uuid as uuid from v_".$this->table." ";
$sql .= "where menu_item_parent_uuid in (".implode(', ', $uuids).") ";
$database = new database;
$rows = $database->select($sql, null, 'all');
$rows = $this->database->select($sql, null, 'all');
if (!empty($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
//assign menu item groups
@@ -522,10 +516,7 @@
$p->add('menu_item_group_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
$this->database->delete($array);
unset($array);
//revoke temporary permissions

View File

@@ -15,10 +15,13 @@ class sounds {
public $full_path;
/**
* Class constructor
*/
* Called when the object is created
*/
public function __construct() {
//connect to the database
if (empty($this->database)) {
$this->database = database::new();
}
}
/**
@@ -45,8 +48,7 @@ class sounds {
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "order by recording_name asc ";
$parameters['domain_uuid'] = $_SESSION["domain_uuid"];
$database = new database;
$recordings = $database->select($sql, $parameters, 'all');
$recordings = $this->database->select($sql, $parameters, 'all');
if (is_array($recordings) && @sizeof($recordings) != 0) {
foreach ($recordings as $x => $row) {
$recording_name = $row["recording_name"];
@@ -63,8 +65,7 @@ class sounds {
$sql = "select * from v_phrases ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION["domain_uuid"];
$database = new database;
$phrases = $database->select($sql, $parameters, 'all');
$phrases = $this->database->select($sql, $parameters, 'all');
if (is_array($phrases) && @sizeof($phrases) != 0) {
foreach ($phrases as $row) {
$array['phrases'][$x]['name'] = "phrase:".$row["phrase_name"];

View File

@@ -12,10 +12,13 @@
public $event_socket_password;
/**
* Called when the object is created
* called when the object is created
*/
public function __construct() {
//connect to the database
if (empty($this->database)) {
$this->database = database::new();
}
}
/**
@@ -209,8 +212,7 @@
//get an array of the default settings
$sql = "select * from v_default_settings ";
$sql .= "where default_setting_category = 'switch' ";
$database = new database;
$default_settings = $database->select($sql, null, 'all');
$default_settings = $this->database->select($sql, null, 'all');
unset($sql);
//find the missing default settings
@@ -251,10 +253,7 @@
$p->add('default_setting_add', 'temp');
//execute insert
$database = new database;
$database->app_name = 'switch_settings';
$database->app_uuid = '84e91084-a227-43cd-ae99-a0f8ed61eb8b';
$database->save($array);
$this->database->save($array);
//revoke temporary permissions
$p->delete('default_setting_add', 'temp');

View File

@@ -27,41 +27,49 @@
class tones {
//define variables
private $tones;
/**
* declare private variables
*/
private $music_list;
private $recordings_list;
private $default_tone_label;
//class constructor
/**
* called when the object is created
*/
public function __construct() {
//add multi-lingual support
$language = new text;
$text = $language->get();
$language = new text;
$text = $language->get();
//connect to the database
if (empty($this->database)) {
$this->database = database::new();
}
//get the tones
$sql = "select * from v_vars ";
$sql .= "where var_category = 'Tones' ";
$sql .= "order by var_name asc ";
$database = new database;
$tones = $database->select($sql, null, 'all');
if (!empty($tones)) {
foreach ($tones as $tone) {
$tone = $tone['var_name'];
if (isset($text['label-'.$tone])) {
$label = $text['label-'.$tone];
}
else {
$label = $tone;
}
$tone_list[$tone] = $label;
}
}
$this->tones = $tone_list ?? '';
unset($sql, $tones, $tone, $tone_list);
}
public function tones_list() {
return $this->tones;
//get the tones
$sql = "select * from v_vars ";
$sql .= "where var_category = 'Tones' ";
$sql .= "order by var_name asc ";
$tones = $this->database->select($sql, null, 'all');
if (!empty($tones)) {
foreach ($tones as $tone) {
$tone = $tone['var_name'];
if (isset($text['label-'.$tone])) {
$label = $text['label-'.$tone];
}
else {
$label = $tone;
}
$tone_list[$tone] = $label;
}
}
unset($sql, $tones, $tone);
//return the tones
return $tone_list ?? '';
}
}