No Code Attached Yet bug
avatar webcraftniray
webcraftniray
3 May 2023

Steps to reproduce the issue

Run any code to get a Joomla user via an id:

<?php
use Joomla\CMS\Factory;

Factory::getUser(100);

or

$userfactory = Factory::getContainer()->get(UserFactoryInterface::class);
$user = $userfactory->loadUserById(100);

Expected result

The User model is returned

Actual result

In the CLI the system fails:

_Exception {#201
  #message: "Failed to start application"
  #code: 500
  #file: "public_html/libraries/src/Factory.php"
  #line: 160
  trace: {
    /public_html/libraries/src/Factory.php:160 {
      Joomla\CMS\Factory::getApplication()^
      › if (!self::$application) {
      ›     throw new \Exception('Failed to start application', 500);
      › }
    }
    public_html/libraries/src/Table/Table.php:217 { …}
    public_html/libraries/src/Table/User.php:59 { …}
    public_html/libraries/src/Table/Table.php:317 { …}
    public_html/libraries/src/User/User.php:565 { …}
    public_html/libraries/src/User/User.php:814 { …}
    public_html/libraries/src/User/User.php:245 { …}
    public_html/cli/test.php:61 { …}
    public_html/libraries/src/Application/CliApplication.php:263 { …}
    public_html/cli/test.php:85 { …}
  }
}_

On the web, it returns NULL.

System information (as much as possible)

Joomla Version: 4.3.1
PHP: 8.2.5

Additional comments

Code worked fine before recent update.

Votes

# of Users Experiencing Issue
2/2
Average Importance Score
5.00

avatar webcraftniray webcraftniray - open - 3 May 2023
avatar webcraftniray webcraftniray - change - 3 May 2023
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 3 May 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 3 May 2023
avatar alikon
alikon - comment - 3 May 2023

can you please detail a little bit more
maybe following the issue template ?

avatar richard67
richard67 - comment - 4 May 2023

@alikon There are only some tick marks missing for escaping code in the issue description, and a few line feeds before the headings. I can’t fix that now because on the way to work. Will do later if nobody has done it before.

Update: I've fixed the formatting in the description so code and headings are visible.

avatar richard67 richard67 - change - 4 May 2023
The description was changed
avatar richard67 richard67 - edited - 4 May 2023
avatar richard67
richard67 - comment - 4 May 2023

@laoneo Could you have a look on this issue?

avatar webcraftniray
webcraftniray - comment - 4 May 2023

Apologies... I followed the template on issues.joomla.org... but didn't use Markup... there is no way to edit the issue on issues.joomla.org.

Thank you @richard67 for adding the formatting.

avatar laoneo
laoneo - comment - 4 May 2023

From which version did you update? As far as I know we didn't change anything. Can you post here the full CLI class? Side not, on Joomla 4 it is recommended to use a console command instead of a full CLI Application.

avatar webcraftniray
webcraftniray - comment - 4 May 2023

@laoneo we upgraded from 4.3.0 to 4.3.1

Quick note... the CLI script was just me testing the function in a different context. I understand that the CLI system has changed in J4 and I usually use that new way. But this was just a test.

avatar laoneo
laoneo - comment - 4 May 2023

Can you post here the failing script. I really doubt that it broke during the upgrade to 4.3.1 because it does contain only changes which are not related to the user factory. But maybe I miss here something.

avatar webcraftniray
webcraftniray - comment - 4 May 2023

Quick question... did the update change how custom user data is stored? My script was expecting strings but suddenly are dealing with arrays.

$userData = FieldsHelper::getFields('com_users.user', $this->user, true);

avatar laoneo
laoneo - comment - 5 May 2023

$userdata should be an array, since we introduced com_fields.

avatar webcraftniray
webcraftniray - comment - 5 May 2023

OK so apologies... this was an error on how we were using custom fields on the users. I'm changed how we are retrieving the data and it works.

Although the CLI test is still broken... and I'm not sure why.

avatar laoneo
laoneo - comment - 5 May 2023

Can you share a simplified form of the script, so we can test it?

avatar webcraftniray
webcraftniray - comment - 5 May 2023
<?php

use Joomla\CMS\Application\CliApplication;
use Joomla\CMS\Factory;

const _JEXEC = 1;

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
ini_set('session.use_cookies', 0);

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php')) {
    require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES')) {
    define('JPATH_BASE', dirname(__DIR__));
    require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_BASE . '/includes/framework.php';

class Test extends CliApplication
{

    public function doExecute()
    {
        
        // replace '100' with viable user Id.
        $user = Factory::getUser(100);

        echo $user->name;
        
    }


    public function getName()
    {
        return 'test';
    }
}


CliApplication::getInstance('test')->execute();
avatar joshgilson
joshgilson - comment - 10 May 2023

Is there an update on this?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/40536.

avatar laoneo
laoneo - comment - 10 May 2023

For me it works with the user factory form the container. All I had to do is to assign the app to the Factory. But this is something you have to do in 4.2.x or 4.3.0 as well. So for me it doesn't look like that there is something broken with the container.

$app = CliApplication::getInstance('test');
Factory::$application = $app;
$app->execute();
avatar Quy Quy - change - 4 Jun 2023
Labels Added: Information Required
avatar Quy Quy - labeled - 4 Jun 2023
avatar Hackwar Hackwar - change - 22 Aug 2023
Labels Added: bug
avatar Hackwar Hackwar - labeled - 22 Aug 2023
avatar brianteeman brianteeman - close - 1 Sep 2023
avatar brianteeman
brianteeman - comment - 1 Sep 2023

I am going to close this nased on the comment above and the lack of any further comments. It can always be reopened

avatar brianteeman brianteeman - change - 1 Sep 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-09-01 11:10:59
Closed_By brianteeman
avatar brianteeman brianteeman - change - 1 Sep 2023
Labels Removed: Information Required
avatar brianteeman brianteeman - unlabeled - 1 Sep 2023

Add a Comment

Login with GitHub to post a comment