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] changelog2009-05-03 06:47 pm

[dw-free] Do the right things when a paid account expires or is renewed

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

http://bugs.dwscoalition.org/show_bug.cgi?id=1067

Properly (in)activate userpics and email alises for paid/expiring users.

Patch by [personal profile] janinedog.

Files modified:
  • cgi-bin/DW/Pay.pm
  • cgi-bin/LJ/User.pm
--------------------------------------------------------------------------------
diff -r 40002de12c46 -r 27d006934a5f cgi-bin/DW/Pay.pm
--- a/cgi-bin/DW/Pay.pm	Sun May 03 17:24:19 2009 +0000
+++ b/cgi-bin/DW/Pay.pm	Sun May 03 18:47:29 2009 +0000
@@ -281,6 +281,12 @@ sub expire_user {
     DW::Pay::update_paid_status( $u, _expire => 1 );
     DW::Pay::sync_caps( $u );
 
+    # inactivate userpics (yes, this method does inactivation too)
+    $u->activate_userpics;
+
+    # disable email alias
+    $u->delete_email_alias;
+
     # happy times
     return 1;
 }
@@ -374,6 +380,12 @@ sub add_paid_time {
     # and make sure caps are always in sync
     DW::Pay::sync_caps( $u )
         if $rv;
+
+    # activate userpics
+    $u->activate_userpics;
+
+    # enable email alias
+    $u->update_email_alias;
 
     # all good, we hope :-)
     return $rv;
diff -r 40002de12c46 -r 27d006934a5f cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Sun May 03 17:24:19 2009 +0000
+++ b/cgi-bin/LJ/User.pm	Sun May 03 18:47:29 2009 +0000
@@ -3366,6 +3366,20 @@ sub should_show_in_search_results {
 ###  15. Email-Related Functions
 
 
+sub delete_email_alias {
+    my $u = shift;
+
+    return if exists $LJ::FIXED_ALIAS{$u->{user}};
+
+    my $dbh = LJ::get_db_writer();
+    $dbh->do( "DELETE FROM email_aliases WHERE alias=?",
+              undef, "$u->{user}\@$LJ::USER_DOMAIN" );
+
+    return 0 if $dbh->err;
+    return 1;
+}
+
+
 sub email_for_feeds {
     my $u = shift;
 
--------------------------------------------------------------------------------