update auto_loader cache file when updating (#7255)

This commit is contained in:
frytimo 2025-02-15 13:44:46 -04:00 committed by GitHub
parent dc0f146485
commit 5e6ec475df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 71 additions and 25 deletions

View File

@ -43,13 +43,13 @@
exit; exit;
} }
//connect to the database
$database = new database;
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//connect to the database
$database = database::new();
//set a default message_timeout //set a default message_timeout
$message_timeout = 4*1000; $message_timeout = 4*1000;
@ -76,7 +76,7 @@
//process the http post //process the http post
if (!empty($_POST) && @sizeof($_POST) > 0) { 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; $action = $_POST['action'] ?? null;
//run source update //run source update
@ -92,6 +92,12 @@
else { else {
message::add($text['message-upgrade_source_failed'], 'negative', $message_timeout); 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 //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_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); } 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 //load an array of the database schema and compare it with the active database
@ -131,7 +144,13 @@
//process the apps defaults //process the apps defaults
if (!empty($action["app_defaults"]) && permission_exists("upgrade_apps")) { 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 = new domains;
$domain->upgrade(); $domain->upgrade();
message::add($text['message-upgrade_apps'], null, $message_timeout); message::add($text['message-upgrade_apps'], null, $message_timeout);
@ -139,6 +158,11 @@
//restore defaults of the selected menu //restore defaults of the selected menu
if (!empty($action["menu_defaults"]) && permission_exists("menu_restore")) { 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"])); $sel_menu = explode('|', check_str($_POST["sel_menu"]));
$menu_uuid = $sel_menu[0]; $menu_uuid = $sel_menu[0];
$menu_language = $sel_menu[1]; $menu_language = $sel_menu[1];
@ -151,6 +175,11 @@
//restore default permissions //restore default permissions
if (!empty($action["permission_defaults"]) && permission_exists("group_edit")) { 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; $included = true;
require_once("core/groups/permissions_default.php"); require_once("core/groups/permissions_default.php");
$text = $language->get(null, '/core/upgrade'); $text = $language->get(null, '/core/upgrade');

View File

@ -177,6 +177,11 @@
exit(); 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 //get the version of the software
if ($upgrade_type == 'version') { if ($upgrade_type == 'version') {
echo software::version()."\n"; echo software::version()."\n";

View File

@ -77,14 +77,13 @@ function show_upgrade_menu() {
echo "1) {$text['label-upgrade_source']} - {$text['description-update_all_source_files']}\n"; echo "1) {$text['label-upgrade_source']} - {$text['description-update_all_source_files']}\n";
echo " 1a) " . $software_name . " - Update Main Software Only \n"; echo " 1a) " . $software_name . " - Update Main Software Only \n";
echo " 1b) {$text['label-update_external_repositories']} - {$text['description-repositories']}\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 "2) {$text['label-schema']} - {$text['description-upgrade_schema']}\n";
echo "3) {$text['label-schema']} - {$text['description-upgrade_schema']}\n"; echo " 2b) {$text['label-upgrade_data_types']} - {$text['description-upgrade_data_types']}\n";
echo " 3b) {$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_apps']} - {$text['description-upgrade_apps']}\n"; echo "4) {$text['label-upgrade_menu']} - {$text['description-upgrade_menu']}\n";
echo "5) {$text['label-upgrade_menu']} - {$text['description-upgrade_menu']}\n"; echo "5) {$text['label-upgrade_permissions']} - {$text['description-upgrade_permissions']}\n";
echo "6) {$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-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 "8) {$text['label-all_of_the_above']} - {$text['description-all_of_the_above']}\n";
echo "0) Exit\n"; echo "0) Exit\n";
echo "\n"; echo "\n";
echo "Choice: "; echo "Choice: ";
@ -93,35 +92,39 @@ function show_upgrade_menu() {
case 1: case 1:
do_upgrade_code(); do_upgrade_code();
do_upgrade_code_submodules(); do_upgrade_code_submodules();
do_upgrade_auto_loader();
break; break;
case '1a': case '1a':
do_upgrade_code(); do_upgrade_code();
do_upgrade_auto_loader();
break; break;
case '1b': case '1b':
do_upgrade_code_submodules(); do_upgrade_code_submodules();
break;
case 2:
do_upgrade_auto_loader(); do_upgrade_auto_loader();
break; break;
case 3: case 2:
do_upgrade_schema(); do_upgrade_schema();
break; break;
case '3b': case '2b':
do_upgrade_schema(true); do_upgrade_schema(true);
break; break;
case 4: case 3:
do_upgrade_auto_loader();
do_upgrade_domains(); do_upgrade_domains();
break; break;
case 5: case 4:
do_upgrade_auto_loader();
do_upgrade_menu(); do_upgrade_menu();
break; break;
case 6: case 5:
do_upgrade_auto_loader();
do_upgrade_permissions(); do_upgrade_permissions();
break; break;
case 7: case 6:
do_upgrade_auto_loader();
do_filesystem_permissions($text, $settings); do_filesystem_permissions($text, $settings);
break; break;
case 8: case 7:
do_upgrade_code(); do_upgrade_code();
do_upgrade_auto_loader(); do_upgrade_auto_loader();
do_upgrade_schema(); do_upgrade_schema();
@ -133,6 +136,7 @@ function show_upgrade_menu() {
case 9: case 9:
break; break;
case 0: case 0:
case 'q':
exit(); exit();
} }
} }
@ -144,16 +148,21 @@ function show_upgrade_menu() {
*/ */
function do_upgrade_auto_loader() { function do_upgrade_auto_loader() {
global $text; global $text;
//remove temp file
unlink(sys_get_temp_dir() . '/' . auto_loader::FILE);
//create a new instance of the autoloader
$loader = new auto_loader(); $loader = new auto_loader();
//reload the classes
$loader->reload_classes(); $loader->reload_classes();
echo "{$text['label-reloaded_classes']}\n"; echo "{$text['label-reloaded_classes']}\n";
//re-create cache file
if ($loader->update_cache()) { if ($loader->update_cache()) {
echo "{$text['label-updated_cache']}\n"; echo "{$text['label-updated_cache']}\n";
} }
} }
/** /**
* Show the software version * Update file system permissions
*/ */
function do_filesystem_permissions($text, settings $settings) { function do_filesystem_permissions($text, settings $settings) {
@ -185,6 +194,8 @@ function do_filesystem_permissions($text, settings $settings) {
if ($log_directory !== null) { if ($log_directory !== null) {
$directories[] = $log_directory . '/xml_cdr'; $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 //execute chown command for each directory
foreach ($directories as $dir) { foreach ($directories as $dir) {
if ($dir !== null) { if ($dir !== null) {

View File

@ -33,7 +33,10 @@ class auto_loader {
public function __construct($project_path = '') { public function __construct($project_path = '') {
//classes must be loaded before this object is registered //classes must be loaded before this object is registered
if (!$this->load_cache()) { if (!$this->load_cache()) {
//cache miss so load them
$this->reload_classes($project_path); $this->reload_classes($project_path);
//update the cache after loading classes array
$this->update_cache();
} }
//register this object to load any unknown classes //register this object to load any unknown classes
spl_autoload_register(array($this, 'loader')); spl_autoload_register(array($this, 'loader'));
@ -106,8 +109,6 @@ class auto_loader {
$this->classes[basename($path, '.php')] = $path; $this->classes[basename($path, '.php')] = $path;
} }
//update the cache after loading classes array
$this->update_cache();
} }
private function loader($class_name) : bool { private function loader($class_name) : bool {