fix: CLI backups no longer named joomla.invalid (host placeholder)
Universal: PR Check / Require Docs Update (pull_request) Has been skipped
Universal: PR Check / Wiki Update Reminder (pull_request) Has been skipped
Universal: PR Check / Branch Policy (pull_request) Successful in 2s
Universal: Pre-Release / Build Pre-Release (${{ inputs.stability || github.ref_name }}) (push) Successful in 40s
Universal: PR Check / Secret Scan (pull_request) Successful in 9s
Generic: Project CI / Lint & Validate (pull_request) Successful in 17s
Joomla: Metadata Validation / Validate Joomla Metadata (pull_request) Successful in 16s
Universal: PR Check / Validate PR (pull_request) Failing after 50s
Generic: Project CI / Tests (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Universal: PR Check / Report Issues (pull_request) Has been cancelled

Joomla's console fills $_SERVER['HTTP_HOST'] with the reserved sentinel
'joomla.invalid', which the [HOST] placeholder resolver used verbatim
because its unusable-host check only knew about empty/localhost. Treat
'joomla.invalid' as unusable too, falling back to live_site then the
system hostname, so CLI/console/scheduled backups get a real name.

Claude-Session: https://claude.ai/code/session_01WbGBN9VyRK61zczYWcCQ2i
This commit is contained in:
2026-07-05 22:02:46 -05:00
parent a47a9e5deb
commit 5ffcbcc2f1
2 changed files with 21 additions and 9 deletions
@@ -52,15 +52,25 @@ class PlaceholderResolver
{
$now = new \DateTimeImmutable('now');
/* Resolve hostname: prefer HTTP_HOST (web), then try Joomla config (CLI), then system hostname */
$rawHost = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? '';
/* Resolve hostname: prefer the real request host (web), then the
configured live_site (CLI), then the system hostname. Joomla's console
fills the request host with the placeholder 'joomla.invalid' (an
RFC 6761 reserved TLD used as a CLI sentinel), so treat that — along
with empty/localhost — as unusable and fall through; otherwise every
CLI-triggered backup would be named 'joomla.invalid_…'. */
$unusable = static function (string $h): bool {
$h = strtolower(trim($h));
if (empty($rawHost) || $rawHost === 'localhost') {
return $h === '' || $h === 'localhost' || $h === 'joomla.invalid';
};
$rawHost = (string) ($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? '');
if ($unusable($rawHost)) {
try {
$app = Factory::getApplication();
$liveSite = $app->get('live_site', '');
$liveSite = (string) Factory::getApplication()->get('live_site', '');
if (!empty($liveSite)) {
if ($liveSite !== '') {
$parsed = parse_url($liveSite, PHP_URL_HOST);
if (!empty($parsed)) {
@@ -68,12 +78,13 @@ class PlaceholderResolver
}
}
} catch (\Throwable $e) {
/* fallback */
/* fall through to system hostname */
}
}
if (empty($rawHost)) {
$rawHost = php_uname('n');
if ($unusable($rawHost)) {
$sysHost = php_uname('n');
$rawHost = $sysHost !== '' ? $sysHost : 'site';
}
$hostname = preg_replace('/[^a-zA-Z0-9._-]/', '', $rawHost);