Documentation, format class, no modification. (#7628)

This commit is contained in:
frytimo
2025-11-18 21:49:39 -04:00
committed by GitHub
parent adfc4cc469
commit bbe7b9e9b7
37 changed files with 5051 additions and 4144 deletions

View File

@@ -578,9 +578,15 @@
}
/**
* Update file system permissions
* Update file permissions for a FusionPBX installation.
*
* This function updates the permissions of various directories in a FusionPBX installation,
* specifically adjusting ownership to match the expected behavior. The changes are only applied
* when running as root, and an error message is displayed otherwise.
*
* @param array $text A translation dictionary containing the label for when not running as root.
* @param settings $settings The current application settings instance.
*/
function update_file_permissions($text, settings $settings) {
@@ -640,7 +646,14 @@ function update_file_permissions($text, settings $settings) {
}
/**
* Upgrade services
* Upgrade services by copying and enabling them in systemd.
*
* This function iterates through all service files found in the application's
* core and app directories, copies each one to /etc/systemd/system, reloads
* the daemon, and enables the service.
*
* @param string $text Text containing the upgrade description (not used)
* @param settings $settings Application settings
*/
function upgrade_services($text, settings $settings) {
//echo ($text['description-upgrade_services'] ?? "")."\n";
@@ -657,7 +670,13 @@ function upgrade_services($text, settings $settings) {
}
/**
* Stop services
* Stops running services by name.
*
* This function iterates over all service files, extracts the service names,
* and stops each service using systemctl.
*
* @param array $text
* @param settings $settings
*/
function stop_services($text, settings $settings) {
//echo ($text['description-stop_services'] ?? "")."\n";
@@ -672,7 +691,12 @@ function stop_services($text, settings $settings) {
}
/**
* Restart services
* Restarts all services
*
* This function restarts all core and app services.
*
* @param array $text Array containing localized text
* @param settings $settings Settings object
*/
function restart_services($text, settings $settings) {
//echo ($text['description-restart_services'] ?? "")."\n";
@@ -687,8 +711,11 @@ function restart_services($text, settings $settings) {
}
/**
* Get the service name
* @param string $file
* Finds the service name in an INI file from a given file.
*
* @param string $file The fully qualified path and file containing the ExecStart command.
*
* @return string|null The service name if found, otherwise an empty string.
*/
function find_service_name(string $file) {
$parsed = parse_ini_file($file);
@@ -703,9 +730,9 @@ function find_service_name(string $file) {
}
/**
* Checks if the current user has root privileges.
* Checks whether the current user is the root user or not.
*
* @return bool Returns true if the current user is the root user, false otherwise.
* @return bool True if the current user has root privileges, false otherwise.
*/
function is_root(): bool {
return posix_getuid() === 0;

View File

@@ -52,9 +52,18 @@ $display_type = 'text';
show_upgrade_menu();
/**
* Show upgrade menu
* @global type $text
* @global type $software_name
* Display the upgrade menu to the user.
*
* This function displays a menu with various upgrade options and prompts the
* user for input. Based on the user's selection, it performs the corresponding
* actions such as upgrading code, schema, auto loader, domains, menu,
* permissions, file permissions, services, or restarting services.
*
* @return void
*
* @global text $text
* @global string $software_name
* @global settings $settings
*/
function show_upgrade_menu() {
//set the global variables
@@ -90,7 +99,7 @@ function show_upgrade_menu() {
//show the command menu
echo "Options:\n";
foreach ($options as list($key, $label, $description)) {
foreach ($options as [$key, $label, $description]) {
if (!is_numeric($key)) { echo " "; }
echo " $key) $label" . ((!empty($option) && $option == 'h') ? " - " . $description : "") . "\n";
}
@@ -172,8 +181,12 @@ function show_upgrade_menu() {
}
/**
* Rebuild the cache file
* @global type $text
* Upgrade auto loader by removing temporary files and updating it.
*
* @return void
*
* @global text $text
* @global auto_loader $autoload
*/
function do_upgrade_auto_loader() {
global $text, $autoload;
@@ -188,7 +201,10 @@ function do_upgrade_auto_loader() {
}
/**
* Update file system permissions
* Update file permissions for the application.
*
* @param array $text Array of text to display to the user.
* @param settings $settings Settings object containing various configuration options.
*/
function do_file_permissions($text, settings $settings) {
@@ -256,18 +272,33 @@ function do_file_permissions($text, settings $settings) {
}
}
/**
* Returns the name of the currently logged in user.
*
* @return string|null The username of the current user, or null if not available
*/
function current_user(): ?string {
return posix_getpwuid(posix_getuid())['name'] ?? null;
}
//show the upgrade type
/**
* Returns a string containing the current version of the software.
*
* @return string|null The software version as a string, or null if not available.
*/
function show_software_version(): ?string {
return software::version() . "\n";
}
/**
* Upgrade the source folder
* @return type
* Upgrade code by pulling the latest changes from version control.
*
* If the pull operation is successful, no result message will be returned.
* Otherwise, a result array containing 'result' set to false and a 'message'
* detailing the failure will be returned.
*
* @return null A result array or null on success
*/
function do_upgrade_code() {
//assume failed
@@ -284,8 +315,7 @@ function do_upgrade_code() {
}
/**
* Upgrade any of the git submodules
* @global type $text
* Upgrade code submodules by pulling the latest changes from Git repositories.
*/
function do_upgrade_code_submodules() {
global $text;
@@ -312,7 +342,7 @@ function do_upgrade_code_submodules() {
}
/**
* Execute all app_defaults.php files
* Perform upgrade on domains.
*/
function do_upgrade_domains() {
$domain = new domains;
@@ -320,7 +350,11 @@ function do_upgrade_domains() {
}
/**
* Upgrade schema and/or data_types
* Upgrades the database schema to the latest version.
*
* @param bool $data_types Whether or not to include data types in the upgrade process. Defaults to false.
*
* @return void
*/
function do_upgrade_schema(bool $data_types = false) {
//get the database schema put it into an array then compare and update the database as needed.
@@ -330,7 +364,9 @@ function do_upgrade_schema(bool $data_types = false) {
}
/**
* Restore the default menu
* Upgrades the menu and restores it to its default state.
*
* @return void
*/
function do_upgrade_menu() {
//define the global variables
@@ -365,7 +401,9 @@ function do_upgrade_menu() {
}
/**
* Restore the default permissions
* Upgrades database permissions to the latest version.
*
* @return void
*/
function do_upgrade_permissions() {
//define the global variables
@@ -381,7 +419,10 @@ function do_upgrade_permissions() {
}
/**
* Default upgrade schema and app defaults
* Performs default upgrades to the application, including multi-lingual support,
* database schema updates, and running of app_defaults.php files.
*
* @return void
*/
function do_upgrade_defaults() {
//add multi-lingual support
@@ -406,7 +447,14 @@ function do_upgrade_defaults() {
}
/**
* Upgrade services
* Upgrades the services to the latest version.
*
* This function upgrades all service files and enables them as systemd services.
*
* @param string $text An array containing upgrade information. The 'description-upgrade_services' key is used for informational messages.
* @param settings $settings Configuration settings object.
*
* @return void
*/
function do_upgrade_services($text, settings $settings) {
echo ($text['description-upgrade_services'] ?? "")."\n";
@@ -423,8 +471,11 @@ function do_upgrade_services($text, settings $settings) {
}
/**
* Get the service name
* @param string $file
* Retrieves the name of a service from an .ini file.
*
* @param string $file Path to the .ini file containing service information.
*
* @return string The name of the service, or empty string if not found.
*/
function get_service_name(string $file) {
$parsed = parse_ini_file($file);
@@ -438,19 +489,22 @@ function get_service_name(string $file) {
return '';
}
/**
* Checks if the current user has root privileges.
* Checks if the current user is the root user.
*
* @return bool Returns true if the current user is the root user, false otherwise.
* @return bool True if the user is the root user, false otherwise.
*/
function is_root_user(): bool {
return posix_getuid() === 0;
}
/**
* Restart services
* Restarts services defined in the system.
*
* @param array $text An array of strings for service descriptions.
* @param object $settings An instance of the settings class, not used in this function.
*
* @return void
*/
function do_restart_services($text, settings $settings) {
echo ($text['description-restart_services'] ?? "")."\n";
@@ -465,8 +519,13 @@ function do_restart_services($text, settings $settings) {
}
/**
* Load the old config.php file
* @return type
* Loads configuration from a PHP file and writes it to a new configuration file.
*
* If the configuration file does not exist but the config.php file is present,
* the settings in the config.php file are used as defaults for the new
* configuration file. The config directory is created if it does not exist.
*
* @return void
*/
function load_config_php() {
//if the config file doesn't exist and the config.php does exist use it to write a new config file