Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[ljcom] r10614: LJSUP-9042: Create user suspend/unsuspen...

Committer: gariev
LJSUP-9042: Create user suspend/unsuspend event
U   trunk/cgi-bin/LJ/EventsFeed/ApplyTheme.pm
U   trunk/cgi-bin/LJ/EventsFeed/EmailChanged.pm
U   trunk/cgi-bin/LJ/EventsFeed/ProfileSave.pm
U   trunk/cgi-bin/LJ/EventsFeed/UserCreated.pm
U   trunk/cgi-bin/LJ/EventsFeed/UserDeleted.pm
A   trunk/cgi-bin/LJ/EventsFeed/UserEvent.pm
U   trunk/cgi-bin/LJ/EventsFeed/UserPurged.pm
A   trunk/cgi-bin/LJ/EventsFeed/UserSuspend.pm
U   trunk/cgi-bin/LJ/EventsFeed/UserUnDeleted.pm
A   trunk/cgi-bin/LJ/EventsFeed/UserUnSuspend.pm
U   trunk/cgi-bin/LJ/Hooks/EventsFeed.pm
Modified: trunk/cgi-bin/LJ/EventsFeed/ApplyTheme.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/ApplyTheme.pm	2011-06-09 04:19:08 UTC (rev 10613)
+++ trunk/cgi-bin/LJ/EventsFeed/ApplyTheme.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -1,26 +1,7 @@
 package LJ::EventsFeed::ApplyTheme;
 
 use strict;
-use base 'LJ::EventsFeed';
-use Carp qw (croak);
-
-sub new {
-    my ($class, $u) = @_;
-
-    croak "Must pass an LJ::User" unless LJ::isu($u);
-
-    return $class->SUPER::new(
-                              userid    => $u->userid,
-                              userlogin => $u->user,
-                             );
-}
-
-sub as_xml {
-    my $self = shift;
-    my $params = $self->params;
-
-    return $self->xml_head('journal_style_changed') . "<user id='$params->{'userid'}' login='$params->{'userlogin'}'/>"
-           . $self->xml_footer;
-}
-
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'journal_style_changed'  }
+ 
 1;

Modified: trunk/cgi-bin/LJ/EventsFeed/EmailChanged.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/EmailChanged.pm	2011-06-09 04:19:08 UTC (rev 10613)
+++ trunk/cgi-bin/LJ/EventsFeed/EmailChanged.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -1,26 +1,7 @@
 package LJ::EventsFeed::EmailChanged;
 
 use strict;
-use base 'LJ::EventsFeed';
-use Carp qw (croak);
-
-sub new {
-    my ($class, $u) = @_;
-
-    croak "Must pass an LJ::User" unless LJ::isu($u);
-
-    return $class->SUPER::new(
-                              userid    => $u->userid,
-                              userlogin => $u->user,
-                             );
-}
-
-sub as_xml {
-    my $self = shift;
-    my $params = $self->params;
-
-    return $self->xml_head('email_changed') . "<user id='$params->{'userid'}' login='$params->{'userlogin'}'/>"
-           . $self->xml_footer;
-}
-
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'email_changed'  }
+ 
 1;

Modified: trunk/cgi-bin/LJ/EventsFeed/ProfileSave.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/ProfileSave.pm	2011-06-09 04:19:08 UTC (rev 10613)
+++ trunk/cgi-bin/LJ/EventsFeed/ProfileSave.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -1,26 +1,8 @@
 package LJ::EventsFeed::ProfileSave;
 
 use strict;
-use base 'LJ::EventsFeed';
-use Carp qw (croak);
-
-sub new {
-    my ($class, $u) = @_;
-
-    croak "Must pass an LJ::User" unless LJ::isu($u);
-
-    return $class->SUPER::new(
-                              userid    => $u->userid,
-                              userlogin => $u->user,
-                             );
-}
-
-sub as_xml {
-    my $self = shift;
-    my $params = $self->params;
-
-    return $self->xml_head('profile_updated') . "<user id='$params->{'userid'}' login='$params->{'userlogin'}'/>"
-           . $self->xml_footer;
-}
-
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'profile_updated'  }
+ 
 1;
+

Modified: trunk/cgi-bin/LJ/EventsFeed/UserCreated.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/UserCreated.pm	2011-06-09 04:19:08 UTC (rev 10613)
+++ trunk/cgi-bin/LJ/EventsFeed/UserCreated.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -1,28 +1,8 @@
 package LJ::EventsFeed::UserCreated;
 
 use strict;
-use base 'LJ::EventsFeed';
-use Carp qw (croak);
-
-sub new {
-    my ($class, $u) = @_;
-
-    croak "Must pass an LJ::User" unless LJ::isu($u);
-
-    return $class->SUPER::new(
-                              id    => $u->userid,
-                              login => $u->user,
-                              type  => $u->journaltype,
-                              caps  => $u->caps,
-                             );
-}
-
-sub as_xml {
-    my $self = shift;
-    my $params = $self->params;
-
-    return $self->xml_head('created') . "<user id='$params->{'id'}' login='$params->{'login'}'"
-           . " type='$params->{'type'}' caps='$params->{'caps'}'/>" . $self->xml_footer;
-}
-
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'created' }
+ 
 1;
+

Modified: trunk/cgi-bin/LJ/EventsFeed/UserDeleted.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/UserDeleted.pm	2011-06-09 04:19:08 UTC (rev 10613)
+++ trunk/cgi-bin/LJ/EventsFeed/UserDeleted.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -1,28 +1,8 @@
 package LJ::EventsFeed::UserDeleted;
 
 use strict;
-use base 'LJ::EventsFeed';
-use Carp qw (croak);
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'deleted' }
 
-sub new {
-    my ($class, $u) = @_;
-
-    croak "Must pass an LJ::User" unless LJ::isu($u);
-
-    return $class->SUPER::new(
-                              id    => $u->userid,
-                              login => $u->user,
-                              type  => $u->journaltype,
-                              caps  => $u->caps,
-                             );
-}
-
-sub as_xml {
-    my $self = shift;
-    my $params = $self->params;
-
-    return $self->xml_head('deleted') . "<user id='$params->{'id'}' login='$params->{'login'}'"
-           . " type='$params->{'type'}' caps='$params->{'caps'}'/>" . $self->xml_footer;
-}
-
 1;
+

Added: trunk/cgi-bin/LJ/EventsFeed/UserEvent.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/UserEvent.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/EventsFeed/UserEvent.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -0,0 +1,35 @@
+package LJ::EventsFeed::UserEvent;
+
+## this is a base class for events whose only argument is LJ::User object
+
+use strict;
+use base 'LJ::EventsFeed';
+use Carp qw (croak);
+
+sub xml_tag_name { die "xml_tag_name must be overriden in child class"; } 
+
+sub new {
+    my ($class, $u) = @_;
+
+    croak "Must pass an LJ::User" unless LJ::isu($u);
+
+    return $class->SUPER::new(
+                              id    => $u->userid,
+                              login => $u->user,
+                              type  => $u->journaltype,
+                              caps  => $u->caps,
+                             );
+}
+
+sub as_xml {
+    my $self = shift;
+    my $params = $self->params;
+    
+    return $self->xml_head( $self->xml_tag_name ) . 
+            "<user id='$params->{'id'}' login='$params->{'login'}'" . 
+            " type='$params->{'type'}' caps='$params->{'caps'}'/>" . 
+            $self->xml_footer;
+}
+
+
+1;

Modified: trunk/cgi-bin/LJ/EventsFeed/UserPurged.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/UserPurged.pm	2011-06-09 04:19:08 UTC (rev 10613)
+++ trunk/cgi-bin/LJ/EventsFeed/UserPurged.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -1,28 +1,7 @@
 package LJ::EventsFeed::UserPurged;
 
 use strict;
-use base 'LJ::EventsFeed';
-use Carp qw (croak);
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'purged' }
 
-sub new {
-    my ($class, $u) = @_;
-
-    croak "Must pass an LJ::User" unless LJ::isu($u);
-
-    return $class->SUPER::new(
-                              id    => $u->userid,
-                              login => $u->user,
-                              type  => $u->journaltype,
-                              caps  => $u->caps,
-                             );
-}
-
-sub as_xml {
-    my $self = shift;
-    my $params = $self->params;
-
-    return $self->xml_head('purged') . "<user id='$params->{'id'}' login='$params->{'login'}'"
-           . " type='$params->{'type'}' caps='$params->{'caps'}'/>" . $self->xml_footer;
-}
-
 1;

Added: trunk/cgi-bin/LJ/EventsFeed/UserSuspend.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/UserSuspend.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/EventsFeed/UserSuspend.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -0,0 +1,7 @@
+package LJ::EventsFeed::UserSuspend;
+
+use strict;
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'user_suspend'  }
+ 
+1;

Modified: trunk/cgi-bin/LJ/EventsFeed/UserUnDeleted.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/UserUnDeleted.pm	2011-06-09 04:19:08 UTC (rev 10613)
+++ trunk/cgi-bin/LJ/EventsFeed/UserUnDeleted.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -1,28 +1,7 @@
 package LJ::EventsFeed::UserUnDeleted;
 
 use strict;
-use base 'LJ::EventsFeed';
-use Carp qw (croak);
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'undeleted' }
 
-sub new {
-    my ($class, $u) = @_;
-
-    croak "Must pass an LJ::User" unless LJ::isu($u);
-
-    return $class->SUPER::new(
-                              id    => $u->userid,
-                              login => $u->user,
-                              type  => $u->journaltype,
-                              caps  => $u->caps,
-                             );
-}
-
-sub as_xml {
-    my $self = shift;
-    my $params = $self->params;
-
-    return $self->xml_head('undeleted') . "<user id='$params->{'id'}' login='$params->{'login'}'"
-           . " type='$params->{'type'}' caps='$params->{'caps'}'/>" . $self->xml_footer;
-}
-
 1;

Added: trunk/cgi-bin/LJ/EventsFeed/UserUnSuspend.pm
===================================================================
--- trunk/cgi-bin/LJ/EventsFeed/UserUnSuspend.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/EventsFeed/UserUnSuspend.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -0,0 +1,7 @@
+package LJ::EventsFeed::UserUnSuspend;
+
+use strict;
+use base 'LJ::EventsFeed::UserEvent';
+sub xml_tag_name { return 'user_unsuspend' }
+ 
+1;

Modified: trunk/cgi-bin/LJ/Hooks/EventsFeed.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/EventsFeed.pm	2011-06-09 04:19:08 UTC (rev 10613)
+++ trunk/cgi-bin/LJ/Hooks/EventsFeed.pm	2011-06-09 07:22:04 UTC (rev 10614)
@@ -20,6 +20,16 @@
     LJ::EventsFeed::UserDeleted->new($u)->fire;
 });
 
+LJ::register_hook('account_suspend', sub {
+    my $u = shift;
+    LJ::EventsFeed::UserSuspend->new($u)->fire;
+});
+
+LJ::register_hook('account_unsuspend', sub {
+    my $u = shift;
+    LJ::EventsFeed::UserUnSuspend->new($u)->fire;
+});
+
 LJ::register_hook('defriended', sub {
     my ($u, $friendee) = @_;
 

Tags: gariev, ljcom, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments