Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chrisgaraffa opened this issue Dec 21, 2023 · 0 comments

Comments

@chrisgaraffa
Copy link

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 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, "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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant