pkg('Alert') - interface to specify events to alert upon,
schedule alerts, and mail out alerts.
use Krang::ClassLoader 'Alert';
# add new alert scenario - user 1 will be notified with a custom message when story 14 is published
my $alert = pkg('Alert')->new( user_id => '1',
action => 'publish',
object_type => 'story',
object_id => '13',
custom_msg_subject => 'THIRTEEN HAS GONE LIVE!',
custom_msg_body => 'Story 13 has gone live -- numerologically this does not bode well' );
# add new alert scenario - user 1 will be notified when any new story is
# created in category 3 (or its descendants)
my $alert = pkg('Alert')->new( user_id => '1',
action => 'new',
category_id => '3' );
# save the alert
$alert->save;
# add new alert scenario - user 1 will be notified when any story is
# moved to desk 4
my $alert2 = pkg('Alert')->new( user_id => '1',
action => 'move',
desk_id => '4' );
# save the alert
$alert2->save;
# Let's pretend that category 5 is a decendant of category 3.
# This find should return the $alert object from the above example.
my @found = pkg('Alert')->find( user_id => '1',
action => 'new',
category_id => '5' );
# check to see if history event should trigger an alert
# for specified object. If a match is found, an alert
# will be scheduled to be mailed with Krang::Schedule
# This is a convenience method that uses Krang::Alert->find()
# and Krang::Schedule->new()
pkg('Alert')->check_alert( history_object => $history_object,
story_object => $story_object );
# delete alert scenario
$alert->delete();
This class handles the storage of events to alert upon. It also checks Krang::History objects to see if an alert is matched. If so, an alert mailing ( Krang::Alert->send() ) will be scheduled in Krang::Schedule.
new()Supports the following name-value pairs:
save()find()Supported keys:
check_alert()This method takes two arguments, a Krang::History object and a Krang::Story or Krang::Media object.
delete()$alert = Krang::Alert->deserialize_xml(xml => $xml, set => $set, no_update => 0)If an incoming alert has the same fields as an existing alert then it is ignored (not duplicated).