Ver código fonte

adjust for required changes
updated for proper traits folder name
removed register function
reverted back to function calls for category and subcategory
added permission maintenance_show_all to allow for admin level use
updated languages file for proper start to internationalization
fixed bug in dashboard uuid call
moved button and modal classes out of project to main project

Tim Fry 1 ano atrás
pai
commit
9be5801533

+ 1 - 1
app_config.php

@@ -60,7 +60,7 @@
 	$apps[$x]['permissions'][$y]['name'] = 'maintenance_view';
 	$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
 	$y++;
-	$apps[$x]['permissions'][$y]['name'] = 'maintenance_edit';
+	$apps[$x]['permissions'][$y]['name'] = 'maintenance_show_all';
 	$apps[$x]['permissions'][$y]['groups'][] = 'superadmin';
 	$y++;
 	$apps[$x]['permissions'][$y]['name'] = 'maintenance_log_view';

+ 101 - 0
app_languages.php

@@ -337,3 +337,104 @@ $text['description-retention_days']['uk-ua'] = '';
 $text['description-retention_days']['zh-cn'] = '';
 $text['description-retention_days']['ja-jp'] = '';
 $text['description-retention_days']['ko-kr'] = '';
+
+$text['label-global']['en-us'] = "Global";
+$text['label-global']['en-gb'] = "Global";
+$text['label-global']['ar-eg'] = "عالمي";
+$text['label-global']['de-at'] = "Global";
+$text['label-global']['de-ch'] = "Global";
+$text['label-global']['de-de'] = "Global";
+$text['label-global']['el-gr'] = "Παγκόσμια";
+$text['label-global']['es-cl'] = "Global";
+$text['label-global']['es-mx'] = "Global";
+$text['label-global']['fr-ca'] = "Mondial";
+$text['label-global']['fr-fr'] = "Mondial";
+$text['label-global']['he-il'] = "כללי";
+$text['label-global']['it-it'] = "Globale";
+$text['label-global']['nl-nl'] = "Globaal";
+$text['label-global']['pl-pl'] = "Globalny";
+$text['label-global']['pt-br'] = "Global";
+$text['label-global']['pt-pt'] = "Global";
+$text['label-global']['ro-ro'] = "Global";
+$text['label-global']['ru-ru'] = "Глобальный";
+$text['label-global']['sv-se'] = "Global";
+$text['label-global']['uk-ua'] = "Глобальний";
+$text['label-global']['tr-tr'] = "Küresel";
+$text['label-global']['zh-cn'] = "全球的";
+$text['label-global']['ja-jp'] = "グローバル";
+$text['label-global']['ko-kr'] = "글로벌";
+
+$text['label-yes']['en-us'] = "Yes";
+$text['label-yes']['en-gb'] = "Yes";
+$text['label-yes']['ar-eg'] = "نعم";
+$text['label-yes']['de-at'] = "Ja";
+$text['label-yes']['de-ch'] = "Ja";
+$text['label-yes']['de-de'] = "Ja";
+$text['label-yes']['el-gr'] = "Ναί";
+$text['label-yes']['es-cl'] = "Si";
+$text['label-yes']['es-mx'] = "Si";
+$text['label-yes']['fr-ca'] = "Oui";
+$text['label-yes']['fr-fr'] = "Oui";
+$text['label-yes']['he-il'] = "כן";
+$text['label-yes']['it-it'] = "Si";
+$text['label-yes']['nl-nl'] = "Ja";
+$text['label-yes']['pl-pl'] = "Tak";
+$text['label-yes']['pt-br'] = "Sim";
+$text['label-yes']['pt-pt'] = "Sim";
+$text['label-yes']['ro-ro'] = "da";
+$text['label-yes']['ru-ru'] = "Да";
+$text['label-yes']['sv-se'] = "Ja";
+$text['label-yes']['uk-ua'] = "Так";
+$text['label-yes']['zh-cn'] = "是的";
+$text['label-yes']['ja-jp'] = "はい";
+$text['label-yes']['ko-kr'] = "예";
+
+$text['label-no']['en-us'] = "No";
+$text['label-no']['en-gb'] = "No";
+$text['label-no']['ar-eg'] = "لا";
+$text['label-no']['de-at'] = "Nein";
+$text['label-no']['de-ch'] = "Nein";
+$text['label-no']['de-de'] = "Nein";
+$text['label-no']['el-gr'] = "Οχι";
+$text['label-no']['es-cl'] = "No";
+$text['label-no']['es-mx'] = "No";
+$text['label-no']['fr-ca'] = "Non";
+$text['label-no']['fr-fr'] = "Non";
+$text['label-no']['he-il'] = "לא";
+$text['label-no']['it-it'] = "No";
+$text['label-no']['nl-nl'] = "Nee";
+$text['label-no']['pl-pl'] = "Nie";
+$text['label-no']['pt-br'] = "Não ";
+$text['label-no']['pt-pt'] = "Não";
+$text['label-no']['ro-ro'] = "Nu";
+$text['label-no']['ru-ru'] = "Нет";
+$text['label-no']['sv-se'] = "Nej";
+$text['label-no']['uk-ua'] = "Ні";
+$text['label-no']['zh-cn'] = "不";
+$text['label-no']['ja-jp'] = "いいえ";
+$text['label-no']['ko-kr'] = "아니요";
+
+$text['label-app']['en-us'] = "Application";
+$text['label-app']['en-gb'] = "Application";
+$text['label-app']['ar-eg'] = "طلب";
+$text['label-app']['de-at'] = "Anwendung";
+$text['label-app']['de-ch'] = "Anwendung";
+$text['label-app']['de-de'] = "Anwendung";
+$text['label-app']['el-gr'] = "Εφαρμογή";
+$text['label-app']['es-cl'] = "Aplicación";
+$text['label-app']['es-mx'] = "Aplicación";
+$text['label-app']['fr-ca'] = "Application";
+$text['label-app']['fr-fr'] = "Application";
+$text['label-app']['he-il'] = "אפליקציה";
+$text['label-app']['it-it'] = "Applicazione";
+$text['label-app']['nl-nl'] = "Toepassing";
+$text['label-app']['pl-pl'] = "Aplikacja";
+$text['label-app']['pt-br'] = "Aplicação";
+$text['label-app']['pt-pt'] = "Aplicação";
+$text['label-app']['ro-ro'] = "Aplicație";
+$text['label-app']['ru-ru'] = "Приложение";
+$text['label-app']['sv-se'] = "Ansökan";
+$text['label-app']['uk-ua'] = "Додаток";
+$text['label-app']['zh-cn'] = "应用";
+$text['label-app']['ja-jp'] = "応用";
+$text['label-app']['ko-kr'] = "애플리케이션";

+ 106 - 46
maintenance.php

@@ -1,5 +1,5 @@
 <?php
-
+declare(strict_types=1);
 /*
  * FusionPBX
  * Version: MPL 1.1
@@ -80,22 +80,43 @@ if (!empty($_REQUEST['action'])) {
 }
 
 //load the settings
-$settings = new settings(['database' => $database]);
-
-//load all classes
-$class_files = glob(dirname(__DIR__, 2) . '/*/*/resources/classes/*');
-foreach ($class_files as $file) {
-	include_once $file;
-}
-
-//get the current list of all database and filesystem maintenance classes
-$maintenance_classes = trait_classes_arr('database_maintenance', 'filesystem_maintenance');
+$default_settings = new settings(['database' => $database]);
 
 //get the list in the default settings
-$default_settings_classes = $settings->get('maintenance', 'application', []);
+$classes = $default_settings->get('maintenance', 'application', []);
+
+//get the display array
+$maintenance_apps = [];
+
+//get all domains if the user has the permission to see them
+if (permission_exists('maintenance_show_all')) {
+	foreach ($classes as $class) {
+		if (has_trait($class, 'database_maintenance')) {
+			$maintenance_apps[$class]['database_maintenance'] = $class::database_maintenance_settings($database);
+		}
+		if (has_trait($class, 'filesystem_maintenance')) {
+			$maintenance_apps[$class]['filesystem_maintenance'] = $class::filesystem_maintenance_settings($database);
+		}
+	}
+}
+else {
+	$domain_uuid = $_SESSION['domain_uuid'];
+	$domain_settings = new settings(['domain_uuid' => $domain_uuid]);
+	//get only the local domain values
+	foreach ($classes as $class) {
+		if (has_trait($class, 'database_maintenance')) {
+			$maintenance_apps[$class]['database_maintenance'][$domain_uuid]['domain_setting_value'] = $domain_settings->get($class, $class::database_retention_subcategory());
+			$maintenance_apps[$class]['database_maintenance'][$domain_uuid]['domain_setting_enabled'] = true;
+		}
+		if (has_trait($class, 'filesystem_maintenance')) {
+			$maintenance_apps[$class]['filesystem_maintenance'][$domain_uuid]['domain_setting_value'] = $domain_settings->get($class, $class::filesystem_retention_subcategory());
+			$maintenance_apps[$class]['filesystem_maintenance'][$domain_uuid]['domain_setting_enabled'] = true;
+		}
+	}
+}
 
-//compare to the installed list
-$difference = array_diff($maintenance_classes, $default_settings_classes);
+//get the list of domains
+$domain_names = maintenance::get_domain_names($database);
 
 //create the token
 $object = new token;
@@ -106,12 +127,12 @@ require_once dirname(__DIR__, 2) . '/resources/header.php';
 //show the content
 $document['title'] = $text['title-maintenance'];
 
-
 	echo "<div class='action_bar' id='action_bar'>";
-	echo "<div class='heading'><b>Maintenance (" . count($maintenance_classes) . ")</b></div>";
+	echo "<div class='heading'><b>Maintenance (" . count($classes) . ")</b></div>";
 	echo "<div class='actions'>";
 		echo button::create(['type'=>'button','label'=>$text['button-logs'],'icon'=>'fas fa-scroll fa-fw','id'=>'btn_logs', 'link'=>'maintenance_logs.php']);
 		echo button_toggle::create(['label'=>$text['button-register'],'icon'=>'fas fa-registered fa-fw']);
+		echo button_show_all::create();
 		echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
 		echo button_search::create(empty($search));
 		echo button_reset::create(empty($search));
@@ -129,44 +150,83 @@ $document['title'] = $text['title-maintenance'];
 		echo "<input type='hidden' name='search' value=\"".escape($search)."\">";
 		echo "<table class='list'>";
 			echo "<tr class='list-header'>";
-				echo "<th class='checkbox'>";
-					echo "<input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(empty($maintenance_classes) ? "style='visibility: hidden;'" : null).">";
-				echo "</th>";
 				echo "<th>Name</th>";
-				echo "<th>Registered</th>";
+				if (permission_exists('maintenance_show_all')) {
+					echo "<th>Domain</th>";
+				}
 				echo "<th>Database Enabled</th>";
 				echo "<th>Retention Days</th>";
 				echo "<th>File System Enabled</th>";
 				echo "<th>Retention Days</th>";
 			echo "</tr>";
-			foreach ($maintenance_classes as $x => $class) {
-				$installed = array_search($class, $difference) ? 'No' : 'Yes';
-				if (has_trait($class, 'database_maintenance')) {
-					$database_maintenance_retention = $settings->get($class::$database_retention_category, $class::$database_retention_subcategory, '');
-					$database_maintenance_enabled = empty($database_maintenance_retention) ? "No" : "Yes";
-				} else {
-					$database_maintenance_enabled = "";
-					$database_maintenance_retention = "";
+			//list all maintenance applications from the defaults settings for global and each domain and show if they are enabled or disabled
+			foreach ($maintenance_apps as $class => $app_settings) {
+				//make the class name more user friendly
+				$display_name = ucwords(str_replace('_', ' ', $class));
+				//display global first
+				if ((isset($app_settings['database_maintenance']['global']) || isset($app_settings['filesystem_maintenance']['global'])) && permission_exists('maintenance_show_all')) {
+					echo "<tr class='list-row' style=''>";
+						echo "<td>$display_name</td>";
+							echo "<td>" . $text['label-global'] . "</td>";
+						if (isset($app_settings['database_maintenance']['global'])) {
+							$enabled = $app_settings['database_maintenance']['global']['default_setting_enabled'] ? $text['label-yes'] : $text['label-no'];
+							$value = $app_settings['database_maintenance']['global']['default_setting_value'];
+							echo "<td>$enabled</td>";
+							echo "<td>$value</td>";
+						} else {
+							echo "<td>&nbsp;</td>";
+							echo "<td>&nbsp;</td>";
+						}
+						if (isset($app_settings['filesystem_maintenance']['global'])) {
+							$enabled = $app_settings['filesystem_maintenance']['global']['default_setting_enabled'] ? $text['label-yes'] : $text['label-no'];
+							$value = $app_settings['filesystem_maintenance']['global']['default_setting_value'];
+							echo "<td>$enabled</td>";
+							echo "<td>$value</td>";
+						} else {
+							echo "<td>&nbsp;</td>";
+							echo "<td>&nbsp;</td>";
+						}
+					echo "</tr>";
 				}
-				if (has_trait($class, 'filesystem_maintenance') ) {
-					$filesystem_maintenance_retention = $settings->get($class::$filesystem_retention_category, $class::$filesystem_retention_subcategory, '');
-					$filesystem_maintenance_enabled = empty($filesystem_maintenance_retention) ? "No" : "Yes";
-				} else {
-					$filesystem_maintenance_enabled = "";
-					$filesystem_maintenance_retention = "";
+				if (isset($app_settings['database_maintenance']) || isset($app_settings['filesystem_maintenance'])) {
+					//get all domains with database traits
+					$database_domain_uuids = array_keys($app_settings['database_maintenance'] ?? []);
+					//get all domains with filesystem traits
+					$filesystem_domain_uuids = array_keys($app_settings['filesystem_maintenance'] ?? []);
+					//combine database and filesystem domain_uuids without duplicates
+					$domain_uuids = $database_domain_uuids + $filesystem_domain_uuids;
+					//loop through domains that have the database and filesystem traits
+					foreach ($domain_uuids as $domain_uuid) {
+						//skip global it has already been done
+						if ($domain_uuid === 'global') {
+							continue;
+						}
+						echo "<tr class='list-row' style=''>";
+							echo "<td>$display_name</td>";
+							if (permission_exists('maintenance_show_all')) {
+								echo "<td>" . $domain_names[$domain_uuid] . "</td>";
+							}
+							if (isset($app_settings['database_maintenance'][$domain_uuid])) {
+								$enabled = $app_settings['database_maintenance'][$domain_uuid]['domain_setting_enabled'] ? $text['label-yes'] : $text['label-no'];
+								$value = $app_settings['database_maintenance'][$domain_uuid]['domain_setting_value'];
+								echo "<td>$enabled</td>";
+								echo "<td>$value</td>";
+							} else {
+								echo "<td>&nbsp;</td>";
+								echo "<td>&nbsp;</td>";
+							}
+							if (isset($app_settings['filesystem_maintenance'][$domain_uuid])) {
+								$enabled = $app_settings['filesystem_maintenance'][$domain_uuid]['domain_setting_enabled'] ? $text['label-yes'] : $text['label-no'];
+								$value = $app_settings['filesystem_maintenance'][$domain_uuid]['domain_setting_value'];
+								echo "<td>$enabled</td>";
+								echo "<td>$value</td>";
+							} else {
+								echo "<td>&nbsp;</td>";
+								echo "<td>&nbsp;</td>";
+							}
+						echo "</tr>";
+					}
 				}
-
-				echo "<tr class='list-row' style=''>";
-					echo "<td class='checkbox'>";
-						echo "<input type='checkbox' name='maintenance_apps[$class]' id='checkbox_$x' value='$class' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">";
-					echo "</td>";
-					echo "<td>$class</td>";
-					echo "<td ". ($installed=='No' ? "style=' background-color: var(--warning);'" : 'style=" background-color: none;"') .">$installed</td>";
-					echo "<td>$database_maintenance_enabled</td>";
-					echo "<td>$database_maintenance_retention</td>";
-					echo "<td>$filesystem_maintenance_enabled</td>";
-					echo "<td>$filesystem_maintenance_retention</td>";
-				echo "</tr>";
 			}
 		echo "</table>";
 		echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>";

+ 0 - 49
resources/classes/button_add.php

@@ -1,49 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of button_save
- *
- * @author Tim Fry <[email protected]>
- */
-class button_add extends button {
-
-	public static function create($link, $array = []): string {
-		global $text;
-		$default_values = [
-			'type' => 'submit',
-			'label' => $text['button-add'],
-			'icon' => $_SESSION['theme']['button_icon_add'] ?? 'plus',
-			'id' => 'btn_add',
-			'name' => 'action',
-			'value' => 'add',
-			'link' => $link,
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 47
resources/classes/button_back.php

@@ -1,47 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of button_back
- *
- * @author Tim Fry <[email protected]>
- */
-class button_back extends button {
-	public static function create($link, $array = []): string {
-		global $text;
-		$default_values = [
-			'type'=>'button',
-			'label'=>$text['button-back'],
-			'icon'=>$_SESSION['theme']['button_icon_back'],
-			'id'=>'btn_back',
-			'style'=>'margin-right: 15px;',
-			'link' => $link,
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 46
resources/classes/button_delete.php

@@ -1,46 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of button_delete
- *
- * @author Tim Fry <[email protected]>
- */
-class button_delete extends button {
-	public static function create($array = []): string {
-		global $text;
-		$default_values = [
-			'name'=>'btn_delete',
-			'type'=>'button',
-			'label'=>$text['button-delete'],
-			'icon'=>$_SESSION['theme']['button_icon_delete'],
-			'onclick'=>"modal_open('modal-delete','btn_delete');",
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 47
resources/classes/button_reset.php

@@ -1,47 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of button_reset
- *
- * @author Tim Fry <[email protected]>
- */
-class button_reset extends button{
-	public static function create($hidden, $array = []): string {
-		global $text;
-		$default_values = [
-			'label'=>$text['button-reset'],
-			'icon'=>$_SESSION['theme']['button_icon_reset'],
-			'type'=>'button',
-			'id'=>'btn_reset',
-			'link'=>'maintenance_logs.php',
-			'style'=>($hidden ? 'display: none;' : null)
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 47
resources/classes/button_save.php

@@ -1,47 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of button_save
- *
- * @author Tim Fry <[email protected]>
- */
-class button_save extends button {
-	public static function create($array = []): string {
-		global $text;
-		$default_values = [
-			'type'=>'submit',
-			'label'=>$text['button-save'],
-			'icon'=>$_SESSION['theme']['button_icon_save'],
-			'id'=>'btn_save',
-			'name'=>'action',
-			'value'=>'save',
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 46
resources/classes/button_search.php

@@ -1,46 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of button_search
- *
- * @author Tim Fry <[email protected]>
- */
-class button_search extends button {
-	public static function create($show, $array = []): string {
-		global $text;
-		$default_values = [
-			'label'=>$text['button-search'],
-			'icon'=>$_SESSION['theme']['button_icon_search'],
-			'type'=>'submit',
-			'id'=>'btn_search',
-			'style'=> ($show ? null : 'display: none;')
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 48
resources/classes/button_show_all.php

@@ -1,48 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of button_show_all
- *
- * @author Tim Fry <[email protected]>
- * @property string $label Alias for title
- */
-class button_show_all extends button {
-	public static function create($array = []): string {
-		global $text;
-		$default_values = [
-			'type'  => 'button',
-			'alt'   => $text['button-show_all'],
-			'label' => $text['button-show_all'],
-			'class' => 'btn btn-default',
-			'icon'  => $_SESSION['theme']['button_icon_all'] ?? 'globe',
-			'link'=>'?show=all',
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 48
resources/classes/button_toggle.php

@@ -1,48 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of button_save
- *
- * @author Tim Fry <[email protected]>
- */
-class button_toggle extends button {
-	public static function create($array = []): string {
-		global $text;
-		$default_values = [
-			'type'=>'button',
-			'label'=>$text['button-toggle'],
-			'icon'=>$_SESSION['theme']['button_icon_toggle'],
-			'id'=>'btn_toggle',
-			'name'=>'btn_toggle',
-			'style'=>'display: none;',
-			'onclick'=>"modal_open('modal-toggle','btn_toggle');"
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 98 - 9
resources/classes/maintenance.php

@@ -135,10 +135,15 @@ class maintenance {
 		}
 
 		//load all classes in the project
-		$class_files = glob(dirname(__DIR__, 2) . '/*/*/resources/classes/*.php');
+		$project_root = dirname(__DIR__, 4);
+		$class_files = glob($project_root . '/*/*/resources/classes/*.php');
 		foreach ($class_files as $file) {
-			//register the class name
-			require_once $file;
+			try {
+				//register the class name
+				include_once $file;
+			} catch (Throwable $t) {
+				//do nothing
+			}
 		}
 
 		//get the loaded declared classes in an array from the php engine
@@ -192,6 +197,90 @@ class maintenance {
 		return $registered_applications;
 	}
 
+	/**
+	 * Returns a list of default settings and domain settings tables allowing to ignore the default_setting_enabled
+	 * @param database $database Database object
+	 * @param string $subcategory_name
+	 * @return array List of retention days with the default setting UUID as the key and the retention days as the value
+	 */
+	public static function get_default_retention_days(database $database, string $subcategory_name, bool $omit_default_setting_enabled = false, bool $default_setting_enabled = true): array {
+		$default_setting_enabled_string = $default_setting_enabled ? 'true' : 'false';
+		$retention_settings = [];
+		$sql = "select default_setting_uuid, default_setting_category, default_setting_value from v_default_settings";
+		$sql .= " where default_setting_subcategory='$subcategory_name'";
+		if (!$omit_default_setting_enabled) {
+			$sql .= " and default_setting_enabled='$default_setting_enabled_string'";
+		}
+		$sql .= " group by default_setting_category, default_setting_uuid, default_setting_value";
+		$result = $database->select($sql, null, 'all');
+		if (!empty($result)) {
+			foreach ($result as $row) {
+				$app_name = $row['default_setting_category'];
+				$uuid = $row['default_setting_uuid'];
+				$value = $row['default_setting_value'];
+				$retention_settings[$app_name][$uuid] = $value;
+			}
+		}
+
+		return $retention_settings;
+	}
+
+	/**
+	 * Returns a list of default settings and domain settings tables allowing to ignore the default_setting_enabled
+	 * @param database $database Database object
+	 * @param string $category_name
+	 * @return array List of retention days with the default setting UUID as the key and the retention days as the value
+	 */
+	public static function get_domain_retention_days(database $database, string $category_name, bool $omit_default_setting_enabled = false, bool $default_setting_enabled = true): array {
+		//set defaults
+		$retention_settings = [];
+		$default_setting_enabled_string = $default_setting_enabled ? 'true' : 'false';
+		//build sql statement
+		$sql = "select default_setting_uuid, default_setting_category, default_setting_value from v_domain_settings";
+		$sql .= " where default_setting_subcategory='$category_name'";
+		if (!$omit_default_setting_enabled) {
+			$sql .= " and default_setting_enabled='$default_setting_enabled_string'";
+		}
+		//ensure the returned list is already sorted
+		$sql .= " group by default_setting_category, default_setting_uuid, default_setting_value";
+		//execute the query
+		$result = $database->select($sql, null, 'all');
+		//check result
+		if (!empty($result)) {
+			//map the results
+			foreach ($result as $row) {
+				$app_name = $row['default_setting_category'];
+				$uuid = $row['default_setting_uuid'];
+				$value = $row['default_setting_value'];
+				//two-dimensional array of name & uuid set to value
+				$retention_settings[$app_name][$uuid] = $value;
+			}
+		}
+		//return settings
+		return $retention_settings;
+	}
+
+	/**
+	 * Returns an array of domain names with their domain UUID as the array key
+	 * @param database $database
+	 * @param bool $ignore_domain_enabled
+	 * @return array
+	 */
+	public static function get_domain_names(database $database, bool $ignore_domain_enabled = false): array {
+		$domains = [];
+		$sql = "select domain_uuid, domain_name from v_domains";
+		if (!$ignore_domain_enabled) {
+			$sql .= " where domain_enabled='true'";
+		}
+		$result = $database->select($sql);
+		if (!empty($result)) {
+			foreach ($result as $row) {
+				$domains[$row['domain_uuid']] = $row['domain_name'];
+			}
+		}
+		return $domains;
+	}
+
 	/**
 	 * Registers the list of applications given in the $maintenance_apps array to the global default settings
 	 * @param database $database
@@ -259,7 +348,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
 	 * <p><b>default setting category</b>: class name that has the <code>use database_maintenance;</code> statement<br>
-	 * <b>default setting subcategory</b>: "database_retention_days"<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>description</b>: "Number of days the maintenance application will keep the information."<br>
 	 * </p>
@@ -274,9 +363,9 @@ class maintenance {
 		//get the application settings from the object for database maintenance
 		if (has_trait($application, 'database_maintenance')) {
 			//the trait has this value defined
-			$category = $application::$database_retention_category;
+			$category = $application::database_retention_category();
 			//the trait has this value defined
-			$subcategory = $application::$database_retention_subcategory;
+			$subcategory = $application::database_retention_subcategory();
 			//check if the default setting already exists in global default settings table
 			$uuid = self::default_setting_uuid($database, $category, $subcategory);
 			if (empty($uuid)) {
@@ -298,7 +387,7 @@ class maintenance {
 	/**
 	 * Updates the array with a file system 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 filesystem_maintenance;</code> statement<br>
-	 * <b>default setting subcategory:</b> "filesystem_retention_days"<br>
+	 * <b>default setting subcategory:</b> "filesystem_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>description:</b> "Number of days the maintenance application will keep the information."<br>
 	 * </p>
@@ -312,9 +401,9 @@ class maintenance {
 	private static function add_filesystem_maintenance_to_array($database, $application, $description, &$array, &$index) {
 		if (has_trait($application, 'filesystem_maintenance')) {
 			//the trait has this value defined
-			$category = $application::$filesystem_retention_category;
+			$category = $application::filesystem_retention_category();
 			//the trait has this value defined
-			$subcategory = $application::$filesystem_retention_subcategory;
+			$subcategory = $application::filesystem_retention_subcategory();
 			//check if the default setting already exists in global settings
 			$uuid = self::default_setting_uuid($database, $category, $subcategory);
 			if (empty($uuid)) {

+ 0 - 53
resources/classes/modal_copy.php

@@ -1,53 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of modal_toggle
- *
- * @author Tim Fry <[email protected]>
- */
-class modal_copy extends modal {
-
-	public static function create($form_id, $array = []): string {
-		global $text;
-		$default_values = [
-			'id'=>'modal-copy',
-			'type'=>'copy',
-			'actions'=> button::create([
-				'type'=>'button',
-				'label'=>$text['button-continue'],
-				'icon'=>'check',
-				'id'=>'btn_copy',
-				'style'=>'float: right; margin-left: 15px;',
-				'collapse'=>'never',
-				'onclick'=>"modal_close(); list_action_set('copy'); list_form_submit($form_id);"
-			])
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 53
resources/classes/modal_delete.php

@@ -1,53 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of modal_toggle
- *
- * @author Tim Fry <[email protected]>
- */
-class modal_delete extends modal {
-
-	public static function create($form_id, $array = []): string {
-		global $text;
-		$default_values = [
-			'id'=>'modal-delete',
-			'type'=>'delete',
-			'actions'=> button::create([
-				'type'=>'button',
-				'label'=>$text['button-continue'],
-				'icon'=>'check',
-				'id'=>'btn_delete',
-				'style'=>'float: right; margin-left: 15px;',
-				'collapse'=>'never',
-				'onclick'=>"modal_close(); list_action_set('delete'); list_form_submit($form_id);"
-			])
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 0 - 53
resources/classes/modal_toggle.php

@@ -1,53 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- * Description of modal_toggle
- *
- * @author Tim Fry <[email protected]>
- */
-class modal_toggle extends modal {
-
-	public static function create($form_id, $array = []): string {
-		global $text;
-		$default_values = [
-			'id'=>'modal-toggle',
-			'type'=>'toggle',
-			'actions'=> button::create([
-				'type'=>'button',
-				'label'=>$text['button-continue'],
-				'icon'=>'check',
-				'id'=>'btn_toggle',
-				'style'=>'float: right; margin-left: 15px;',
-				'collapse'=>'never',
-				'onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('$form_id');"
-			])
-		];
-		return parent::create(array_merge($default_values, $array));
-	}
-}

+ 11 - 10
resources/dashboard/maintenance.php

@@ -157,8 +157,8 @@
 			//check for database status
 			if (has_trait($maintenance_app, 'database_maintenance')) {
 				$total_maintenance_apps++;
-				$category = $maintenance_app::$database_retention_category;
-				$subcategory = $maintenance_app::$database_retention_subcategory;
+				$category = $maintenance_app::database_retention_category();
+				$subcategory = $maintenance_app::database_retention_subcategory();
 				if (!empty($setting->get($category, $subcategory, ''))) {
 					$total_running_maintenance_apps++;
 				}
@@ -166,8 +166,8 @@
 			//check for filesystem status
 			if (has_trait($maintenance_app, 'filesystem_maintenance')) {
 				$total_maintenance_apps++;
-				$category = $maintenance_app::$filesystem_retention_category;
-				$subcategory = $maintenance_app::$filesystem_retention_subcategory;
+				$category = $maintenance_app::filesystem_retention_category();
+				$subcategory = $maintenance_app::filesystem_retention_subcategory();
 				if(!empty($setting->get($category, $subcategory, ''))) {
 					$total_running_maintenance_apps++;
 				}
@@ -210,7 +210,7 @@ if (true) {
 				echo "<button type='button' alt='Save' title='Save' onclick=\"list_form_submit('form_list_maintainers');\" class='btn btn-default ' style='position: absolute; margin-top: -35px; margin-left: -72px;'><span class='fas fa-bolt fa-fw'></span><span class='button-label  pad'>Save</span></button>";
 				echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0' border='0'>";
 					echo "<tr style='position: -webkit-sticky; position: sticky; z-index: 5; top: 0; left: 2px;'>";
-						echo "<th class='hud_heading' style='width: 40%;'>".($text['label-maintenance_application'] ?? 'Maintenance Application')."</th>";
+						echo "<th class='hud_heading' style='width: 40%;'>".($text['label-app'] ?? 'Application')."</th>";
 						echo "<th class='hud_heading' style='width: 15%;'>".'Database'."</th>";
 						echo "<th class='hud_heading' style='width: 15%;'>".'Days'."</th>";
 						echo "<th class='hud_heading' style='width: 15%;'>".'Filesystem'."</th>";
@@ -231,8 +231,8 @@ if (true) {
 						if (class_exists($maintenance_app)) {
 							//check for database status
 							if (has_trait($maintenance_app, 'database_maintenance')) {
-								$database_category = $maintenance_app::$database_retention_category;
-								$database_subcategory = $maintenance_app::$database_retention_subcategory;
+								$database_category = $maintenance_app::database_retention_category();
+								$database_subcategory = $maintenance_app::database_retention_subcategory();
 								$database_default_value = $maintenance_app::database_retention_default_value();
 								$database_days = $setting->get($database_category, $database_subcategory, '');
 								//uuid of setting
@@ -248,8 +248,8 @@ if (true) {
 
 							//check for filesystem status
 							if (has_trait($maintenance_app, 'filesystem_maintenance')) {
-								$filesystem_category = $maintenance_app::$filesystem_retention_category;
-								$filesystem_subcategory = $maintenance_app::$filesystem_retention_subcategory;
+								$filesystem_category = $maintenance_app::filesystem_retention_category();
+								$filesystem_subcategory = $maintenance_app::filesystem_retention_subcategory();
 								$filesystem_default_value = $maintenance_app::filesystem_retention_default_value();
 								$filesystem_days = $setting->get($filesystem_category, $filesystem_subcategory, '');
 								//uuid of setting
@@ -276,7 +276,8 @@ if (true) {
 						}
 						//display the maintanence application
 						echo "<tr>";
-							echo "<td valign='top' class='".$row_style[$c]." hud_text'>$maintenance_app</td>";
+							$display_name = ucwords(str_replace('_', ' ', $maintenance_app));
+							echo "<td valign='top' class='".$row_style[$c]." hud_text'>$display_name</td>";
 							//
 							// Database apps
 							//

+ 0 - 73
resources/interfaces/database_maintenance.php

@@ -1,73 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- *
- * @author Tim Fry <[email protected]>
- */
-trait database_maintenance {
-
-	public static $database_maintenance_application = self::class;
-	public static $database_retention_category = self::class;
-	public static $database_retention_subcategory = 'database_retention_days';
-
-	//class must implement this method
-	abstract public static function database_maintenance_sql(string $domain_uuid, string $retention_days): string;
-
-	/**
-	 * Class can override this method to return the default value
-	 * @return string
-	 */
-	public static function database_retention_default_value(): string {
-		return '30';
-	}
-
-	/**
-	 * Class can override this method to do their own maintenance or just return the sql for this method
-	 * @return string
-	 */
-	public static function database_maintenance(database $database, settings $settings): void {
-		//get retention days
-		$days = $settings->get(self::$database_retention_category, self::$database_retention_subcategory, '');
-		//look for old entries
-		if (!empty($days) && is_numeric($days)) {
-			$domains = maintenance_service::get_domains($database);
-			foreach ($domains as $domain_uuid => $domain_name) {
-				$database->execute(self::database_maintenance_sql($domain_uuid, $days));
-				if ($database->message['code'] === '200') {
-					maintenance_service::log_write(self::$database_maintenance_application, "Removed maintenance log entries older than $days days", $domain_uuid);
-				} else {
-					maintenance_service::log_write(self::$database_maintenance_application, "Failed to clear entries", $domain_uuid, maintenance_service::LOG_ERROR);
-				}
-			}
-		} else {
-			//database retention not set or not a valid number
-			maintenance_service::log_write(self::$database_maintenance_application, 'Retention days not set', '', maintenance_service::LOG_ERROR);
-		}
-	}
-}

+ 0 - 86
resources/interfaces/filesystem_maintenance.php

@@ -1,86 +0,0 @@
-<?php
-
-/*
- * FusionPBX
- * Version: MPL 1.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is FusionPBX
- *
- * The Initial Developer of the Original Code is
- * Mark J Crane <[email protected]>
- * Portions created by the Initial Developer are Copyright (C) 2008-2024
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Mark J Crane <[email protected]>
- * Tim Fry <[email protected]>
- */
-
-/**
- *
- * @author Tim Fry <[email protected]>
- */
-trait filesystem_maintenance {
-
-	public static $filesystem_maintenance_application = self::class;
-	public static $filesystem_retention_category = self::class;
-	public static $filesystem_retention_subcategory = 'filesystem_retention_days';
-
-	//class must implement this method
-	abstract public static function filesystem_maintenance_files(settings $settings, string $domain_uuid, string $domain_name, string $retention_days): array;
-
-	/**
-	 * Default setting for global default values when it is created
-	 * @return string
-	 */
-	public static function filesystem_retention_default_value(): string {
-		return '30';
-	}
-
-	/**
-	 * Removes old files on a per-domain basis
-	 * @param database $database
-	 * @param settings $settings
-	 * @return void
-	 */
-	public static function filesystem_maintenance(database $database, settings $settings): void {
-		//get retention days
-		$days = $settings->get(self::$filesystem_retention_category, self::$filesystem_retention_subcategory, '');
-		//look for old entries
-		if (!empty($days) && is_numeric($days)) {
-			$domains = maintenance_service::get_domains($database);
-			//loop over domains
-			foreach ($domains as $domain_uuid => $domain_name) {
-				//assign the settings object
-				$domain_settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]);
-				$files = self::filesystem_maintenance_files($domain_settings, $domain_uuid, $domain_name, $days);
-				//loop over each file in the domain
-				foreach ($files as $file) {
-					//check if it is old enough
-					if (maintenance_service::days_since_created($file) > $days) {
-						if (unlink($file)) {
-							//successfully deleted file
-							maintenance_service::log_write(self::$filesystem_maintenance_application, "Removed $file", $domain_uuid);
-						} else {
-							//failed
-							maintenance_service::log_write(self::$filesystem_maintenance_application, "Unabled to remove $file", $domain_uuid, maintenance_service::LOG_ERROR);
-						}
-					}
-				}
-			}
-		} else {
-			//filesystem retention not set or not a valid number
-			maintenance_service::log_write(self::$filesystem_maintenance_application, 'Retention days not set', '', maintenance_service::LOG_ERROR);
-		}
-	}
-}

+ 130 - 0
resources/traits/database_maintenance.php

@@ -0,0 +1,130 @@
+<?php
+
+/*
+ * FusionPBX
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FusionPBX
+ *
+ * The Initial Developer of the Original Code is
+ * Mark J Crane <[email protected]>
+ * Portions created by the Initial Developer are Copyright (C) 2008-2024
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Mark J Crane <[email protected]>
+ * Tim Fry <[email protected]>
+ */
+
+/**
+ *
+ * @author Tim Fry <[email protected]>
+ */
+trait database_maintenance {
+
+	public static $database_maintenance_application = self::class;
+
+	//class must implement this method
+	abstract public static function database_maintenance_sql(string $domain_uuid, string $retention_days): string;
+
+	/**
+	 * The class may override this method by returning a different value to use for the default settings category
+	 * @return string Value to use in the default settings for a category name
+	 */
+	public static function database_retention_category(): string{ return self::class; }
+
+	/**
+	 * The class may override this method by returning a different value to use for the default settings subcategory
+	 * @return string value to use in the default settings for a subcategory (name of the setting)
+	 */
+	public static function database_retention_subcategory(): string { return "database_retention_days"; }
+
+	/**
+	 * Class can override this method to return the default value
+	 * @return string
+	 */
+	public static function database_retention_default_value(): string {
+		return '30';
+	}
+
+	/**
+	 * Class can override this method to do their own maintenance or just return the sql for this method
+	 * @return string
+	 */
+	public static function database_maintenance(database $database, settings $settings): void {
+		//get retention days
+		$days = $settings->get(self::database_retention_category(), self::database_retention_subcategory(), '');
+		//look for old entries
+		if (!empty($days) && is_numeric($days)) {
+			$domains = maintenance_service::get_domains($database);
+			foreach ($domains as $domain_uuid => $domain_name) {
+				$database->execute(self::database_maintenance_sql($domain_uuid, $days));
+				if ($database->message['code'] === '200') {
+					maintenance_service::log_write(self::$database_maintenance_application, "Removed maintenance log entries older than $days days", $domain_uuid);
+				} else {
+					maintenance_service::log_write(self::$database_maintenance_application, "Failed to clear entries", $domain_uuid, maintenance_service::LOG_ERROR);
+				}
+			}
+		} else {
+			//database retention not set or not a valid number
+			maintenance_service::log_write(self::$database_maintenance_application, 'Retention days not set', '', maintenance_service::LOG_ERROR);
+		}
+	}
+
+	/**
+	 * Creates a list of categories that have the database_retention_days even when the setting is disabled.
+	 * @param database $database Database object
+	 * @param bool $enabled Used internally
+	 * @return array Two-dimensional array for returning the category and settings value. The key is the UUID of the domain or 'global'.
+	 */
+	public static function database_maintenance_settings(database $database, bool $enabled = true): array {
+		//get the false values first and then overwrite them with true
+		if ($enabled) {
+			$settings = self::database_maintenance_settings($database, false);
+		} else {
+			$settings = [];
+		}
+		$status_string = $enabled ? 'true' : 'false';
+		$category = self::database_retention_category();
+		$subcategory = self::database_retention_subcategory();
+		//get the global settings
+		$sql = "select default_setting_value, default_setting_uuid from v_default_settings";
+		$sql .= " where default_setting_category = '$category'";
+		$sql .= " and default_setting_subcategory = '$subcategory'";
+		$sql .= " and default_setting_enabled = '$status_string'";
+		$sql .= " limit 1";
+		$global_results = $database->select($sql);
+		if (!empty($global_results)) {
+			foreach ($global_results as $row) {
+				$settings['global']['default_setting_uuid'] = $row['default_setting_uuid'];
+				$settings['global']['default_setting_value'] = $row['default_setting_value'];
+				$settings['global']['default_setting_enabled'] = $enabled;
+			}
+		}
+
+		//get the per domain settings
+		$sql = "select domain_uuid, domain_setting_uuid, domain_setting_enabled, domain_setting_value from v_domain_settings";
+		$sql .= " where domain_setting_category = '$category'";
+		$sql .= " and domain_setting_subcategory = '$subcategory'";
+		$sql .= " and domain_setting_enabled = '$status_string'";
+		$domain_results = $database->select($sql);
+		if (!empty($domain_results)) {
+			foreach ($domain_results as $row) {
+				$settings[$row['domain_uuid']]['domain_setting_uuid'] = $row['domain_setting_uuid'];
+				$settings[$row['domain_uuid']]['domain_setting_enabled'] = $row['domain_setting_enabled'];
+				$settings[$row['domain_uuid']]['domain_setting_value'] = $row['domain_setting_value'];
+			}
+		}
+		return $settings;
+	}
+}

+ 148 - 0
resources/traits/filesystem_maintenance.php

@@ -0,0 +1,148 @@
+<?php
+
+/*
+ * FusionPBX
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FusionPBX
+ *
+ * The Initial Developer of the Original Code is
+ * Mark J Crane <[email protected]>
+ * Portions created by the Initial Developer are Copyright (C) 2008-2024
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Mark J Crane <[email protected]>
+ * Tim Fry <[email protected]>
+ */
+
+/**
+ *
+ * @author Tim Fry <[email protected]>
+ */
+trait filesystem_maintenance {
+
+	//the class name is used to track loading the object that uses the filesystem_maintenance
+	//this value will appear in the default settings under maintenace->application
+	public static $filesystem_maintenance_application = self::class;
+
+	//class must implement this method
+	abstract public static function filesystem_maintenance_files(settings $settings, string $domain_uuid, string $domain_name, string $retention_days): array;
+
+	/**
+	 * The class may override this method by returning a different value to use for the default settings category
+	 * @return string Value to use in the default settings for a category name
+	 */
+	public static function filesystem_retention_category(): string{ return self::class; }
+
+	/**
+	 * The class may override this method by returning a different value to use for the default settings subcategory
+	 * @return string value to use in the default settings for a subcategory (name of the setting)
+	 */
+	public static function filesystem_retention_subcategory(): string { return "filesystem_retention_days"; }
+
+	/**
+	 * Default setting for global default values when it is created
+	 * @return string
+	 */
+	public static function filesystem_retention_default_value(): string {
+		return '30';
+	}
+
+	/**
+	 * Removes old files on a per-domain basis
+	 * @param database $database
+	 * @param settings $settings
+	 * @return void
+	 */
+	public static function filesystem_maintenance(database $database, settings $settings): void {
+		//get retention days
+		$days = $settings->get(self::filesystem_retention_category(), self::filesystem_retention_subcategory(), '');
+		//look for old entries
+		if (!empty($days) && is_numeric($days)) {
+			$domains = maintenance_service::get_domains($database);
+			//loop over domains
+			foreach ($domains as $domain_uuid => $domain_name) {
+				//assign the settings object
+				$domain_settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]);
+				$files = self::filesystem_maintenance_files($domain_settings, $domain_uuid, $domain_name, $days);
+				//loop over each file in the domain
+				foreach ($files as $file) {
+					//check if it is old enough
+					if (maintenance_service::days_since_created($file) > $days) {
+						if (unlink($file)) {
+							//successfully deleted file
+							maintenance_service::log_write(self::$filesystem_maintenance_application, "Removed $file", $domain_uuid);
+						} else {
+							//failed
+							maintenance_service::log_write(self::$filesystem_maintenance_application, "Unabled to remove $file", $domain_uuid, maintenance_service::LOG_ERROR);
+						}
+					}
+				}
+			}
+		} else {
+			//filesystem retention not set or not a valid number
+			maintenance_service::log_write(self::$filesystem_maintenance_application, 'Retention days not set', '', maintenance_service::LOG_ERROR);
+		}
+	}
+
+	/**
+	 * Creates a list of categories that have the filesystem_retention_days even when the setting is disabled.
+	 * @param database $database Database object
+	 * @param bool $enabled Used internally
+	 * @return array Two-dimensional array for returning the category and settings value. The key is the UUID of the domain or 'global'.
+	 */
+	public static function filesystem_maintenance_settings(database $database, bool $enabled = true): array {
+		//get the false values first and then overwrite them with true
+		if ($enabled) {
+			$settings = self::filesystem_maintenance_settings($database, false);
+		} else {
+			$settings = [];
+		}
+		$parameters = [];
+		$status_string = $enabled ? 'true' : 'false';
+		$category = self::filesystem_retention_category();
+		$subcategory = self::filesystem_retention_subcategory();
+		$parameters['category'] = $category;
+		//get the global settings
+		$sql = "select default_setting_value, default_setting_uuid from v_default_settings";
+		$sql .= " where default_setting_category = :category";
+		$sql .= " and default_setting_subcategory = '$subcategory'";
+		$sql .= " and default_setting_enabled = '$status_string'";
+		$sql .= " limit 1";
+		$global_results = $database->select($sql, $parameters);
+		if (!empty($global_results)) {
+			foreach ($global_results as $row) {
+				$settings['global']['default_setting_uuid'] = $row['default_setting_uuid'];
+				$settings['global']['default_setting_value'] = $row['default_setting_value'];
+				$settings['global']['default_setting_enabled'] = $enabled;
+			}
+		}
+
+		//get the per domain settings
+		$sql = "select domain_uuid, domain_setting_uuid, domain_setting_enabled, domain_setting_value from v_domain_settings";
+		$sql .= " where default_setting_category = :category";
+		$sql .= " and domain_setting_subcategory = '$subcategory'";
+		$sql .= " and domain_setting_enabled = '$status_string'";
+		$domain_results = $database->select($sql, $parameters);
+		if (!empty($domain_results)) {
+			foreach ($domain_results as $row) {
+				$settings[$row['domain_uuid']]['domain_setting_uuid'] = $row['domain_setting_uuid'];
+				$settings[$row['domain_uuid']]['domain_setting_enabled'] = $row['domain_setting_enabled'];
+				$settings[$row['domain_uuid']]['domain_setting_value'] = $row['domain_setting_value'];
+			}
+		}
+		return $settings;
+	}
+
+}