[Rt-commit] r13579 - in rt/3.8/trunk: sbin

sartak at bestpractical.com sartak at bestpractical.com
Tue Jun 24 17:17:39 EDT 2008


Author: sartak
Date: Tue Jun 24 17:17:39 2008
New Revision: 13579

Modified:
   rt/3.8/trunk/   (props changed)
   rt/3.8/trunk/sbin/rt-email-dashboards.in

Log:
 r63194 at onn:  sartak | 2008-06-24 17:17:18 -0400
 If a dashboard fails to load, delete the subscription and notify the user


Modified: rt/3.8/trunk/sbin/rt-email-dashboards.in
==============================================================================
--- rt/3.8/trunk/sbin/rt-email-dashboards.in	(original)
+++ rt/3.8/trunk/sbin/rt-email-dashboards.in	Tue Jun 24 17:17:39 2008
@@ -192,14 +192,41 @@
 
     my $dashboard = RT::Dashboard->new($currentuser);
 
-    $dashboard->LoadById($subscription->SubValue('DashboardId'))
-        or die loc(
-            "Unable to load dashboard [_1] of subscription [_2] for user [_3]",
+    $dashboard->LoadById($subscription->SubValue('DashboardId'));
+
+    # failed to load dashboard. perhaps it was deleted?
+    if (!$dashboard->Id) {
+        warning "Unable to load dashboard [_1] of subscription [_2] for user [_3]",
             $subscription->SubValue('DashboardId'),
             $subscription->Id,
-            $currentuser->Name
+            $currentuser->Name;
+
+        my $ok = RT::Interface::Email::SendEmailUsingTemplate(
+            From      => $from,
+            To        => email_of($currentuser),
+            Template  => 'Error: Missing dashboard',
+            Arguments => {
+                SubscriptionObj => $subscription,
+            },
         );
 
+        # only delete the subscription if the email looks like it went through
+        if ($ok) {
+            my ($deleted, $msg) = $subscription->Delete();
+            if ($deleted) {
+                verbose("Deleted an obsolete subscription: [_1]", $msg);
+            }
+            else {
+                warning("Unable to delete an obsolete subscription: [_1]", $msg);
+            }
+        }
+        else {
+            warning("Unable to notify [_1] of an obsolete subscription", $currentuser->Name);
+        }
+
+        return;
+    }
+
     verbose 'Creating dashboard "[_1]" for user "[_2]":',
             $dashboard->Name,
             $currentuser->Name;


More information about the Rt-commit mailing list