Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Factory::getUser() to ::getApplication()->getIdentity() #37321

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ActionlogModel extends BaseDatabaseModel
*/
public function addLog($messages, $messageLanguageKey, $context, $userId = null)
{
$user = Factory::getUser($userId);
$user = Factory::getApplication()->getIdentity($userId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for information the change here is not right. The getIdentity method does not accept any parameter like you passed here. If we want to replace it, we will need to use UserFactory, something like:

$user = Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById($userId);

$db = $this->getDbo();
$date = Factory::getDate();
$params = ComponentHelper::getComponent('com_actionlogs')->getParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

\defined('_JEXEC') or die;

use Exception;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;

Expand Down Expand Up @@ -50,18 +51,19 @@ abstract class ActionLogPlugin extends CMSPlugin
*
* This method adds a record to #__action_logs contains (message_language_key, message, date, context, user)
*
* @param array $messages The contents of the messages to be logged
* @param string $messageLanguageKey The language key of the message
* @param string $context The context of the content passed to the plugin
* @param int $userId ID of user perform the action, usually ID of current logged in user
* @param array $messages The contents of the messages to be logged
* @param string $messageLanguageKey The language key of the message
* @param string $context The context of the content passed to the plugin
* @param int $userId ID of user perform the action, usually ID of current logged in user
Comment on lines +54 to +57
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert.

*
* @return void
*
* @throws Exception
* @since 3.9.0
*/
protected function addLog($messages, $messageLanguageKey, $context, $userId = null)
{
$user = Factory::getUser();
$user = Factory::getApplication()->getIdentity();

foreach ($messages as $index => $message)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class HtmlView extends BaseHtmlView
public function display($tpl = null): void
{
// Access check.
if (!Factory::getUser()->authorise('core.admin'))
if (!Factory::getApplication()->getIdentity()->authorise('core.admin'))
{
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class JsonView extends AbstractView
public function display($tpl = null): void
{
// Access check.
if (!Factory::getUser()->authorise('core.admin'))
if (!Factory::getApplication()->getIdentity()->authorise('core.admin'))
{
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TextView extends AbstractView
public function display($tpl = null): void
{
// Access check.
if (!Factory::getUser()->authorise('core.admin'))
if (!Factory::getApplication()->getIdentity()->authorise('core.admin'))
{
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
Expand Down