From 774520b2f0a2bead4572ad72854eafc8ced5c602 Mon Sep 17 00:00:00 2001 From: Sonny Le Date: Thu, 13 Jun 2024 14:25:21 +0700 Subject: [PATCH] Fix issue Attempt to assign property "astroid_author_social0" on array #695 --- plugins/astroid/astroid.xml | 4 +-- .../astroid/src/Extension/AstroidPlugin.php | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/plugins/astroid/astroid.xml b/plugins/astroid/astroid.xml index d5972b8e..9bb96020 100644 --- a/plugins/astroid/astroid.xml +++ b/plugins/astroid/astroid.xml @@ -2,8 +2,8 @@ Astroid Plugin Astroid Framework Team - November 2023 - 3.0.5 + June 2024 + 3.1.0 https://www.astroidframe.work Copyright (C) 2023 TemPlaza, Inc. All rights reserved. GNU General Public License version 3 or later; see LICENSE.txt diff --git a/plugins/astroid/src/Extension/AstroidPlugin.php b/plugins/astroid/src/Extension/AstroidPlugin.php index 6b85dbd1..98649545 100644 --- a/plugins/astroid/src/Extension/AstroidPlugin.php +++ b/plugins/astroid/src/Extension/AstroidPlugin.php @@ -8,6 +8,7 @@ */ namespace Joomla\Plugin\System\Astroid\Extension; +use Joomla\CMS\Factory; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Plugin\PluginHelper; @@ -97,6 +98,35 @@ public function onAfterRespond() echo Helper::str_lreplace('', Helper::debug() . '', $contents); } + public function onContentPrepareData($context, $user) + { + if ($context == 'com_users.profile') { + $params = new \Joomla\Registry\Registry(); + $params->loadArray($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'); + } + } + } + + public function onUserAfterSave($user, $isnew, $success, $msg): void + { + $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'); + } + } + public function onInstallerAfterInstaller($installmodel, $package, $installer, $result) { if (!$result || Framework::isSite()) {