JUser: :_load: Unable to load user with ID: 1

There already is an isJson() in the main helper, FabrikWorker::isJson(). It has a few extra tests to avoid pitching warnings out of the main json_decode() test.

We're definitely zeroing in on this, I found a similar case recently. I'll be working on the user code in the next week or so, got some other stuff needs patching up, so I'll tend to it then.

And I have a custom project I'm working on at the moment which has user elements in joined repeats at various depths, so there's a good chance I'll replicate this specific instance of the problem.

-- hugh
 
Thanks Hugh. Please post a notice here when you have something ready for me to test - so I get notice of it in email.
 
Well, I'll try this yet again because this error continues to plague me.
Unable to load user with ID: 1

This bug has existed for years. I know where it is triggered and how to fix it.

To debug the issue I threw a var_dump at line 1003 of plugins/fabrik_element/user/user.php to determine the current value passed as '$userid'.

Then I added a debug_backtrace just above where the error message is actually generated
(on line 830 in libraries/joomla/user/user.php - which is supposed to then reset the user to a guest user. But that doesn't really work either since, even though '$this->guest' is then set to 1, it really does nothing to log out the user or reset the user session - but I guess that's another issue and a Joomla problem).

Anyhow, below is a cut and paste of the results of my debugging code...

array(1) { [0]=> string(2) "85" }
line 1003 plugins/fabrik_element/user/user.php - userid is

array(2) { [0]=> array(1) { [0]=> string(2) "85" } [1]=> array(1) { [0]=> string(2) "85" } }
line 1003 plugins/fabrik_element/user/user.php - userid is

Backtrace from fatal error 'Fatal error' at /home/public_html/libraries/joomla/user/user.php 831:

/home/public_html/index.php 40 calling execute()
/home/public_html/libraries/cms/application/cms.php 251 calling doExecute()
/home/public_html/libraries/cms/application/site.php 237 calling dispatch()
/home/public_html/libraries/cms/application/site.php 191 calling renderComponent()
/home/public_html/libraries/cms/component/helper.php 332 calling executeComponent()
/home/public_html/libraries/cms/component/helper.php 352 calling require_once()
/home/public_html/components/com_fabrik/fabrik.php 180 calling execute()
/home/public_html/libraries/legacy/controller/legacy.php 730 calling process()
/home/public_html/components/com_fabrik/controllers/form.php 249 calling process()
/home/public_html/components/com_fabrik/models/form.php 1253 calling runPlugins()
/home/public_html/components/com_fabrik/models/pluginmanager.php 643 calling onAfterProcess()
/home/public_html/plugins/fabrik_form/php/php.php 251 calling _runPHP()
/home/public_html/plugins/fabrik_form/php/php.php 367 calling getProcessData()
/home/public_html/components/com_fabrik/models/plugin-form.php 195 calling getEmailData()
/home/public_html/components/com_fabrik/models/plugin-form.php 392 calling getEmailValue()
/home/public_html/plugins/fabrik_element/user/user.php 1016 calling getUser()
/home/public_html/libraries/joomla/factory.php 246 calling getInstance()
/home/public_html/libraries/joomla/user/user.php 275 calling __construct()
/home/public_html/libraries/joomla/user/user.php 226 calling load()
/home/public_html/libraries/joomla/user/user.php 831 calling trigger_error()

I'm pretty sure this issue is caused when the PHP plugin is used on form submit - and only when the form includes a joined table and both tables include a user element.

That's why, in my var_dump, the first time getEmailValue() is called $userid is...
array(1) { [0]=> string(2) "85" }
and the 2nd time $userid it is...
array(2) { [0]=> array(1) { [0]=> string(2) "85" } [1]=> array(1) { [0]=> string(2) "85" } }

(and if there was a 2nd joined table that also had a user element, the value for $userid would end up being...)
array(3) { [0]=> array(1) { [0]=> string(2) "85" } [1]=> array(1) { [0]=> string(2) "85" } [2]=> array(1) { [0]=> string(2) "85" } }

Here's the fix/replacement for the getEmailValue() function in plugins/fabrik_element/user/user.php that I have been using to correct this problem - but it's really getting old having to fix it every time I update from github.

OLD function
PHP:
    public function getEmailValue($value, $data = array(), $repeatCounter = 0)
    {
        $key = $this->getFullName(true, false);
        $rawkey = $key . '_raw';
        $userid = $value;
 
        if (array_key_exists($rawkey, $data))
        {
            $userid = $data[$rawkey];
        }
        elseif (array_key_exists($key, $data))
        {
            $userid = $data[$key];
        }
 
        if (is_array($userid))
        {
            $userid = (int) array_shift($userid);
        }
        else
        {
            // Test json string e.g. ["350"] - fixes JUser: :_load: User does not exist notices
            if (!is_int($userid))
            {
                $userid = FabrikWorker::JSONtoData($userid, true);
                $userid = (int) JArrayHelper::getValue($userid, 0, 0);
            }
        }
 
        $user = $userid === 0 ? JFactory::getUser() : JFactory::getUser($userid);
 
        return $this->getUserDisplayProperty($user);
    }
NEW (fixed) function
PHP:
    public function getEmailValue($value, $data = array(), $repeatCounter = 0)
    {
        $key = $this->getFullName(true, false);
        $rawkey = $key . '_raw';
        $userid = $value;
 
        if (array_key_exists($rawkey, $data))
        {
            $userid = $data[$rawkey];
        }
        elseif (array_key_exists($key, $data))
        {
            $userid = $data[$key];
        }
 
        if (is_array($userid))
        {
            while (is_array($userid)) $userid = array_shift($userid);
        }
        else
        {
            // Test json string e.g. ["350"] - fixes JUser: :_load: User does not exist notices
            if (!is_int($userid))
            {
                $userid = FabrikWorker::JSONtoData($userid, true);
                $userid = JArrayHelper::getValue($userid, 0, 0);
            }
        }
 
        $user = (int) $userid === 0 ? JFactory::getUser() : JFactory::getUser($userid);
 
        return $this->getUserDisplayProperty($user);
    }
If you look at the old code, $userid was returned as 1 because the (int) value was being made on an array.

And as I have mentioned in past posts regarding this issue - I am not really sure if this 'fix' is a real fix to the root cause of the problem. I suppose that if my guess for the reason for this happening is true -
and that is the only instance in all of the fabrik code where this might be occurring -
then it is a legitimate 'fix'.

Otherwise someone needs to figure out why the $userid keeps getting re-initialized as an array - with just another array containing the same userid being added each time.
 
Hey, Bauer -

Yeah, this could be bugging me as well (I say "could" because, after all the work I put into developing a call center call tracking system, we got a new VP of Service who decided to scrap it in favor of something she was familiar with from her previous company - and which is a lot harder to use. But I'm not bitter... :rolleyes: )

Anyway... if I ever get a chance to use this again, it'd be nice to have it working the way it's supposed to. One thing you said above:

I'm pretty sure this issue is caused when the PHP plugin is used on form submit - and only when the form includes a joined table and both tables include a user element.

was exactly the scenario I had.

Maybe one thing - if you're comfortable with it - would be to go ahead and migrate that change to the github repository, especially since Hugh and company don't seem to have this high on their priority list at this time (not a knock on anyone - they have their hands full and Hugh's been out of pocket for a while [and I'm glad he's doing better]). Making the change in github would at least allow it to be reverted, if it causes any other issues.
 
Thanks for your feedback darkroast. (And I know the feeling of having hours or weeks of your work trashed in favor of something 'more familiar' to the end user - so I feel your pain.)

I just ran this line of code by to verify where the '1' comes from...
error_log( "array INT value: " . (INT) array('x','y','z') );
This is what it shows...
array INT value: 1

So between that, and your comment verifying my suspicion of what condition triggers the error, I think we pretty much know what causes the error - and my fix is the way to go.

However I am the world's biggest procrastinator and never took the time to learn how to use fabrik's Github. (I had a bad experience with using github once - from another developer - and am now afraid to try using it again.) Plus I have more than enough on my plate as is and am just being stubborn about it, I guess. As I've said many times, I'm more than happy to try to help figure out some of these long standing bugs - and feel no guilt in that being the limit to my contributions here, as THAT is what takes up most of the time and brainpower.

So if you - or ANYONE who has github access set up - wants to fix this bug once and for all, PLEASE DO - and I will be eternally grateful. The code fix as shown above seems to be the trick.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top