fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-04-29 08:43 am

[dw-free] Need to record previous expiration of a now-seed-account

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

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

Don't destroy the previous expiration date, so we can see how much paid time
is transferrable.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/DW/Pay.pm
  • htdocs/admin/pay/index.bml
  • t/paid-time.t
--------------------------------------------------------------------------------
diff -r 98cc7a5bf242 -r f86159d4bcfe cgi-bin/DW/Pay.pm
--- a/cgi-bin/DW/Pay.pm	Thu Apr 28 12:46:55 2011 +0800
+++ b/cgi-bin/DW/Pay.pm	Fri Apr 29 16:43:30 2011 +0800
@@ -381,8 +381,10 @@ sub add_paid_time {
         unless $months > 0 || $days > 0 ;
 
     # okay, let's see what the user is right now to decide what to do
+    my $permanent = $months == 99 ? 1 : 0;
+
     my ( $newtypeid, $amonths, $adays, $asecs ) = ( $typeid, $months, $days, 0 );
-    my $permanent = $months == 99 ? 1 : 0;
+    $amonths = 0 if $permanent;
 
     # if they have a $ps hashref, they have or had paid time at some point
     if ( my $ps = DW::Pay::get_paid_status( $u ) ) {
@@ -400,7 +402,7 @@ sub add_paid_time {
 
             # but if they're going permanent...
             } elsif ( $permanent ) {
-                $amonths = 0;
+                $asecs = $ps->{expiresin};
 
             # but the types are different...
             } else {
diff -r 98cc7a5bf242 -r f86159d4bcfe htdocs/admin/pay/index.bml
--- a/htdocs/admin/pay/index.bml	Thu Apr 28 12:46:55 2011 +0800
+++ b/htdocs/admin/pay/index.bml	Fri Apr 29 16:43:30 2011 +0800
@@ -81,6 +81,10 @@
 
             if ( $ps->{permanent} ) {
                 $body .= '; <strong>Permanent Status</strong> will never expire.';
+
+                # but they may have transferrable paid time
+                $body .= " Has paid time up until " . LJ::mysql_time( $ps->{expiretime} )
+                    if $ps->{expiresin} > 0;
 
             } else {
                 if ( $ps->{expiresin} > 0 ) {
diff -r 98cc7a5bf242 -r f86159d4bcfe t/paid-time.t
--- a/t/paid-time.t	Thu Apr 28 12:46:55 2011 +0800
+++ b/t/paid-time.t	Fri Apr 29 16:43:30 2011 +0800
@@ -91,7 +91,7 @@ assert( $u1, 'premium', "paid +1 month =
 # seed account
 DW::Pay::add_paid_time( $u1, 'seed', 99 )
     or die DW::Pay::error_text();
-$paidmos = 0;  # never expires
+# no additional paid time, but store old value for reference
 
 assert( $u1, 'seed', "seed account" );
 
--------------------------------------------------------------------------------