From 5e6ec475dfe23bf017dfbbf1564bc2ac6288e85d Mon Sep 17 00:00:00 2001 From: frytimo Date: Sat, 15 Feb 2025 13:44:46 -0400 Subject: [PATCH] update auto_loader cache file when updating (#7255) --- core/upgrade/index.php | 39 +++++++++++++++++++++---- core/upgrade/upgrade.php | 5 ++++ core/upgrade/upgrade_menu.php | 47 +++++++++++++++++++------------ resources/classes/auto_loader.php | 5 ++-- 4 files changed, 71 insertions(+), 25 deletions(-) diff --git a/core/upgrade/index.php b/core/upgrade/index.php index 8c74e89acd..f9ed6c7c77 100644 --- a/core/upgrade/index.php +++ b/core/upgrade/index.php @@ -43,13 +43,13 @@ exit; } -//connect to the database - $database = new database; - //add multi-lingual support $language = new text; $text = $language->get(); +//connect to the database + $database = database::new(); + //set a default message_timeout $message_timeout = 4*1000; @@ -76,7 +76,7 @@ //process the http post if (!empty($_POST) && @sizeof($_POST) > 0) { - //get the action options: source, schema, app_defaults, menu_defaults, permisisons + //get the action options: source, schema, app_defaults, menu_defaults, permissions $action = $_POST['action'] ?? null; //run source update @@ -92,6 +92,12 @@ else { message::add($text['message-upgrade_source_failed'], 'negative', $message_timeout); } + + global $autoload; + if ($autoload !== null && $autoload instanceof auto_loader) { + $autoload->reload_classes(); + $autoload->update_cache(); + } } //run optional app source updates @@ -116,6 +122,13 @@ if ($apps_updated != 0) { message::add($text['message-optional_apps_upgrade_source'], null, $message_timeout); } if ($apps_failed != 0) { message::add($text['message-optional_apps_upgrade_source_failed'], 'negative', $message_timeout); } + //update the auto_loader cache just-in-case the source files have updated + global $autoload; + if ($autoload !== null && $autoload instanceof auto_loader) { + $autoload->reload_classes(); + $autoload->update_cache(); + } + } //load an array of the database schema and compare it with the active database @@ -131,7 +144,13 @@ //process the apps defaults if (!empty($action["app_defaults"]) && permission_exists("upgrade_apps")) { - require_once "resources/classes/domains.php"; + //update the auto_loader cache just-in-case the source files have updated + global $autoload; + if ($autoload !== null && $autoload instanceof auto_loader) { + $autoload->reload_classes(); + $autoload->update_cache(); + } + $domain = new domains; $domain->upgrade(); message::add($text['message-upgrade_apps'], null, $message_timeout); @@ -139,6 +158,11 @@ //restore defaults of the selected menu if (!empty($action["menu_defaults"]) && permission_exists("menu_restore")) { + global $autoload; + if ($autoload !== null && $autoload instanceof auto_loader) { + $autoload->reload_classes(); + $autoload->update_cache(); + } $sel_menu = explode('|', check_str($_POST["sel_menu"])); $menu_uuid = $sel_menu[0]; $menu_language = $sel_menu[1]; @@ -151,6 +175,11 @@ //restore default permissions if (!empty($action["permission_defaults"]) && permission_exists("group_edit")) { + global $autoload; + if ($autoload !== null && $autoload instanceof auto_loader) { + $autoload->reload_classes(); + $autoload->update_cache(); + } $included = true; require_once("core/groups/permissions_default.php"); $text = $language->get(null, '/core/upgrade'); diff --git a/core/upgrade/upgrade.php b/core/upgrade/upgrade.php index e196cb4193..376c3b0a22 100644 --- a/core/upgrade/upgrade.php +++ b/core/upgrade/upgrade.php @@ -177,6 +177,11 @@ exit(); } +//always update the auto_loader cache just-in-case the source files have updated + $auto_loader = new auto_loader(); + $auto_loader->reload_classes(); + $auto_loader->update_cache(); + //get the version of the software if ($upgrade_type == 'version') { echo software::version()."\n"; diff --git a/core/upgrade/upgrade_menu.php b/core/upgrade/upgrade_menu.php index d167930bd1..e2497f80f9 100644 --- a/core/upgrade/upgrade_menu.php +++ b/core/upgrade/upgrade_menu.php @@ -77,14 +77,13 @@ function show_upgrade_menu() { echo "1) {$text['label-upgrade_source']} - {$text['description-update_all_source_files']}\n"; echo " 1a) " . $software_name . " - Update Main Software Only \n"; echo " 1b) {$text['label-update_external_repositories']} - {$text['description-repositories']}\n"; - echo "2) {$text['label-update_auto_loader']} - {$text['description-update_auto_loader']}\n"; - echo "3) {$text['label-schema']} - {$text['description-upgrade_schema']}\n"; - echo " 3b) {$text['label-upgrade_data_types']} - {$text['description-upgrade_data_types']}\n"; - echo "4) {$text['label-upgrade_apps']} - {$text['description-upgrade_apps']}\n"; - echo "5) {$text['label-upgrade_menu']} - {$text['description-upgrade_menu']}\n"; - echo "6) {$text['label-upgrade_permissions']} - {$text['description-upgrade_permissions']}\n"; - echo "7) {$text['label-update_filesystem_permissions']} - {$text['description-update_filesystem_permissions']}\n"; - echo "8) {$text['label-all_of_the_above']} - {$text['description-all_of_the_above']}\n"; + echo "2) {$text['label-schema']} - {$text['description-upgrade_schema']}\n"; + echo " 2b) {$text['label-upgrade_data_types']} - {$text['description-upgrade_data_types']}\n"; + echo "3) {$text['label-upgrade_apps']} - {$text['description-upgrade_apps']}\n"; + echo "4) {$text['label-upgrade_menu']} - {$text['description-upgrade_menu']}\n"; + echo "5) {$text['label-upgrade_permissions']} - {$text['description-upgrade_permissions']}\n"; + echo "6) {$text['label-update_filesystem_permissions']} - {$text['description-update_filesystem_permissions']}\n"; + echo "7) {$text['label-all_of_the_above']} - {$text['description-all_of_the_above']}\n"; echo "0) Exit\n"; echo "\n"; echo "Choice: "; @@ -93,35 +92,39 @@ function show_upgrade_menu() { case 1: do_upgrade_code(); do_upgrade_code_submodules(); + do_upgrade_auto_loader(); break; case '1a': do_upgrade_code(); + do_upgrade_auto_loader(); break; case '1b': do_upgrade_code_submodules(); - break; - case 2: do_upgrade_auto_loader(); break; - case 3: + case 2: do_upgrade_schema(); break; - case '3b': + case '2b': do_upgrade_schema(true); break; - case 4: + case 3: + do_upgrade_auto_loader(); do_upgrade_domains(); break; - case 5: + case 4: + do_upgrade_auto_loader(); do_upgrade_menu(); break; - case 6: + case 5: + do_upgrade_auto_loader(); do_upgrade_permissions(); break; - case 7: + case 6: + do_upgrade_auto_loader(); do_filesystem_permissions($text, $settings); break; - case 8: + case 7: do_upgrade_code(); do_upgrade_auto_loader(); do_upgrade_schema(); @@ -133,6 +136,7 @@ function show_upgrade_menu() { case 9: break; case 0: + case 'q': exit(); } } @@ -144,16 +148,21 @@ function show_upgrade_menu() { */ function do_upgrade_auto_loader() { global $text; + //remove temp file + unlink(sys_get_temp_dir() . '/' . auto_loader::FILE); + //create a new instance of the autoloader $loader = new auto_loader(); + //reload the classes $loader->reload_classes(); echo "{$text['label-reloaded_classes']}\n"; + //re-create cache file if ($loader->update_cache()) { echo "{$text['label-updated_cache']}\n"; } } /** - * Show the software version + * Update file system permissions */ function do_filesystem_permissions($text, settings $settings) { @@ -185,6 +194,8 @@ function do_filesystem_permissions($text, settings $settings) { if ($log_directory !== null) { $directories[] = $log_directory . '/xml_cdr'; } + //update the auto_loader cache permissions file + $directories[] = sys_get_temp_dir() . '/' . auto_loader::FILE; //execute chown command for each directory foreach ($directories as $dir) { if ($dir !== null) { diff --git a/resources/classes/auto_loader.php b/resources/classes/auto_loader.php index 65d85afe06..fcb0b4fce3 100644 --- a/resources/classes/auto_loader.php +++ b/resources/classes/auto_loader.php @@ -33,7 +33,10 @@ class auto_loader { public function __construct($project_path = '') { //classes must be loaded before this object is registered if (!$this->load_cache()) { + //cache miss so load them $this->reload_classes($project_path); + //update the cache after loading classes array + $this->update_cache(); } //register this object to load any unknown classes spl_autoload_register(array($this, 'loader')); @@ -106,8 +109,6 @@ class auto_loader { $this->classes[basename($path, '.php')] = $path; } - //update the cache after loading classes array - $this->update_cache(); } private function loader($class_name) : bool {