$GLOBALS['prefix_resource_id_to_filename'], 'prefix_filename_string' => $GLOBALS['prefix_filename_string'], 'original_filenames_when_downloading' => $GLOBALS['original_filenames_when_downloading'], 'download_filename_id_only' => $GLOBALS['download_filename_id_only'], 'download_id_only_with_size' => $GLOBALS['download_id_only_with_size'], 'download_filenames_without_size' => $GLOBALS['download_filenames_without_size'], ]; if (isset($GLOBALS['download_filename_field'])) { $opts['download_filename_field'] = $GLOBALS['download_filename_field']; } elseif ($include_optional) { $opts['download_filename_field'] = 'unset'; // Required so override_rs_variables_by_eval() can override undefined globals $GLOBALS['download_filename_field'] = 'unset'; } return $opts; }; $deprecated_options = $get_global_config_options(true); $reset_global_values_to = function (array $vars) { foreach ($vars as $name => $value) { $GLOBALS[$name] = $value; } }; $get_var_value_from_code = function (array $find, string $code) { if (!eval_check_signed($code)) { return []; } $tokens = token_get_all(" null, 'value' => [], 'assign' => false, ]; foreach ($tokens as $token) { $is_token = is_array($token); $token_id = $is_token ? $token[0] : $token; $assigning = $current['assign'] && $current['token'] !== null; // Debug /* if ($is_token) { printf('%sLine %s: %s (%s)', PHP_EOL, $token[2], token_name($token[0]), $token[1]); } else { printf('%sCharacter (%s)', PHP_EOL, $token); } */ if (T_VARIABLE == $token_id && isset($find[mb_strcut($token[1], 1)])) { $current['token'] = $token; } elseif ($current['token'] !== null && '=' === $token_id) { $current['assign'] = true; $current['value'][] = $token; } elseif ($assigning && ';' === $token_id) { $current['value'][] = $token; $matches[] = $current['token'][1] . implode('', $current['value']); $current = [ 'token' => null, 'value' => [], 'assign' => false, ]; } elseif ($assigning) { $current['value'][] = $is_token ? $token[1] : $token; } } return $matches; }; $sign_code = fn(string $code) => "//SIG" . sign_code($code) . "\n" . $code; $process_config_overrides = function ( array $rows, string $what ) use ( $lang, $build_download_filename_format, $deprecated_options, $get_global_config_options, $get_var_value_from_code, $sign_code, $reset_global_values_to ): array { $messages = []; $init_deprecated_options = $deprecated_options; foreach ($rows as $row) { set_sysvar(SYSVAR_UPGRADE_PROGRESS_SCRIPT, sprintf("%s: %s", ucfirst($what), $row['name'])); $config_options = trim((string) $row['config_options']); if ($config_options === '') { continue; } $reset_global_values_to($init_deprecated_options); $deprecated_options = $init_deprecated_options; $matches = $get_var_value_from_code($deprecated_options, $config_options); // Try overriding global variables based on the matched deprecated config options $GLOBALS['use_error_exception'] = true; try { // Auto signing $matches because a variable assignment from an already signed code is considered safe override_rs_variables_by_eval($GLOBALS, $sign_code(implode(PHP_EOL, $matches)), 'test'); } catch (Throwable $th) { unset($GLOBALS['use_error_exception']); $err_msg = str_replace( ['%entity%', '%error%'], [ sprintf('%s (%s)', $row['name'], mb_strtolower($what)), $th->getMessage() ], $lang['upgrade_026_error_unable_to_process_deprecated_config_options'] ); debug(sprintf('[upgrade][%s] %s', __FILE__, $err_msg)); logScript($err_msg); $messages[] = $err_msg; continue; } unset($GLOBALS['use_error_exception']); $current_global_vars = $get_global_config_options(false); if ($deprecated_options === $current_global_vars) { continue; } // Remove made up value - @see $get_global_config_options definition if ( isset($current_global_vars['download_filename_field']) && $current_global_vars['download_filename_field'] === 'unset' ) { unset($GLOBALS['download_filename_field'], $deprecated_options['download_filename_field']); } $messages[] = str_replace( ['%entity%', '%format%'], [ sprintf("%s (%s)", $row['name'], mb_strtolower($what)), $build_download_filename_format() ], $lang['upgrade_026_notification'] ); } return $messages; }; set_sysvar(SYSVAR_UPGRADE_PROGRESS_SCRIPT, 'Processing user group config overrides...'); $ug_msg = $process_config_overrides(get_usergroups(), $lang['user_group']); set_sysvar(SYSVAR_UPGRADE_PROGRESS_SCRIPT, 'Processing resource type config overrides...'); $rt_msg = $process_config_overrides(get_resource_types('', true, true, false), $lang['property-resource_type']); set_sysvar(SYSVAR_UPGRADE_PROGRESS_SCRIPT, 'Notify admins'); $upgrade_26_admin_messages = array_filter(array_merge($system_wide_cfg_msg, $ug_msg, $rt_msg)); $notification_users = array_column(get_notification_users('SYSTEM_ADMIN'), 'ref'); foreach ($upgrade_26_admin_messages as $msg) { message_add( $notification_users, "{$lang['upgrade_script']} #026: {$msg}", '', null, MESSAGE_ENUM_NOTIFICATION_TYPE_SCREEN, MESSAGE_DEFAULT_TTL_SECONDS ); } set_sysvar(SYSVAR_UPGRADE_PROGRESS_SCRIPT, 'Finished download_filename_format configuration upgrade!');