Преглед на файлове

revert back to the class specifying the category

Tim Fry преди 1 година
родител
ревизия
92f9d996b9

+ 21 - 18
maintenance.php

@@ -113,8 +113,10 @@ $maintenance_apps = [];
 if (permission_exists('maintenance_show_all') && $show_all) {
 if (permission_exists('maintenance_show_all') && $show_all) {
 	//get the global settings
 	//get the global settings
 	$sql = "select default_setting_subcategory, default_setting_value, default_setting_enabled from v_default_settings";
 	$sql = "select default_setting_subcategory, default_setting_value, default_setting_enabled from v_default_settings";
-	$sql .= " where default_setting_category = 'maintenance'";
-	$sql .= " and (default_setting_subcategory like '%_database_retention_days' or default_setting_subcategory like '%_filesystem_retention_days')";
+	$sql .= " where";
+	$sql .= "   default_setting_subcategory = '" . maintenance::DATABASE_SUBCATEGORY . "'";
+	$sql .= " or";
+	$sql .= "   default_setting_subcategory = '" . maintenance::FILESYSTEM_SUBCATEGORY . "'";
 	$parameters = null;
 	$parameters = null;
 
 
 	//filter based on search
 	//filter based on search
@@ -131,20 +133,22 @@ if (permission_exists('maintenance_show_all') && $show_all) {
 
 
 	if (!empty($result)) {
 	if (!empty($result)) {
 		foreach ($result as $row) {
 		foreach ($result as $row) {
-			if (str_ends_with($row['default_setting_subcategory'], '_database_retention_days')) {
-				$class_name = substr($row['default_setting_subcategory'], 0, -1 * strlen('_database_rentention_days') + 1);
+			if ($row['default_setting_subcategory'] === maintenance::DATABASE_SUBCATEGORY) {
+				$class_name = $row['default_setting_category'];
 				$maintenance_apps[$class_name]['database_maintenance']['global'] = $row;
 				$maintenance_apps[$class_name]['database_maintenance']['global'] = $row;
 			}
 			}
-			if (str_ends_with($row['default_setting_subcategory'], '_filesystem_retention_days')) {
-				$class_name = substr($row['default_setting_subcategory'], 0, -1 * strlen('_filesystem_rentention_days') + 1);
+			if ($row['default_setting_subcategory'] === maintenance::FILESYSTEM_SUBCATEGORY) {
+				$class_name = $row['default_setting_category'];
 				$maintenance_apps[$class_name]['filesystem_maintenance']['global'] = $row;
 				$maintenance_apps[$class_name]['filesystem_maintenance']['global'] = $row;
 			}
 			}
 		}
 		}
 	}
 	}
 	//get the domain settings
 	//get the domain settings
 	$sql = "select domain_uuid, domain_setting_subcategory, domain_setting_value, domain_setting_enabled from v_domain_settings";
 	$sql = "select domain_uuid, domain_setting_subcategory, domain_setting_value, domain_setting_enabled from v_domain_settings";
-	$sql .= " where domain_setting_category = 'maintenance'";
-	$sql .= " and (domain_setting_subcategory like '%_database_retention_days' or domain_setting_subcategory like '%_filesystem_retention_days')";
+	$sql .= " where (";
+	$sql .= "   domain_setting_subcategory = '" . maintenance::DATABASE_SUBCATEGORY . "'";
+	$sql .= " or";
+	$sql .= "   domain_setting_subcategory = '" . maintenance::FILESYSTEM_SUBCATEGORY . "')";
 
 
 	//filter based on search
 	//filter based on search
 	if (!empty($search)) {
 	if (!empty($search)) {
@@ -160,12 +164,12 @@ if (permission_exists('maintenance_show_all') && $show_all) {
 
 
 	if (!empty($result)) {
 	if (!empty($result)) {
 		foreach ($result as $row) {
 		foreach ($result as $row) {
-			if (str_ends_with($row['domain_setting_subcategory'], '_database_retention_days')) {
-				$class_name = substr($row['domain_setting_subcategory'], 0, -1 * strlen('_database_rentention_days') + 1);
+			if ($row['domain_setting_subcategory'] === maintenance::DATABASE_SUBCATEGORY) {
+				$class_name = $row['domain_setting_category'];
 				$maintenance_apps[$class_name]['database_maintenance'][$row['domain_uuid']] = $row;
 				$maintenance_apps[$class_name]['database_maintenance'][$row['domain_uuid']] = $row;
 			}
 			}
-			if (str_ends_with($row['domain_setting_subcategory'], '_filesystem_retention_days')) {
-				$class_name = substr($row['domain_setting_subcategory'], 0, -1 * strlen('_filesystem_rentention_days') + 1);
+			if ($row['domain_setting_subcategory'] === maintenance::FILESYSTEM_SUBCATEGORY) {
+				$class_name = $row['domain_setting_category'];
 				$maintenance_apps[$class_name]['filesystem_maintenance'][$row['domain_uuid']] = $row;
 				$maintenance_apps[$class_name]['filesystem_maintenance'][$row['domain_uuid']] = $row;
 			}
 			}
 		}
 		}
@@ -174,8 +178,7 @@ if (permission_exists('maintenance_show_all') && $show_all) {
 	$domain_uuid = $_SESSION['domain_uuid'];
 	$domain_uuid = $_SESSION['domain_uuid'];
 	//show only the current domain settings
 	//show only the current domain settings
 	$sql = "select domain_uuid, domain_setting_subcategory, domain_setting_value, domain_setting_enabled from v_domain_settings";
 	$sql = "select domain_uuid, domain_setting_subcategory, domain_setting_value, domain_setting_enabled from v_domain_settings";
-	$sql .= " where domain_setting_category = 'maintenance'";
-	$sql .= " and (domain_setting_subcategory like '%_database_retention_days' or domain_setting_subcategory like '%_filesystem_retention_days')";
+	$sql .= " where (domain_setting_subcategory = ' " . maintenance::DATABASE_SUBCATEGORY . "' or domain_setting_subcategory = '" . maintenance::FILESYSTEM_SUBCATEGORY . "')";
 	$sql .= " and domain_uuid = '$domain_uuid'";
 	$sql .= " and domain_uuid = '$domain_uuid'";
 	if (!empty($search)) {
 	if (!empty($search)) {
 		$search_param = "%$search%";
 		$search_param = "%$search%";
@@ -190,12 +193,12 @@ if (permission_exists('maintenance_show_all') && $show_all) {
 
 
 	if (!empty($result)) {
 	if (!empty($result)) {
 		foreach ($result as $row) {
 		foreach ($result as $row) {
-			if (str_ends_with($row['domain_setting_subcategory'], '_database_retention_days')) {
-				$class_name = substr($row['domain_setting_subcategory'], 0, -1 * strlen('_database_rentention_days') + 1);
+			if ($row['domain_setting_subcategory'] === maintenance::DATABASE_SUBCATEGORY) {
+				$class_name = $row['domain_setting_category'];
 				$maintenance_apps[$class_name]['database_maintenance'][$row['domain_uuid']] = $row;
 				$maintenance_apps[$class_name]['database_maintenance'][$row['domain_uuid']] = $row;
 			}
 			}
-			if (str_ends_with($row['domain_setting_subcategory'], '_filesystem_retention_days')) {
-				$class_name = substr($row['domain_setting_subcategory'], 0, -1 * strlen('_filesystem_rentention_days') + 1);
+			if ($row['domain_setting_subcategory'] === maintenance::FILESYSTEM_SUBCATEGORY) {
+				$class_name = $row['domain_setting_category'];
 				$maintenance_apps[$class_name]['filesystem_maintenance'][$row['domain_uuid']] = $row;
 				$maintenance_apps[$class_name]['filesystem_maintenance'][$row['domain_uuid']] = $row;
 			}
 			}
 		}
 		}

+ 271 - 9
resources/classes/maintenance.php

@@ -42,6 +42,11 @@ class maintenance {
 	const TOGGLE_FIELD = 'maintenance_enabled';
 	const TOGGLE_FIELD = 'maintenance_enabled';
 	const TOGGLE_VALUES = ['true', 'false'];
 	const TOGGLE_VALUES = ['true', 'false'];
 
 
+	const DATABASE_SUBCATEGORY = 'database_retention_days';
+	const FILESYSTEM_SUBCATEGORY = 'filesystem_retention_days';
+
+	private static $app_config_list = null;
+
 	/**
 	/**
 	 * Returns an array of domain names with their domain UUID as the array key
 	 * Returns an array of domain names with their domain UUID as the array key
 	 * @param database $database
 	 * @param database $database
@@ -65,13 +70,22 @@ class maintenance {
 		return $domains;
 		return $domains;
 	}
 	}
 
 
+	/**
+	 * Registers new applications by searching for files in the project that have the signature for a method called
+	 * <code>public static function database_maintenance</code> or the method <code>public static function
+	 * filesystem_maintenance</code>. When found, they are added to the <code>default_settings</code> category of
+	 * <b>maintenance</b> and put in to subcategory array <b>application</b> in default settings table.
+	 * This function is intended to be called by the upgrade method.
+	 * @param database $database
+	 */
 	public static function app_defaults(database $database) {
 	public static function app_defaults(database $database) {
 		//get the maintenance apps
 		//get the maintenance apps
 		$database_maintenance_apps = self::find_classes_by_method('database_maintenance');
 		$database_maintenance_apps = self::find_classes_by_method('database_maintenance');
 		$filesystem_maintenance_apps = self::find_classes_by_method('filesystem_maintenance');
 		$filesystem_maintenance_apps = self::find_classes_by_method('filesystem_maintenance');
 		$maintenance_apps = $database_maintenance_apps + $filesystem_maintenance_apps;
 		$maintenance_apps = $database_maintenance_apps + $filesystem_maintenance_apps;
-
-		self::register_applications($database, $maintenance_apps);
+		if (!empty($maintenance_apps)) {
+			self::register_applications($database, $maintenance_apps);
+		}
 	}
 	}
 
 
 	/**
 	/**
@@ -102,10 +116,10 @@ class maintenance {
 			self::add_maintenance_app_to_array($registered_apps, $application, $text['description-default_settings_app'], $new_maintenance_apps, $index);
 			self::add_maintenance_app_to_array($registered_apps, $application, $text['description-default_settings_app'], $new_maintenance_apps, $index);
 
 
 			//get the application settings from the class for database maintenance
 			//get the application settings from the class for database maintenance
-			self::add_database_maintenance_to_array($database, $application, $text['description-retention_days'], $new_maintenance_apps, $index);
+			//self::add_database_maintenance_to_array($database, $application, $text['description-retention_days'], $new_maintenance_apps, $index);
 
 
 			//get the application settings from the class for filesystem maintenance
 			//get the application settings from the class for filesystem maintenance
-			self::add_filesystem_maintenance_to_array($database, $application, $text['description-retention_days'], $new_maintenance_apps, $index);
+			//self::add_filesystem_maintenance_to_array($database, $application, $text['description-retention_days'], $new_maintenance_apps, $index);
 		}
 		}
 		if (count($new_maintenance_apps) > 0) {
 		if (count($new_maintenance_apps) > 0) {
 			$database->app_name = self::APP_NAME;
 			$database->app_name = self::APP_NAME;
@@ -116,6 +130,66 @@ class maintenance {
 		return false;
 		return false;
 	}
 	}
 
 
+	/**
+	 * Returns the class specified category to be used for the maintenance service. If the class does not have a method that
+	 * returns a string with the category to use then the class name will be used as the category.
+	 * @param object|string $class_name
+	 * @return string
+	 */
+	public static function get_database_category($class_name): string {
+		if (method_exists($class_name, 'database_maintenance_category')) {
+			$default_value = $class_name::database_maintenance_category();
+		} else {
+			$default_value = $class_name;
+		}
+		return $default_value;
+	}
+
+	/**
+	 * Returns the class specified subcategory to be used for the maintenance service. If the class does not have a method that
+	 * returns a string with the subcategory to use then the class name will be used as the subcategory.
+	 * @param object|string $class_name
+	 * @return string
+	 */
+	public static function get_database_subcategory($class_name): string {
+		if (method_exists($class_name, 'database_maintenance_subcategory')) {
+			$default_value = $class_name::database_maintenance_subcategory();
+		} else {
+			$default_value = self::DATABASE_SUBCATEGORY;
+		}
+		return $default_value;
+	}
+
+	/**
+	 * Returns the class specified category to be used for the maintenance service. If the class does not have a method that
+	 * returns a string with the category to use then the class name will be used as the category.
+	 * @param object|string $class_name
+	 * @return string
+	 */
+	public static function get_filesystem_category($class_name): string {
+		if (method_exists($class_name, 'filesystem_maintenance_category')) {
+			$default_value = $class_name::filesystem_maintenance_category();
+		} else {
+			$default_value = $class_name;
+		}
+		return $default_value;
+	}
+
+	/**
+	 * Returns the class specified subcategory to be used for the maintenance service. If the class does not have a method that
+	 * returns a string with the subcategory to use then the class name will be used as the subcategory.
+	 * @param object|string $class_name
+	 * @return string
+	 */
+	public static function get_filesystem_subcategory($class_name): string {
+		if (method_exists($class_name, 'filesystem_maintenance_subcategory')) {
+			$default_value = $class_name::filesystem_maintenance_subcategory();
+		} else {
+			$default_value = self::FILESYSTEM_SUBCATEGORY;
+		}
+		return $default_value;
+	}
+
 	/**
 	/**
 	 * Returns a list of maintenance applications already in the default settings table ignoring default_setting_enabled
 	 * Returns a list of maintenance applications already in the default settings table ignoring default_setting_enabled
 	 * @param database $database
 	 * @param database $database
@@ -139,6 +213,27 @@ class maintenance {
 		return $registered_applications;
 		return $registered_applications;
 	}
 	}
 
 
+	/**
+	 * Get a value from the app_config.php file default settings
+	 * This function will load all app_config.php files and then load them in a class array only once. The first call will
+	 * have a performance impact but subsequent calls will have minimal impact as no files will be loaded.
+	 * @param string $category
+	 * @param string $subcategory
+	 * @return array|string|null If no value is found then null will be returned
+	 */
+	public static function get_app_config_value(string $category, string $subcategory) {
+		$return_value = null;
+		//check if this is the first time loading the files
+		if (self::$app_config_list === null) {
+			//load the app_config files once
+			self::load_app_config_list();
+		}
+		if (!empty(self::$app_config_list[$category][$subcategory])) {
+			$return_value = self::$app_config_list[$category][$subcategory];
+		}
+		return $return_value;
+	}
+
 	/**
 	/**
 	 * updates the array with a maintenance app using a format the database object save method can use to save in the default settings
 	 * updates the array with a maintenance app using a format the database object save method can use to save in the default settings
 	 * default settings category: maintenance, subcategory: application, value: name of new application
 	 * default settings category: maintenance, subcategory: application, value: name of new application
@@ -164,7 +259,7 @@ class maintenance {
 
 
 	/**
 	/**
 	 * Updates the array with a database maintenance app using a format the database object save method can use in default settings table
 	 * Updates the array with a database maintenance app using a format the database object save method can use in default settings table
-	 * <p><b>default setting category</b>: class name that has the <code>use database_maintenance;</code> statement<br>
+	 * <p><b>default setting category</b>: class name that has the <code>implements database_maintenance;</code> statement<br>
 	 * <b>default setting subcategory</b>: "database_retention_days" (The class can override this setting to a custom value)<br>
 	 * <b>default setting subcategory</b>: "database_retention_days" (The class can override this setting to a custom value)<br>
 	 * <b>default setting value</b>: "30" (The class can override this setting to a custom value)<br>
 	 * <b>default setting value</b>: "30" (The class can override this setting to a custom value)<br>
 	 * <b>description</b>: "Number of days the maintenance application will keep the information."<br>
 	 * <b>description</b>: "Number of days the maintenance application will keep the information."<br>
@@ -179,8 +274,8 @@ class maintenance {
 	private static function add_database_maintenance_to_array($database, $application, $description, &$array, &$index) {
 	private static function add_database_maintenance_to_array($database, $application, $description, &$array, &$index) {
 		//get the application settings from the object for database maintenance
 		//get the application settings from the object for database maintenance
 		if (method_exists($application, 'database_maintenance')) {
 		if (method_exists($application, 'database_maintenance')) {
-			$category = 'maintenance';
-			$subcategory = $application . '_database_retention_days';
+			$category = $application;
+			$subcategory =  self::DATABASE_SUBCATEGORY;
 			//check if the default setting already exists in global default settings table
 			//check if the default setting already exists in global default settings table
 			$uuid = self::default_setting_uuid($database, $category, $subcategory);
 			$uuid = self::default_setting_uuid($database, $category, $subcategory);
 			if (empty($uuid)) {
 			if (empty($uuid)) {
@@ -235,9 +330,9 @@ class maintenance {
 	private static function add_filesystem_maintenance_to_array($database, $application, $description, &$array, &$index) {
 	private static function add_filesystem_maintenance_to_array($database, $application, $description, &$array, &$index) {
 		if (method_exists($application, 'filesystem_maintenance')) {
 		if (method_exists($application, 'filesystem_maintenance')) {
 			//the trait has this value defined
 			//the trait has this value defined
-			$category = 'maintenance';
+			$category = $application;
 			//the trait has this value defined
 			//the trait has this value defined
-			$subcategory = $application . '_filesystem_retention_days';
+			$subcategory = 'filesystem_retention_days';
 			//check if the default setting already exists in global settings
 			//check if the default setting already exists in global settings
 			$uuid = self::default_setting_uuid($database, $category, $subcategory);
 			$uuid = self::default_setting_uuid($database, $category, $subcategory);
 			if (empty($uuid)) {
 			if (empty($uuid)) {
@@ -279,6 +374,173 @@ class maintenance {
 		}
 		}
 		return $found_classes;
 		return $found_classes;
 	}
 	}
+
+	private static function load_app_config_list() {
+
+		//app_config files use the array $apps to define the default_settings
+		global $apps;
+
+		//initialize the config list
+		self::$app_config_list = [];
+
+		//get the list of app_config files
+		$project_dir = dirname(__DIR__, 4);
+		$app_config_files = glob($project_dir . '/app/*/app_config.php');
+		$core_config_files = glob($project_dir . '/core/*/app_config.php');
+		$config_files = array_merge($app_config_files, $core_config_files);
+
+		//iterate over list
+		foreach ($config_files as $x => $file) {
+			//include the app_config file
+			include $file;
+			//create a classname
+			//get the array from the included file
+			if (!empty($apps[$x]['default_settings'])) {
+				foreach ($apps[$x]['default_settings'] as $setting) {
+					//get the subcategory
+					$category = $setting['default_setting_category'];
+					$subcategory = $setting['default_setting_subcategory'];
+					$value = $setting['default_setting_value'];
+					$type = $setting['default_setting_name'];
+					//check for array type
+					if ($type !== 'array') {
+						//store the values
+						self::$app_config_list[$category][$subcategory] = $value;
+					} else {
+						$order = intval($setting['default_setting_order']);
+						self::$app_config_list[$category][$subcategory][$order] = $value;
+					}
+				}
+			}
+		}
+	}
+
+	/**
+	 * Finds the UUID of a maintenance setting searching in the default settings, domain settings, and user settings tables.
+	 * This is primarily used for the dashboard display as there was a need to detect a setting even if it was disabled.
+	 * <p>NOTE:<br>
+	 * This will not deal with an array of returned values (such as maintenance_application) appropriately at this time as it has a limited scope of detecting a
+	 * string value that is unique with the category and subcategory combination across the tables.</p>
+	 * @param database $database Already connected database object
+	 * @param string $category Main category
+	 * @param string $subcategory Subcategory or name of the setting
+	 * @param bool $status Used for internal use but could be used to find a setting that is currently disabled
+	 * @return array Two-dimensional array assigned but using key/value pairs. The keys are:<br>
+	 *   <ul>uuid: Primary UUID that would be chosen by the settings object
+	 *   <ul>uuids: Array of all matching category and subcategory strings
+	 *   <ul>table: Table name that the primary UUID was found
+	 *   <ul>status: bool true/false
+	 * @access public
+	 */
+	public static function find_uuid(database $database, string $category, string $subcategory, bool $status = true): array {
+		//first look for false setting then override with enabled setting
+		if ($status) {
+			$uuids = self::find_uuid($database, $category, $subcategory, false);
+		} else {
+			//set defaults to not found
+			$uuids = [];
+			$uuids['uuid'] = '';
+			$uuids['uuids'] = [];
+			$uuids['table'] = '';
+			$uuids['status'] = false;
+		}
+		$status_string = ($status) ? 'true' : 'false';
+		//
+		// Get the settings for false first then override the 'false' setting with the setting that is set to 'true'
+		//
+		//get global setting
+		$result = self::get_uuid($database, 'default', $category, $subcategory, $status_string);
+		if (!empty($result)) {
+			$uuids['uuid'] = $result[0];
+			$uuids['count'] = count($result);
+			if (count($result) > 1) {
+				$uuids['uuids'] = $result;
+			} else {
+				$uuids['uuids'] = [];
+			}
+			$uuids['table'] = 'default';
+			$uuids['status'] = $status;
+		}
+		//override default with domain setting
+		$result = self::get_uuid($database, 'domain', $category, $subcategory, $status_string);
+		if (!empty($result)) {
+			if ($uuids['count'] > 0) {
+				$uuids['count'] += count($result);
+				if (count($uuids['uuids']) > 0) {
+					array_merge($uuids['uuids'], $result);
+				} else {
+					$ids[] = $uuids['uuid'];
+					$uuids['uuids'] = array_merge($result, $ids);
+				}
+			} else {
+				$uuids['count'] = count($result);
+				if (count($result) > 1) {
+					$uuids['uuids'] = $result;
+				} else {
+					$uuids['uuids'] = [];
+				}
+			}
+			$uuids['uuid'] = $result[0];
+			$uuids['table'] = 'domain';
+			$uuids['status'] = $status;
+		}
+		//override domain with user setting
+		$result = self::get_uuid($database, 'user', $category, $subcategory, $status_string);
+		if (!empty($result)) {
+			$uuids['uuid'] = $result[0];
+			$uuids['count'] = count($result);
+			if (count($result) > 1) {
+				$uuids['uuids'] = $result;
+			} else {
+				$uuids['uuids'] = [];
+			}
+			$uuids['table'] = 'user';
+			$uuids['status'] = $status;
+		}
+		return $uuids;
+	}
+
+	/**
+	 * Called by the find_uuid function to actually search database using prepared data structures
+	 * @access private
+	 */
+	private static function get_uuid(database $database, string $table, string $category, string $subcategory, string $status): array {
+		$uuid = [];
+		$sql = "select {$table}_setting_uuid from v_{$table}_settings s";
+		$sql .= " where s.{$table}_setting_category = :category";
+		$sql .= " and s.{$table}_setting_subcategory = :subcategory";
+		$sql .= " and s.{$table}_setting_enabled = '$status'";
+
+		//set search params
+		$params = [];
+		$params['category'] = $category;
+		$params['subcategory'] = $subcategory;
+		if ($table === 'domain' && !empty($_SESSION['domain_uuid']) && is_uuid($_SESSION['domain_uuid'])) {
+			$sql .= " and s.domain_uuid = :domain_uuid";
+			$params['domain_uuid'] = $_SESSION['domain_uuid'];
+		}
+		if ($table === 'user' && !empty($_SESSION['user_uuid']) && is_uuid($_SESSION['user_uuid'])) {
+			$sql .= " and s.user_uuid = :user_uuid";
+			$params['user_uuid'] = $_SESSION['user_uuid'];
+		}
+		$result = $database->select($sql, $params);
+		if (!empty($result)) {
+			if (is_array($result)) {
+				$uuids = array_map(function ($value) use ($table) {
+					if (is_array($value)) {
+						return $value["{$table}_setting_uuid"];
+					} else {
+						return $value;
+					}
+				}, $result);
+				$uuid = $uuids;
+			} else {
+				$uuid[] = $result;
+			}
+		}
+		return $uuid;
+	}
+
 }
 }
 
 
 ?>
 ?>

+ 11 - 3
resources/classes/maintenance_logs.php

@@ -31,7 +31,7 @@
  *
  *
  * @author Tim Fry <[email protected]>
  * @author Tim Fry <[email protected]>
  */
  */
-class maintenance_logs {
+class maintenance_logs implements database_maintenance {
 
 
 	const APP_NAME = 'maintenance_logs';
 	const APP_NAME = 'maintenance_logs';
 	const APP_UUID = '5be7b4c2-1a4f-4236-b91a-60e3c33904d7';
 	const APP_UUID = '5be7b4c2-1a4f-4236-b91a-60e3c33904d7';
@@ -64,8 +64,8 @@ class maintenance_logs {
 		foreach ($domains as $domain_uuid => $domain_name) {
 		foreach ($domains as $domain_uuid => $domain_name) {
 			//get the settings for this domain
 			//get the settings for this domain
 			$domain_settings = new $settings(['database' => $database, 'domain_uuid' => $domain_uuid]);
 			$domain_settings = new $settings(['database' => $database, 'domain_uuid' => $domain_uuid]);
-			//get retention days with automatic default settings fallback
-			$retention = $domain_settings->get('maintenance', self::class . '_database_retention_days', '');
+			//get retention days using the class defined category and subcategory
+			$retention = $domain_settings->get(self::database_maintenance_category(), self::database_maintenance_subcategory(), '');
 			//ensure there is something to do
 			//ensure there is something to do
 			if (!empty($retention) && is_numeric($retention)) {
 			if (!empty($retention) && is_numeric($retention)) {
 				//delete old entries for this domain
 				//delete old entries for this domain
@@ -267,6 +267,14 @@ class maintenance_logs {
 			message::add($text['message-copy']);
 			message::add($text['message-copy']);
 		}
 		}
 	}
 	}
+
+	public static function database_maintenance_category(): string {
+		return "maintenance_logs";
+	}
+
+	public static function database_maintenance_subcategory(): string {
+		return "database_retention_days";
+	}
 }
 }
 
 
 ?>
 ?>

+ 0 - 134
resources/classes/maintenance_service.php

@@ -38,14 +38,6 @@
  *
  *
  * It is up to the class implementation to do any domain specific settings within the function.
  * It is up to the class implementation to do any domain specific settings within the function.
  *
  *
- * All classes will be automatically detected and registered during "App Defaults" in the Upgrade module. Each
- * class will have settings that are (classname)_database_retention_days and (classname)_filesystem_retention_days
- * automatically added to the maintenance section of Global Default Settings. Due to each class executing the
- * function database_maintenace or filesystem_maintenance with the settings object, it is possible to have more
- * settings available wherever the class prefers them to be. However, the dashboard may not function correctly
- * without the default settings. It is recommended to use the built-in functions and not modify the default
- * behavior directly.
- *
  * The interfaces of database_maintenance and filesystem_maintenance for classes are provided but are not necessary
  * The interfaces of database_maintenance and filesystem_maintenance for classes are provided but are not necessary
  * for the behavior of maintenance services being executed.
  * for the behavior of maintenance services being executed.
  *
  *
@@ -285,132 +277,6 @@ class maintenance_service extends service {
 	// Common functions used with maintainer services //
 	// Common functions used with maintainer services //
 	////////////////////////////////////////////////////
 	////////////////////////////////////////////////////
 
 
-	/**
-	 * Finds the UUID of a maintenance setting searching in the default settings, domain settings, and user settings tables.
-	 * This is primarily used for the dashboard display as there was a need to detect a setting even if it was disabled.
-	 * <p>NOTE:<br>
-	 * This will not deal with an array of returned values (such as maintenance_application) appropriately at this time as it has a limited scope of detecting a
-	 * string value that is unique with the category and subcategory combination across the tables.</p>
-	 * @param database $database Already connected database object
-	 * @param string $category Main category
-	 * @param string $subcategory Subcategory or name of the setting
-	 * @param bool $status Used for internal use but could be used to find a setting that is currently disabled
-	 * @return array Two-dimensional array assigned but using key/value pairs. The keys are:<br>
-	 *   <ul>uuid: Primary UUID that would be chosen by the settings object
-	 *   <ul>uuids: Array of all matching category and subcategory strings
-	 *   <ul>table: Table name that the primary UUID was found
-	 *   <ul>status: bool true/false
-	 * @access public
-	 */
-	public static function find_uuid(database $database, string $category, string $subcategory, bool $status = true): array {
-		//first look for false setting then override with enabled setting
-		if ($status) {
-			$uuids = self::find_uuid($database, $category, $subcategory, false);
-		} else {
-			//set defaults to not found
-			$uuids = [];
-			$uuids['uuid'] = '';
-			$uuids['uuids'] = [];
-			$uuids['table'] = '';
-			$uuids['status'] = false;
-		}
-		$status_string = ($status) ? 'true' : 'false';
-		//
-		// Get the settings for false first then override the 'false' setting with the setting that is set to 'true'
-		//
-		//get global setting
-		$result = self::get_uuid($database, 'default', $category, $subcategory, $status_string);
-		if (!empty($result)) {
-			$uuids['uuid'] = $result[0];
-			$uuids['count'] = count($result);
-			if (count($result) > 1) {
-				$uuids['uuids'] = $result;
-			} else {
-				$uuids['uuids'] = [];
-			}
-			$uuids['table'] = 'default';
-			$uuids['status'] = $status;
-		}
-		//override default with domain setting
-		$result = self::get_uuid($database, 'domain', $category, $subcategory, $status_string);
-		if (!empty($result)) {
-			if ($uuids['count'] > 0) {
-				$uuids['count'] += count($result);
-				if (count($uuids['uuids']) > 0) {
-					array_merge($uuids['uuids'], $result);
-				} else {
-					$ids[] = $uuids['uuid'];
-					$uuids['uuids'] = array_merge($result, $ids);
-				}
-			} else {
-				$uuids['count'] = count($result);
-				if (count($result) > 1) {
-					$uuids['uuids'] = $result;
-				} else {
-					$uuids['uuids'] = [];
-				}
-			}
-			$uuids['uuid'] = $result[0];
-			$uuids['table'] = 'domain';
-			$uuids['status'] = $status;
-		}
-		//override domain with user setting
-		$result = self::get_uuid($database, 'user', $category, $subcategory, $status_string);
-		if (!empty($result)) {
-			$uuids['uuid'] = $result[0];
-			$uuids['count'] = count($result);
-			if (count($result) > 1) {
-				$uuids['uuids'] = $result;
-			} else {
-				$uuids['uuids'] = [];
-			}
-			$uuids['table'] = 'user';
-			$uuids['status'] = $status;
-		}
-		return $uuids;
-	}
-
-	/**
-	 * Called by the find_uuid function to actually search database using prepared data structures
-	 * @access private
-	 */
-	private static function get_uuid(database $database, string $table, string $category, string $subcategory, string $status): array {
-		$uuid = [];
-		$sql = "select {$table}_setting_uuid from v_{$table}_settings s";
-		$sql .= " where s.{$table}_setting_category = :category";
-		$sql .= " and s.{$table}_setting_subcategory = :subcategory";
-		$sql .= " and s.{$table}_setting_enabled = '$status'";
-
-		//set search params
-		$params = [];
-		$params['category'] = $category;
-		$params['subcategory'] = $subcategory;
-		if ($table === 'domain' && !empty($_SESSION['domain_uuid']) && is_uuid($_SESSION['domain_uuid'])) {
-			$sql .= " and s.domain_uuid = :domain_uuid";
-			$params['domain_uuid'] = $_SESSION['domain_uuid'];
-		}
-		if ($table === 'user' && !empty($_SESSION['user_uuid']) && is_uuid($_SESSION['user_uuid'])) {
-			$sql .= " and s.user_uuid = :user_uuid";
-			$params['user_uuid'] = $_SESSION['user_uuid'];
-		}
-		$result = $database->select($sql, $params);
-		if (!empty($result)) {
-			if (is_array($result)) {
-				$uuids = array_map(function ($value) use ($table) {
-					if (is_array($value)) {
-						return $value["{$table}_setting_uuid"];
-					} else {
-						return $value;
-					}
-				}, $result);
-				$uuid = $uuids;
-			} else {
-				$uuid[] = $result;
-			}
-		}
-		return $uuid;
-	}
-
 	/**
 	/**
 	 * Saves the logs in an array in order to write them all at once. This is to remove the number of times the database will try to
 	 * Saves the logs in an array in order to write them all at once. This is to remove the number of times the database will try to
 	 * be written to during the many worker processes to improve performance similar to an atomic commit.
 	 * be written to during the many worker processes to improve performance similar to an atomic commit.

+ 28 - 13
resources/dashboard/maintenance.php

@@ -64,6 +64,11 @@
 			//check enabled/disabled status
 			//check enabled/disabled status
 			$uuid = (empty($row['uuid']) ? uuid() : $row['uuid']);
 			$uuid = (empty($row['uuid']) ? uuid() : $row['uuid']);
 			$table = (empty($row['type']) ? 'default' : $row['type']);
 			$table = (empty($row['type']) ? 'default' : $row['type']);
+			//check table
+			if ($table !== 'domain' || $table !== 'default') {
+				header('HTTP/1.1 403 Forbidden', true, 403);
+				die();
+			}
 			$category = $row['category'];
 			$category = $row['category'];
 			$subcategory = $row['subcategory'];
 			$subcategory = $row['subcategory'];
 			$days = $row['days'];
 			$days = $row['days'];
@@ -101,6 +106,11 @@
 
 
 			$uuid = (empty($row['uuid']) ? uuid() : $row['uuid']);
 			$uuid = (empty($row['uuid']) ? uuid() : $row['uuid']);
 			$table = (empty($row['type']) ? 'default' : $row['type']);
 			$table = (empty($row['type']) ? 'default' : $row['type']);
+			//check table
+			if ($table !== 'domain' || $table !== 'default') {
+				header('HTTP/1.1 403 Forbidden', true, 403);
+				die();
+			}
 			$filesystem_category = $row['category'] ?? '';
 			$filesystem_category = $row['category'] ?? '';
 			$filesystem_subcategory = $row['subcategory'] ?? '';
 			$filesystem_subcategory = $row['subcategory'] ?? '';
 			$days = $row['days'] ?? '';
 			$days = $row['days'] ?? '';
@@ -150,8 +160,8 @@
 			//check for database status
 			//check for database status
 			if (method_exists($maintenance_app, 'database_maintenance')) {
 			if (method_exists($maintenance_app, 'database_maintenance')) {
 				$total_maintenance_apps++;
 				$total_maintenance_apps++;
-				$category = 'maintenance';
-				$subcategory = $maintenance_app . '_database_retention_days';
+				$category = maintenance::get_database_category($maintenance_app);
+				$subcategory = maintenance::get_database_subcategory($maintenance_app);
 				if (!empty($setting->get($category, $subcategory, ''))) {
 				if (!empty($setting->get($category, $subcategory, ''))) {
 					$total_running_maintenance_apps++;
 					$total_running_maintenance_apps++;
 				}
 				}
@@ -159,8 +169,8 @@
 			//check for filesystem status
 			//check for filesystem status
 			if (method_exists($maintenance_app, 'filesystem_maintenance')) {
 			if (method_exists($maintenance_app, 'filesystem_maintenance')) {
 				$total_maintenance_apps++;
 				$total_maintenance_apps++;
-				$category = 'maintenance';
-				$subcategory = $maintenance_app . '_filesystem_retention_days';
+				$category = maintenance::get_filesystem_category($maintenance_app);
+				$subcategory = maintenance::get_filesystem_subcategory($maintenance_app);
 				if(!empty($setting->get($category, $subcategory, ''))) {
 				if(!empty($setting->get($category, $subcategory, ''))) {
 					$total_running_maintenance_apps++;
 					$total_running_maintenance_apps++;
 				}
 				}
@@ -267,14 +277,16 @@ if (permission_exists('maintenance_view')) {
 		$database_checkbox_state = CHECKBOX_HIDDEN;
 		$database_checkbox_state = CHECKBOX_HIDDEN;
 		$param = [];
 		$param = [];
 		if (class_exists($maintenance_app)) {
 		if (class_exists($maintenance_app)) {
+			$display_name = $maintenance_app;
 			//check for database status
 			//check for database status
 			if (method_exists($maintenance_app, 'database_maintenance')) {
 			if (method_exists($maintenance_app, 'database_maintenance')) {
-				$database_category = 'maintenance';
-				$database_subcategory = $maintenance_app . '_database_retention_days';
-				$database_default_value = '30';
+				$database_category = maintenance::get_database_category($maintenance_app);
+				$database_subcategory = maintenance::get_database_subcategory($maintenance_app);
+				$database_default_value = maintenance::get_app_config_value($database_category, $database_subcategory); //app_config.php default value
 				$database_days = $setting->get($database_category, $database_subcategory, '');
 				$database_days = $setting->get($database_category, $database_subcategory, '');
+				$display_name = $database_category;
 				//uuid of setting
 				//uuid of setting
-				$database_setting_uuids = maintenance_service::find_uuid($database, $database_category, $database_subcategory);
+				$database_setting_uuids = maintenance::find_uuid($database, $database_category, $database_subcategory);
 				$database_setting_uuid = $database_setting_uuids['uuid'];
 				$database_setting_uuid = $database_setting_uuids['uuid'];
 				$database_setting_table = $database_setting_uuids['table'];
 				$database_setting_table = $database_setting_uuids['table'];
 				if (empty($database_days)) {
 				if (empty($database_days)) {
@@ -286,12 +298,15 @@ if (permission_exists('maintenance_view')) {
 
 
 			//check for filesystem status
 			//check for filesystem status
 			if (method_exists($maintenance_app, 'filesystem_maintenance')) {
 			if (method_exists($maintenance_app, 'filesystem_maintenance')) {
-				$filesystem_category = 'maintenance';
-				$filesystem_subcategory = $maintenance_app . '_filesystem_retention_days';
-				$filesystem_default_value = '30';
+				$filesystem_category = maintenance::get_filesystem_category($maintenance_app);
+				$filesystem_subcategory = maintenance::get_filesystem_subcategory($maintenance_app);
+				$filesystem_default_value = maintenance::get_app_config_value($filesystem_category, $filesystem_subcategory);
 				$filesystem_days = $setting->get($filesystem_category, $filesystem_subcategory, '');
 				$filesystem_days = $setting->get($filesystem_category, $filesystem_subcategory, '');
+				if (empty($database_category)) {
+					$display_name = $filesystem_category;
+				}
 				//uuid of setting
 				//uuid of setting
-				$filesystem_setting_uuids = maintenance_service::find_uuid($database, $filesystem_category, $filesystem_subcategory);
+				$filesystem_setting_uuids = maintenance::find_uuid($database, $filesystem_category, $filesystem_subcategory);
 				$filesystem_setting_uuid = $filesystem_setting_uuids['uuid'];
 				$filesystem_setting_uuid = $filesystem_setting_uuids['uuid'];
 				$filesystem_setting_table = $filesystem_setting_uuids['table'];
 				$filesystem_setting_table = $filesystem_setting_uuids['table'];
 				if (empty($filesystem_days)) {
 				if (empty($filesystem_days)) {
@@ -314,7 +329,7 @@ if (permission_exists('maintenance_view')) {
 		}
 		}
 		//display the maintanence application
 		//display the maintanence application
 		echo "<tr>";
 		echo "<tr>";
-		$display_name = ucwords(str_replace('_', ' ', $maintenance_app));
+		$display_name = ucwords(str_replace('_', ' ', $display_name));
 		echo "	<td valign='top' class='".$row_style[$c]." hud_text'>$display_name</td>";
 		echo "	<td valign='top' class='".$row_style[$c]." hud_text'>$display_name</td>";
 		//
 		//
 		// Database apps
 		// Database apps

+ 2 - 0
resources/interfaces/database_maintenance.php

@@ -6,6 +6,8 @@
  */
  */
 interface database_maintenance {
 interface database_maintenance {
 	public static function database_maintenance(settings $settings): void;
 	public static function database_maintenance(settings $settings): void;
+	public static function database_maintenance_category(): string;
+	public static function database_maintenance_subcategory(): string;
 }
 }
 
 
 ?>
 ?>