Skip to content

Commit

Permalink
Fix issue warning when user param is null
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Jul 31, 2024
1 parent b0b333c commit 221e7e8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions plugins/astroid/src/Extension/AstroidPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function onAfterRespond()
public function onContentPrepareData($context, $user)
{
// Fix issue Attempt to assign property "astroid_author_social0" on array of User Component
if ($context == 'com_users.profile') {
if ($context == 'com_users.profile' && isset($user->params) && !empty($user->params)) {
$params = new \Joomla\Registry\Registry();
$params->loadArray($user->params);
if (is_array($params->get('astroid_author_social')) && !count($params->get('astroid_author_social'))) {
Expand All @@ -118,14 +118,16 @@ public function onContentPrepareData($context, $user)
public function onUserAfterSave($user, $isnew, $success, $msg): void
{
// Fix issue Attempt to assign property "astroid_author_social0" on array of User Component
$params = new \Joomla\Registry\Registry($user['params']);
if (is_array($params->get('astroid_author_social')) && !count($params->get('astroid_author_social'))) {
$params->remove('astroid_author_social');
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
$object = new \stdClass();
$object->id = $user['id'];
$object->params = $params->toString();
$db->updateObject('#__users', $object, 'id');
if (isset($user['params']) && !empty($user['params'])) {
$params = new \Joomla\Registry\Registry($user['params']);
if (is_array($params->get('astroid_author_social')) && !count($params->get('astroid_author_social'))) {
$params->remove('astroid_author_social');
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
$object = new \stdClass();
$object->id = $user['id'];
$object->params = $params->toString();
$db->updateObject('#__users', $object, 'id');
}
}
}

Expand Down

2 comments on commit 221e7e8

@ClemSchn2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, it works very well

@ClemSchn2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry i have an additional question. Do I also have to replace lines 121 to 130?

Thank you!

Please sign in to comment.