? Success

User tests: Successful: Unsuccessful:

avatar jackkum
jackkum
3 Jan 2015

Need sort plugins, plg_user_joomla must be last.

class PlgUserLogout extends JPlugin
{
    public function onUserLogout($user, $options = array())
    {
            throw new Exception("You shall not pass!");
    }
}
avatar jackkum jackkum - open - 3 Jan 2015
avatar jissues-bot jissues-bot - change - 3 Jan 2015
Labels Added: ?
avatar wilsonge
wilsonge - comment - 3 Jan 2015

If an exception is thrown we should probably trigger the onUserFailure plugin event and continue. Just like if there's something returned false now.

avatar jackkum
jackkum - comment - 3 Jan 2015

@wilsonge Is that better?

avatar wilsonge
wilsonge - comment - 3 Jan 2015

Personally yes :)

avatar infograf768
infograf768 - comment - 4 Jan 2015

Any reason to use $ex instead of $e as usually in core?

avatar jackkum
jackkum - comment - 4 Jan 2015

it's IDE autocomplete, i'll change it.

avatar zero-24 zero-24 - change - 4 Jan 2015
Category Plugins
avatar wilsonge
wilsonge - comment - 8 May 2016

Overall I like this, however I think we need to wrap the onUserAfterLogout new plugin event in a separate try/catch. Once a user has passed through onUserLogout then they are logged out and any further exceptions should not mean that onUserLogoutFailure will get triggered. Otherwise you're going to get serious bugs

avatar jackkum
jackkum - comment - 11 May 2016

@wilsonge
if i understand you correctly, i have to do something like this:


// OK, the credentials are built. Lets fire the onLogout event.
try
{
  $results = $this->triggerEvent('onUserLogout', array($parameters, $options));
}
catch (Exception $e)
{
  $this->enqueueMessage($e->getMessage());
}

// Check if any of the plugins failed. If none did, success.
try 
{
  if (isset($results) && is_array($results) && !in_array(false, $results, true))
  {
    $options['username'] = $user->get('username');
    $this->triggerEvent('onUserAfterLogout', array($options));

    return true;
  }

  // Trigger onUserLoginFailure Event.
  $this->triggerEvent('onUserLogoutFailure', array($parameters));
}
catch(Exception $e)
{
  $this->enqueueMessage($e->getMessage());
}
avatar roland-d
roland-d - comment - 20 May 2016

@jackkum That code snippet looks good to me.


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

avatar wilsonge
wilsonge - comment - 20 May 2016

In your first try/catch you need to trigger onUserLogoutFailure in the catch and return OR define $results as false.

avatar jackkum
jackkum - comment - 23 May 2016

@wilsonge
If i do trigger onUserLogoutFailure in the catch i have to do this twise, because old plugins can return false instead throws exception.

$results is undefined, so isset() will return false, this can be not obvious, and maybe better will define $results before try/catch.

avatar roland-d
roland-d - comment - 4 Jun 2016

@jackkum I guess that is the downside of backwards compatibility, we have to take into account both cases.


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

avatar roland-d
roland-d - comment - 3 Nov 2016

Hello @jackkum

Thank you for your contribution.

The last comment here was on June 4th. Are you still interested in updating this pull request?
If no reply is received within 4 weeks we will close this issue.

Thanks for understanding!


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

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 5 Jan 2017

@roland-d 4 weeks are gone.

avatar jeckodevelopment jeckodevelopment - change - 5 Jan 2017
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2017-01-05 19:50:19
Closed_By jeckodevelopment
avatar jeckodevelopment jeckodevelopment - close - 5 Jan 2017
avatar joomla-cms-bot joomla-cms-bot - change - 5 Jan 2017
Category Plugins Libraries

Add a Comment

Login with GitHub to post a comment