mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2011-12-29 11:36 pm

[dw-free] Status messages can't be sent to the community itself, send to all maintainers

[commit: http://hg.dwscoalition.org/dw-free/rev/b7c1c3dc51d4]

Status messages can't be sent to the community itself, send to all
maintainers

Patch by [staff profile] mark.

Files modified:
  • cgi-bin/DW/Worker/ContentImporter.pm
--------------------------------------------------------------------------------
diff -r f6ef8b023acd -r b7c1c3dc51d4 cgi-bin/DW/Worker/ContentImporter.pm
--- a/cgi-bin/DW/Worker/ContentImporter.pm	Thu Dec 29 21:34:27 2011 +0000
+++ b/cgi-bin/DW/Worker/ContentImporter.pm	Thu Dec 29 23:37:11 2011 +0000
@@ -108,6 +108,23 @@
     return $hr;
 }
 
+=head2 C<< $class->userids_to_message( $userid ) >>
+
+For communities, this returns the userids for all of the admins so we let them know what has
+happened with their import.
+
+=cut
+
+sub userids_to_message {
+    my ( $class, $uid ) = @_;
+
+    my $u = LJ::load_userid( $uid )
+        or return $uid; # fail?
+    return $uid unless $u->is_community;
+
+    return $u->maintainer_userids;
+}
+
 =head2 C<< $class->fail( $import_data, $item, $job, "text", [arguments, ...] ) >>
 
 Permanently fail this import job.
@@ -130,7 +147,9 @@
         if $LJ::IS_DEV_SERVER;
 
     # fire an event for the user to know that it failed
-    LJ::Event::ImportStatus->new( $imp->{userid}, $item, { type => 'fail', msg => $msg } )->fire;
+    foreach my $uid ( $class->userids_to_message( $imp->{userid} ) ) {
+        LJ::Event::ImportStatus->new( $uid, $item, { type => 'fail', msg => $msg } )->fire;
+    }
 
     $job->permanent_failure( $msg );
     return;
@@ -156,14 +175,16 @@
         if $LJ::IS_DEV_SERVER;
 
     # fire an event for the user to know that it failed (temporarily)
-    LJ::Event::ImportStatus->new( $imp->{userid}, $item,
-        {
-            type     => 'temp_fail',
-            msg      => $msg,
-            failures => $job->failures,
-            retries  => $job->funcname->max_retries,
-        }
-    )->fire;
+    foreach my $uid ( $class->userids_to_message( $imp->{userid} ) ) {
+        LJ::Event::ImportStatus->new( $uid, $item,
+            {
+                type     => 'temp_fail',
+                msg      => $msg,
+                failures => $job->failures,
+                retries  => $job->funcname->max_retries,
+            }
+        )->fire;
+    }
 
     $job->failed( $msg );
     return;
@@ -187,8 +208,11 @@
     }
 
     # advise the user this finished
-    LJ::Event::ImportStatus->new( $imp->{userid}, $item, { type => 'ok' } )->fire
-        unless defined $show && $show == 0;
+    unless ( defined $show && $show == 0 ) {
+        foreach my $uid ( $class->userids_to_message( $imp->{userid} ) ) {
+            LJ::Event::ImportStatus->new( $uid, $item, { type => 'ok' } )->fire
+        }
+    }
 
     $job->completed;
     return;
@@ -232,7 +256,9 @@
 
 sub status {
     my ( $class, $imp, $item, $args ) = @_;
-    return LJ::Event::ImportStatus->new( $imp->{userid}, $item, { type => 'status', %{ $args || {} } } )->fire;
+    foreach my $uid ( $class->userids_to_message( $imp->{userid} ) ) {
+        LJ::Event::ImportStatus->new( $uid, $item, { type => 'status', %{ $args || {} } } )->fire;
+    }
 }
 
 
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org