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);
The User model is returned
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.
Joomla Version: 4.3.1
PHP: 8.2.5
Code worked fine before recent update.
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
@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.
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.
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.
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.
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);
$userdata should be an array, since we introduced com_fields.
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.
Can you share a simplified form of the script, so we can test it?
<?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();
Is there an update on this?
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();
Labels |
Added:
Information Required
|
Labels |
Added:
bug
|
I am going to close this nased on the comment above and the lack of any further comments. It can always be reopened
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-09-01 11:10:59 |
Closed_By | ⇒ | brianteeman |
Labels |
Removed:
Information Required
|
can you please detail a little bit more
maybe following the issue template ?