Fixed `[E_WARNING] Undefined array key "defaultLanguageId"` during CLI installation

PaulB

Well-known member
Affected version
2.2.3 Patch 1
Repro:
  1. Clean environment, such as a VM or Docker. I used Docker Compose with the following images:
    1. openresty/openresty:1.19.3.1-2-alpine
    2. php:8.0.2-fpm-alpine3.12 (with PHP extensions)
    3. mariadb:10.5.8-focal
    4. elasticsearch:7.10.1
  2. XenForo 2.2.3 Patch 1 (2020371)
  3. Create a database named xf2.
  4. Create a basic config.php, attached below.
  5. Run:
Code:
php cmd.php xf:install \
    --no-interaction \
    --user='AzureDiamond' \
    --password='hunter2' \
    --email='test@xf2.localhost' \
    --title='Test' \
    --url='http://localhost' \
    --skip-statistics

config.php:
PHP:
<?php
   
declare(strict_types=1);

$config = [
    'debug'                 => true,
    'enableMail'            => false,
    'enableApi'             => false,
    'enableOneClickUpgrade' => false,
    'checkVersion'          => false,
    'fullUnicode'           => true,
    'db'                    => [
        'host'     => 'mysql',
        'port'     => '3306',
        'username' => 'root',
        'password' => '',
        'dbname'   => 'xf2',
    ],
];

Output:
Code:
All 4920 checked files are present and correct. :)
Database name: xf2
Creating tables...
212/212 [============================] 100%
Done.
Creating default data...
28/28 [============================] 100%
Done. Importing data...

Importing... Master data (Bb code media sites)

In App.php line 1254:

  [E_WARNING] Undefined array key "defaultLanguageId"

Changing this code in App.php:
PHP:
$container->factory('language', function($id, array $params, Container $c)
{
    $id = intval($id);

    $cache = $c['language.cache'];
    if (!$id || !isset($cache[$id]))
    {
        $id = $c['options']->defaultLanguageId;
    }
...to this:
PHP:
$container->factory('language', function($id, array $params, Container $c)
{
   $id = intval($id);

   $cache = $c['language.cache'];
   if (!$id || !isset($cache[$id]))
   {
      $id = $c['options']->defaultLanguageId ?? 0;
   }
... resolves the issue, but I'm not entirely sure whether defaultLanguageId is actually supposed to be missing there, so the real bug may be elsewhere.
 
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.4).

Change log:
Fix an issue preventing installs from the command line when using PHP 8
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom