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

Bauer

Well-Known Member
For months now I?ve had this error (see attachment) show at the top of a list after being redirected after a form is submitted and couldn't figure out why. Others have mentioned this same issue in these forums. So today I spent some time trying to debug. But after a few hours I gave up.

I know the cause of the problem ? I just don?t know how to fix it ?the right way?.

What happens is the function getEmailValue() in /plugins/fabrik_element/user/user.php is being called repetitively.

I?m not sure why ? but I assume it is either because I have a user element in both the parent and joined group in the form ? or because there is 2 joined rows linked to the parent .

Below is a var dump of the values of $userid in each of the ?If? statements in the getEmailValue function. (the line numbers are off, of course, because I inserted the debugging var_dump code)?

/plugins/fabrik_element/user/user.php 959 - userid is array(1) { [0]=> string(2) "55" }
/plugins/fabrik_element/user/user.php 963 - userid is array(1) { [0]=> string(2) "55" }
/plugins/fabrik_element/user/user.php 973 - userid is array(1) { [0]=> string(2) "55" }
/plugins/fabrik_element/user/user.php 975 - userid is int(55) /plugins/fabrik_element/user/user.php 989 - userid is int(55)

I also inserted this Backtrace just before the return at the end of the function :
1. /server_path/public_html/index.php 40 calling execute()
2. /server_path/public_html/libraries/cms/application/cms.php 255 calling doExecute()
3. /server_path/public_html/libraries/cms/application/site.php 208 calling dispatch()
4. /server_path/public_html/libraries/cms/application/site.php 178 calling renderComponent()
5. /server_path/public_html/libraries/cms/component/helper.php 332 calling executeComponent()
6. /server_path/public_html/libraries/cms/component/helper.php 352 calling require_once()
7. /server_path/public_html/components/com_fabrik/fabrik.php 185 calling execute()
8. /server_path/public_html/libraries/legacy/controller/legacy.php 722 calling process()
9. /server_path/public_html/components/com_fabrik/controllers/form.php 231 calling process()
10. /server_path/public_html/components/com_fabrik/models/form.php 1221 calling runPlugins()
11. /server_path/public_html/components/com_fabrik/models/pluginmanager.php 636 calling onAfterProcess()
12. /server_path/public_html/plugins/fabrik_form/php/php.php 250 calling _runPHP()
13. /server_path/public_html/plugins/fabrik_form/php/php.php 329 calling getProcessData()
14. /server_path/public_html/components/com_fabrik/models/plugin-form.php 192 calling getEmailData()

THEN, AS APPARENTLY THE FUNCTION IS CALLED A 2ND TIME, the screen continues echoing these results?
/plugins/fabrik_element/user/user.php 959 - userid is array(2) { [0]=> array(1) { [0]=> string(2) "55" } [1]=> array(1) { [0]=> string(2) "55" } }
/plugins/fabrik_element/user/user.php 963 - userid is array(2) { [0]=> array(1) { [0]=> string(2) "55" } [1]=> array(1) { [0]=> string(2) "55" } }
/plugins/fabrik_element/user/user.php 973 - userid is array(2) { [0]=> array(1) { [0]=> string(2) "55" } [1]=> array(1) { [0]=> string(2) "55" } }

NOTE HOW THE USER ARRAY IS NOW DOUBLED.
Note the var_dump result right after the line $userid = (int) array_shift($userid); (which is supposed to take care of a single array)...

/plugins/fabrik_element/user/user.php 975 - userid is int(1) /plugins/fabrik_element/user/user.php 989 - userid is int(1)

SO ? back in /libraries/joomla/user/user.php - line 800 - user id is now 1
And that is what throws the error.

My fix was to add another 'if' before the array_shift function...
PHP:
  if (is_array($userid))
  {
      if(count($userid)>1 ) $userid = $userid[0];
      $userid = (int) array_shift($userid);
  }

I'm sure that is not the optimal way to 'fix' this (the function shouldn't be called repetitively to begin with) - but until then , it works for me.
 

Attachments

  • jUser_error.PNG
    jUser_error.PNG
    31.1 KB · Views: 527
To followup on this - I think I found another problem - and it might explain why this "double" thing was happening.

In working out another issue with validation plugins (see this thread http://fabrikar.com/forums/index.ph...n-plugin-not-working-for-databasejoins.38041/ ) - using the php plugin, I entered this code (with some debugging info written to the php error log) to be run for validation.

(What I was getting at here was trying to come up with a way for the element to be validated only in certain rows of a joined form - based on the value of an element in that row.)
PHP:
ob_start('ob_tidyhandler');
echo 'rowid is {rowid} and id is {id}';
$contents = ob_get_contents();
error_log($contents);
ob_end_clean();
return !empty( $data );

And what do you know...
There are two entries being made in the error log - meaning the validation is being done TWICE.
Could someone please verify they get these same results? (I almost hope it's one of those 'just me' problems.)

This might also explain the slowness I have with validations - and issues I've had with ajax - and fatal errors reported in javascript console in Firebug.

It also probably explains the issue I had with using the 'notempty' validation plugin on databasejoin elements (as explained in the link I posted above) - and numerous other 'mysterious' issues users might be having recently.

One thing I've noticed in looking at the code over the past few days is that there are numerous places where "$repeatCount" is a parameter passed to a function, and yet not always implemented in the code withing that function. (Well, usually it's called "$repeatCounter".)

In the 'getElemetData()' function (at line 1463 in /components/com_fabrik/models/form.php)
and the 'downloadHit()' function (at line 2996 in /plugins/fabrik_element/fileupload/fileupload.php) it is called "$repeatCount".

And yet in both of those functions the variable "$repeatCount" is never referenced. Maybe the tracking of a '$repeatCount" was something that is on the TODO list for those functions and that's why it is there - but maybe some other code is already expecting it DONE???
 
Hey, this sounds like it'll be a good workaround while the Team finds a permanent solution. Where did you put that "if" code - which plugin and about which line (I'm using the current githib of fabrik)?
 
It's at line 971 of plugins/fabrik_element/user/user.php

If you still can't find it just search for "public function getEmailValue" and then look down a few lines for
$userid = (int) array_shift($userid);
and insert
if(count($userid)>1 ) $userid = $userid[0];
in the line above it.
 
Beautiful! That at least gets rid of it long enough to use for the presentation I have for my project tomorrow, and should tide me over until there's a permanent solution.

I'm currently a (simple) customer service rep for my company, but I've also been involved with web design - using Joomla, of course - for several years. We're currently doing all of our call tracking manually - as in each rep has their own set of Excel spreadsheets (one for each product line) that we manage. We don't share them so if we get a second call, we end up skyping each other to ask for any past history. Obviously, this is hardly efficient, plus we can't really track ANYthing for R&D, at least not easily.

I'm working on this project to help us do our stuff better - and, hopefully, move me out of the Customer Service department into a full time spot working with the main website and the Intranet. I'm going to be presenting it to my boss tomorrow, and hopefully it'll move up the chain of command so I can do what I really want - tech stuff.

All the help from Bauer, Troester, Cheesegrits, and all the rest of this community is helping me at least make the case that this could be a serious way to go - and not just for our Customer Service dept, but possibly for the company as a whole. So, basically, y'all are helping me make my dream a reality!

So, THANKS!
 
If you want to impress a customer who is an Excel freak - install PHPExcel and use it as part of your application. That also just happens to also be the 'go to' application my client for my current project has been using for all of the 25+ years at her business (since she could use a computer). It's got quite a learning curve as there isn't much documentation - though Google and discussions found at stackoverflow.com have been my best friends. Someone ported it over so it can be installed as a library in Joomla and used in any of your php code. https://github.com/vdespa/PHPExcel-Joomla-Library

Once you get the hang of it you can create and distribute spreadsheets from your Jooml/fabrik tables - and use the import/export (as csv) features of your lists to pass your data back and forth. (So long as you both go by the same rules). 18 months ago I barely even knew what to do with spreadsheets or had any use for them - but lately they are a big part of my life. With a few simple css/javascript tricks you can use the PHPExcel HTML writer to create an html file from a workbook that will bring up each worsheet via a fixed menubar at the bottom - and with the header fixed at the top - so you can scroll through an entire sheet on one screen. The biggest drawback with PHPExcel is that it's a notorious memory hog - so any huge workbooks might use up all your memory if your trying to run it on a shared host like she is ("until things take off") .

Another application I discovered was tablegear. http://andrewplummer.com/code/tablegear/ (newer versions are found on github link). It's about the closest thing to real 'inline editing' in 'spreadsheet-like' style I could find - without paying an arm and a leg for some cloud based service like Microsoft Excel Online that requires group invites, shared passwords, and such. Using one of the component creators from Joomla Extensions I somehow got it working as a Joomla app - though it's been so hacked and personalized for this project over the months that I couldn't distribute it if I wanted to.

Good luck with your Fabrik project - and try not to get addicted to it like I am.;)
 
Thanks... presentation went well. Unfortunately, I'm all ready addicted to Fabrik - just need to keep learning about using it! :)
 
That one won't work all the time either.
I was still getting the error sometimes because the user array is sometimes nested even more than just one deep.

I just updated from Github and now have the issue again.
I sure wish someone would fix it.
But I'd rather they fix it by finding what keeps adding the user as an array repeatedly. My solution isn't a fix - it's a Band-Aid.
Unless it's something I don't get and that user array is being built that way intentionally.
I do know it's related to repeat groups.
 
This bug keeps plauging me.

Despite that 'just' being a notice - if it is not corrected, then the form is NOT submitted correctly and any post-processing plugins or php code that you may have included in the form will not be executed.

BUT in 'getting around' this issue, in each case, it is not enough to just use the first array key value (e.g. $user[0]) as the value if the current value is an array. This is what the code is doing now, but it is not enough. Sometimes the array is nested even deeper than one level (In my debugging 'echos' - I've see it as many as 5 levels deep!!!)

In recent weeks I've found a 2nd area of the same user.php file that encounters this same problem. (And explains why my earlier suggested fix stopped working.)

This time the var name is '$id' - but it is still a user id. I believe this is coming from a 'user' element in the form. That $id will be a nested array if you are using a form with a user element that also has a joined table that also has a user element. Depending on the number of repeat groups, this causes a new array to be added to the '$id' array each time.

To fix that (well 'get past' the bug anyhow)...

in plugins/fabrik_element/user/user.php I changed this code...

In public function render() (approx line 140)
Change
PHP:
$id = is_array($id) ? $id[0] : $id;
To
PHP:
while(is_array($id)){
    $id=$id[0];
}
$id = is_array($id) ? $id[0] : $id;

Then, in public function getEmailValue() (approx line 971)
Change
PHP:
$userid = (int) array_shift($userid);
To
PHP:
while(is_array($userid)){
    $userid = $userid[0];
}
And again - this literal 'hack' does not solve the bug. Fixing the bug would mean to find and stop the code that keeps building onto that $id or $user array the way it does now.
 
I have seen this, but I've never been able to reliably duplicate it locally. Can you confirm something for me ... where you dump $userid in your test, can you also dump $repeatCounter, and post the results.

-- hugh
 
I have seen this, but I've never been able to reliably duplicate it locally. Can you confirm something for me ... where you dump $userid in your test, can you also dump $repeatCounter, and post the results.

-- hugh
Sorry Hugh I haven't been around much lately. Just getting back into this project. I have updated from github and not made any of the 'tweaks' mentioned above. So when I get around to the same form that I know was always causing that error, I'll let you know if it's still there - and if it is I will report with a var_dump of $repeatCounter as requested.
 
Thanks.

Yeah, I've been away for about a month as well, having some fairly major spine surgery. Now I'm not in constant crippling pain, I'm in a slightly better mood. Not that much better, I'm still a grumpy bastard, but a bit better.

-- hugh
 
darkroast

I'm utterly amazed by how effective my surgery has been. I had an L5-S1 TLIF and L3-L4 laminectomy 5 weeks ago, and it has just completely removed all the crazy bad pain I've had for years in my lower spine, and the sciatic pain in my legs. It's been like turning off a switch. And I'm recovering from the surgery much faster than most folk do, just in terms of general strength, stamina, post-op pain, etc.

When I finally got to see the x-rays and MRI's of my lower spine prior to surgery, it's not surprising - the L5-S1 disc basically wasn't there any more, it had completely ruptured and disintegrated, and those two vertabrae were basically mashed together. There was also really bad stenosis in L3-L4. So my sacral nerve was being crushed in several places.

I still have to have a C5-C6 ACDF in a month or two, to resolve similar issues affecting my neck / shoulders / arms, but that pain isn't quite as bad.

-- hugh
 
Dont worry, we're working on a BRAIN2SSD converter...you dont need your broken body soon anymore...just hold still till 2050
 
LOL!

My neck fusion is now scheduled for Nov 4th, which is an indication of how well I'm recovering from the 3 level lumbar surgery. Usually they'd want to wait at least 6 months between major surgeries, but my surgeon is happy enough with my recovery that he's OK with doing it after only 3 months.

Plan is then for a hip and a knee replacement, some time next year, once my bank balance recovers from this year. So who knows, maybe in a year or so I'll be fully bionic, and relatively pain free.

-- hugh
 
I have seen this, but I've never been able to reliably duplicate it locally. Can you
confirm something for me ... where you dump $userid in your test, can you also dump $repeatCounter, and post the results.

-- hugh
I came across this again today... "Unable to load user with ID: 1"

After researching where the error is triggered, the backtrace looks like this...
Code:
string(2047) "
#0 /home/compcirc/public_html/libraries/joomla/user/user.php(226): JUser->load(1)
#1 /home/compcirc/public_html/libraries/joomla/user/user.php(275): JUser->__construct(1)
#2 /home/compcirc/public_html/libraries/joomla/factory.php(246): JUser::getInstance(1)
#3 /home/compcirc/public_html/plugins/fabrik_element/user/user.php(1030): JFactory::getUser(1)
#4 /home/compcirc/public_html/components/com_fabrik/models/plugin-form.php(392): PlgFabrik_ElementUser->getEmailValue(Array, Array, 0)
#5 /home/compcirc/public_html/components/com_fabrik/models/plugin-form.php(195): PlgFabrik_Form->getEmailData()
#6 /home/compcirc/public_html/plugins/fabrik_form/php/php.php(329): PlgFabrik_Form->getProcessData()
#7 /home/compcirc/public_html/plugins/fabrik_form/php/php.php(251): PlgFabrik_FormPHP->_runPHP()
#8 /home/compcirc/public_html/components/com_fabrik/models/pluginmanager.php(643): PlgFabrik_FormPHP->onAfterProcess(Array)
#9 /home/compcirc/public_html/components/com_fabrik/models/form.php(1243): FabrikFEModelPluginmanager->runPlugins('onAfterProcess', Object(FabrikFEModelForm))
#10 /home/compcirc/public_html/components/com_fabrik/controllers/form.php(237): FabrikFEModelForm->process()
#11 /home/compcirc/public_html/libraries/legacy/controller/legacy.php(730): FabrikControllerForm->process()
#12 /home/compcirc/public_html/components/com_fabrik/fabrik.php(185): JControllerLegacy->execute('process')
#13 /home/compcirc/public_html/libraries/cms/component/helper.php(352): require_once('/home/compcirc/...')
#14 /home/compcirc/public_html/libraries/cms/component/helper.php(332): JComponentHelper::executeComponent('/home/compcirc/...')
#15 /home/compcirc/public_html/libraries/cms/application/site.php(191): JComponentHelper::renderComponent('com_fabrik')
#16 /home/compcirc/public_html/libraries/cms/application/site.php(237): JApplicationSite->dispatch()
#17 /home/compcirc/public_html/libraries/cms/application/cms.php(251): JApplicationSite->doExecute()
#18 /home/compcirc/public_html/index.php(42): JApplicationCms->execute()
#19 {main}"

The backtrace shows the error message is triggered triggered at line 834 of libraries/joomla/user/user.php ( where the id dumps as int(1) )

But the real problem - where the wrong user id is produced as 1 - is in Fabrik code. Specifically, that is the #3 item in the trace list...
#3 /home/compcirc/public_html/plugins/fabrik_element/user/user.php(1030): JFactory::getUser(1)

I think I fixed the problem by changing the code at the bottom of that function " public function getEmailValue() ".
This works for me, but I wouldn't feel comfortable with a commit until someone can test it with something that you know is sending a json encoded string as the id.

It's the same problem as had caused these similar errors. When there are repeat groups, somewhere along the way the $userid is being added as an array to the $userid value that is already an array. My guess is that something in that code is checking for the user id as being blank or zero - and if so, adding the id as an array - because the nesting will be as long as the number of repeat groups. I also question whether the bug only pops up when there is more than one 'user' plugin elements in those (3 joined) forms. I have the user_id saved to a 'user' element in 2 of the 3 joined tables, because in another part of the project I need to allow access and editing to that joined form independently (based on user_id).

So what seems to be the problem is that using array_shift() - or checking just once for $userid being an array and using the first key value - is not enough. The value of that first key might just be another array containing the id (possibly with more nested id arrays to follow) .

Anyhow, in this case (for me), the form is created from a table with 2 joined tables - and one of those 2 joined tables has repeat groups. The "Unable to load user with ID: 1" error message was always showing when I Submit/Save the form.

Here's my code, which I think solves the problem of the actual $userid number being nested in multiple arrays.
I changed the bottom of that 'getEmailValue()' function in 'plugins/fabrik_element/user/user.php' from...
PHP:
        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);

TO...
PHP:
        while(is_array($userid)) {$userid = $userid[0];}
        // Test json string e.g. ["350"] - fixes JUser: :_load: User does not exist notices
        if(strpos($userid,"[")>-1)
        {
                $userid = FabrikWorker::JSONtoData($userid, true);
                $userid = (int) JArrayHelper::getValue($userid, 0, 0);
        }else{
                $userid =(int) $userid;
        }
 
        $user = $userid === 0 ? JFactory::getUser() : JFactory::getUser($userid);
 
        return $this->getUserDisplayProperty($user);

Here's a quick function I found for checking if a value is a Json string.
You might want to implement this function instead of my simple strpos() check for '[' - to replace your checking !is_int($userid)

PHP:
function isJson($string) {
    json_decode($string);
    return (json_last_error() == JSON_ERROR_NONE);
}

AND FINALLY...
I'm wondering if this has anything to do with the changes in php v5.3.7 and 5.3.9 - when using the is_a() function? (That function is being used in the user.php element plugin). There are 2 notes about those changes (new behaviors) in the 'User Contributed Notes' section for the is_a() function at php.net . <See link. (I'm running php v5.5.12)
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top