civicrm / civicrm/cv

"Found unconstructed IntlDateFormatter" when logging happens during upgrade:db on PHP 8.1.26

Open
#185 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
45
Forks
36
Avg merge
17h 54m
Merged PRs (30d)
3

Description

# Environments:
Ubuntu 20.04, Ubuntu 22.04
PHP 8.1.26 (CLI and PHP-FPM)
cv 0.3.48
/etc/php/8.1/cli/php.ini sets `intl.default_locale = en_US` or `en_US.utf8` or that line is commented out
Drupal 9.5.11, WordPress 6.4.2

# Steps to reproduce:
- Have a Civi install before 5.66 (5.64.4 in this case)
- Upgrade to 5.66.2 or later (5.68.0 in this case)
- Run `cv upgrade:db`

# Results:
If the upgrader tries to log something as the FiveSixtySix step does, the upgrade fails with "Found error IntlDateFormatter" in php-8.1-strftime.php line 105.

Importantly: Restoring from a backup and running the database upgrade from the web UI works fine.

Full output of `cv upgrade:db -vvv --retry`:

```
Box Requirements Checker
========================

> Using PHP 8.1.26
> PHP is using the following php.ini file:
/etc/php/8.1/cli/php.ini

> Checking Box requirements:
✔ The application requires a version matching ">=7.3.0".
✔ The application requires the extension "json".
✔ The package "psy/psysh" requires the extension "json".
✔ The package "nikic/php-parser" requires the extension "tokenizer".
✔ The package "psy/psysh" requires the extension "tokenizer".


[OK] Your system is ready to run the application.

[BootTrait:debug] Start
[BootTrait:debug] Attempting to set verbose error reporting
[BootTrait:debug] Call standard cv bootstrap
[Bootstrap:debug] Options: {
"dynamicSettingsFile": "phar:///usr/local/bin/cv/lib/settings_location.php",
"env": "CIVICRM_SETTINGS",
"prefetch": true,
"settingsFile": null,
"search": true,
"cmsType": null,
"httpHost": "",
"output": {}
}
[Bootstrap:debug] Find settings file
[Bootstrap:debug] Load supplemental configuration for "/srv/www/d9_test/web/sites/default/civicrm.settings.php"
[Bootstrap:notice] Find CMS root for "/srv/www/d9_test"
[Bootstrap:notice] Found "drupal" in "/srv/www/d9_test/web"
[Bootstrap:notice] Simulate web environment in CLI
[Bootstrap:debug] Load settings file "/srv/www/d9_test/web/sites/default/civicrm.settings.php"
[Bootstrap:notice] Initialize class loader
[Bootstrap:notice] Call core bootstrap
[Bootstrap:debug] Finished
[BootTrait:debug] Call core bootstrap
[BootTrait:debug] Call CMS bootstrap
[BootTrait:debug] Set active MySQL timezone
[BootTrait:debug] Finished
Found CiviCRM database version 5.66.alpha1.upgrade.
Found CiviCRM code version 5.68.0.
Resuming upgrade...
Executing upgrade...
Add fields to civicrm_mail_settings to allow more flexibility for email to activity (CRM_Upgrade_Incremental_php_FiveSixtySix::addMailSettingsFields())

In php-8.1-strftime.php line 105:

[Error]
Found unconstructed IntlDateFormatter

Exception trace:
at /srv/www/d9_test/vendor/pear/log/php-8.1-strftime.php:105
IntlDateFormatter->format() at /srv/www/d9_test/vendor/pear/log/php-8.1-strftime.php:105
PHP81_BC\{closure}() at /srv/www/d9_test/vendor/pear/log/php-8.1-strftime.php:204
PHP81_BC\{closure}() at n/a:n/a
preg_replace_callback() at /srv/www/d9_test/vendor/pear/log/php-8.1-strftime.php:185
PHP81_BC\strftime() at /srv/www/d9_test/vendor/pear/log/Log.php:887
Log->formatTime() at /srv/www/d9_test/vendor/pear/log/Log/display.php:171
Log_display->log() at /srv/www/d9_test/vendor/pear/log/Log.php:375
Log->info() at /srv/www/d9_test/vendor/civicrm/civicrm-core/CRM/Upgrade/Incremental/php/FiveSixtySix.php:94
CRM_Upgrade_Incremental_php_FiveSixtySix::addMailSettingsFields() at /srv/www/d9_test/vendor/civicrm/civicrm-core/CRM/Queue/Task.php:101
CRM_Queue_Task->run() at phar:///usr/local/bin/cv/src/Util/ConsoleQueueRunner.php:44
Civi\Cv\Util\ConsoleQueueRunner->runAll() at phar:///usr/local/bin/cv/src/Command/UpgradeDbCommand.php:105
Civi\Cv\Command\UpgradeDbCommand->execute() at phar:///usr/local/bin/cv/vendor/symfony/console/Command/Command.php:127
Cvphar\Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/cv/vendor/symfony/console/Application.php:637
Cvphar\Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/cv/vendor/symfony/console/Application.php:190
Cvphar\Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/cv/src/Application.php:67
Civi\Cv\Application->doRun() at phar:///usr/local/bin/cv/vendor/symfony/console/Application.php:101
Cvphar\Symfony\Component\Console\Application->run() at phar:///usr/local/bin/cv/src/Application.php:33
Civi\Cv\Application::main() at phar:///usr/local/bin/cv/bin/cv:28
require() at /usr/local/bin/cv:14

upgrade:db [--out OUT] [--flat [FLAT]] [--dry-run] [--retry] [--skip] [--step] [--level LEVEL] [--hostname HOSTNAME] [-t|--test] [-U|--user USER]
```

# Notes & Observations
This seems related to the recent [changes in PHP 8.1.25 / PHP 8.1.26](https://github.com/php/php-src/issues/12912) around IntlDateFormatter not accepting an invalid $locale parameter. Adding some debug code to vendor/pear/log/php-8.1-strftime.php, I found that $locale is set to "C". [In 8.0,](https://www.php.net/manual/en/migration80.incompatible.php) "The default locale on startup is now always 'C'. No locales are inherited from the environment by default."

I tried rebuilding cv after adding the following to lib/src/Util/BootTrait.php's _boot_full at line 152:

```
$locale = \Civi\Core\Locale::detect();
print_r($locale);
$locale->apply();
setlocale(LC_ALL, $locale->nominal)
```

This shows the Locale object as
```
(
[nominal] => en_US
[ts] => en_US
[db] =>
[moneyFormat] => en_US
[uf] => en_US
)
```
but $locale passed to \PHP81_BC::strftime remains "C" and the error persists, so that wasn't the way to go.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with vendor/pear/log/php-8.1-strftime.php at line 105 and trace the logging call from CRM/Upgrade/Incremental/php/FiveSixtySix.php line 94 through cv's ConsoleQueueRunner. Review lib/src/Util/BootTrait.php _boot_full alongside the reported PHP 8.1 locale behavior, then run cv upgrade:db -vvv --retry. Done means the database upgrade completes when logging occurs under PHP 8.1.26.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.