Notifying user of an occurrence

Permalink
Further to my earlier post about events, I'm trying to find if there's a way to post a notification to a user that an expected action failed to complete.

e.g. you have an event fire on a page view, say, and that event does something in the background which relies on a 3rd party system, say a statcounter or something else needing an HTTP request to be fired off.

You can't rely on the user having phpcurl installed so you use the builtin Zend HTTP Client. If the HTTP request fails you get a typical ugly Zend message and a die. Ideally you'd want a graceful notify to the user that expected action xxxx failed to complete.

How to achieve this, especially if the event is 'on_page_version_approve' which seems to offer no scope for outputting a message anywhere.

Alternately I was considering recording all failed actions in a db table so they could be automagically retried at some point, perhaps even adding a system job to deal with them.

Thoughts & advice, anyone?

G

surefyre
 
jordanlev replied on at Permalink Reply
jordanlev
I'm not sure if this would work in your situation, but I created a block with a form and I wanted any error messages to be displayed at the top of the page (as opposed to in the sidebar where the form lives), so I passed the message from the block controller to the theme template via a global variable.
So in the block controller's action_submit_form event, if there's an error I do this:
$GLOBALS['my_error'] = 'Error: Something went wrong...';


Then in my theme's page type templates, I added this to the top (I put it in an element so I don't have to repeat the code in all templates):
global $my_error;
if (isset($my_error)) {
    echo $my_error;
}


Hope that helps!

-Jordan
surefyre replied on at Permalink Reply
surefyre
Hi Jordan, that's not a bad idea though I don't think it would quite fit this need I have right now it's something to remember for the future, certainly!

I'm leaning toward the db + job approach as the functionality I'm working on - automatically tweeting a title+link on publishing a new page or an update - will need a db table to track certain events anyway and should 'know' if a task failed so it can retry it later via a job.

I like the idea of popping a notification block into the header/wherever though so I'm sure that'll get used in the near future :o)

G