? ? Pending

User tests: Successful: 2 chmst, matrikular Unsuccessful: 0

avatar bembelimen
bembelimen
8 Feb 2017

Summary of Changes

At the moment, the JApplicationCms class allows us to retrive all messages attached to the object via $app->getMessageQueue(). This method clears the messages from the session, so we'll get no duplicates (what is great), but the methods also attach/keeps the messages itself. So after a redirect all the messages will be outputted again. (https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/application/cms.php#L1052).

This is very unhandy, if you want to change the error messages, like (as easy example):

$app = JFactory::getApplication();

$messages = $app->getMessageQueue();

foreach ($messages as $message)
{
    $app->enqueueMessage('Prefix: ' . $message['message'], $message['type']);
}

The complex picture where this could appear is:

  • You have an profile plugin with an onUserBeforeSave and an onContentPrepareForm event.
  • The onContentPrepareForm extends the user profile form with a image upload
  • The onUserBeforeSave validates the file with the JMediaHelper class

The problem is now: if an error raises in the JHelperMedia class (https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/helper/media.php), it will use $app->enqueMessage(...) to "communicate" this errors (e.g. https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/helper/media.php#L59). The profile saving method looks for errors in the user model and attach a prefix (https://github.com/joomla/joomla-cms/blob/staging/components/com_users/controllers/profile.php#L162), so any plugin has to raise/throw it's own errors to interact with this call (https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/user/user.php#L786).

So the way is:

  1. Let JHelperMedia validate the file
  2. Check $app->getMessageQueue() for existing errors and throw them
  3. The user object catchs them and gives them to the model/controller, which attach it as prefix
  4. The error will be outputted (what is OK)
  5. the "old" error will also be outputted (what is very annoying)

Solution: see this patch. An additional parameter which clears the application message queue and prevent double output.

Testing Instructions

Call somewhere

$app = JFactory::getApplication();
$app->enqueueMessage('Foo', 'notice');
$app->getMessageQueue(true);
$app->redirect(JRoute::_('index.php'));

Expected result (After patch)

The message does not appear

Actual result (Before patch)

The message appears

Documentation Changes Required

avatar bembelimen bembelimen - open - 8 Feb 2017
avatar bembelimen bembelimen - change - 8 Feb 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 8 Feb 2017
Category Libraries
avatar bembelimen bembelimen - change - 8 Feb 2017
The description was changed
avatar bembelimen bembelimen - edited - 8 Feb 2017
avatar bembelimen bembelimen - edited - 8 Feb 2017
avatar bembelimen bembelimen - change - 8 Feb 2017
The description was changed
Labels Added: ?
avatar bembelimen bembelimen - change - 8 Feb 2017
The description was changed
avatar bembelimen bembelimen - edited - 8 Feb 2017
avatar chmst
chmst - comment - 8 Feb 2017

I have tested this item successfully on f551d1f

I've tested this successfull following the testing instructions. I used the view of the administrator - com_content - article to insert the sample code. Then it works as described.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13975.

avatar chmst chmst - test_item - 8 Feb 2017 - Tested successfully
avatar matrikular
matrikular - comment - 9 Feb 2017

I have tested this item successfully on f551d1f

Patch works as described - Joomla! 3.6.5

It is to mention though, that I had to apply the changes in JApplicationCms::getMessageQueue manually. I wasn't able to apply the patch via patchtester.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13975.

avatar matrikular matrikular - test_item - 9 Feb 2017 - Tested successfully
avatar chmst
chmst - comment - 9 Feb 2017

@matrikular: I've tested on 3.7.0 beta2 using the patch tester.

avatar jeckodevelopment jeckodevelopment - change - 11 Feb 2017
Status Pending Ready to Commit
avatar jeckodevelopment
jeckodevelopment - comment - 11 Feb 2017

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13975.

avatar rdeutz rdeutz - change - 12 Feb 2017
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2017-02-12 15:51:02
Closed_By rdeutz
Labels Added: ?
avatar rdeutz rdeutz - close - 12 Feb 2017
avatar rdeutz rdeutz - merge - 12 Feb 2017

Add a Comment

Login with GitHub to post a comment