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.