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-04-25 02:30 am

[dw-free] Finishing up payment system

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

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

Oops, this should return how many are available, not how many have been
sold. Sorry, Janine\!

Patch by [personal profile] janinedog.

Files modified:
  • cgi-bin/DW/Pay.pm
--------------------------------------------------------------------------------
diff -r a2b4788d9fd3 -r 1c3631ebb55d cgi-bin/DW/Pay.pm
--- a/cgi-bin/DW/Pay.pm	Sat Apr 25 02:28:41 2009 +0000
+++ b/cgi-bin/DW/Pay.pm	Sat Apr 25 02:30:32 2009 +0000
@@ -328,18 +328,24 @@ sub num_permanent_accounts_available {
     return 0 unless $LJ::PERMANENT_ACCOUNT_LIMIT;
     return -1 if $LJ::PERMANENT_ACCOUNT_LIMIT < 0;
 
+    # 1. figure out how many permanent accounts have been purchased
+
     # try memcache first
     my $ct = LJ::MemCache::get( 'numpermaccts' );
-    return $ct if defined $ct;
 
-    # not in memcache, so let's hit the database
-    # FIXME: add ddlockd so we don't hit the db in waves every 60 seconds
-    my $dbh = DW::Pay::get_db_writer()
-        or return error( ERR_TEMP, "Unable to get db writer." );
-    my $ct = $dbh->selectrow_array( 'SELECT COUNT(*) FROM dw_paidstatus WHERE permanent = 1' )+0;
-    LJ::MemCache::set( 'numpermaccts', $ct, 60 );
+    unless ( defined $ct ) {
+        # not in memcache, so let's hit the database
+        # FIXME: add ddlockd so we don't hit the db in waves every 60 seconds
+        my $dbh = DW::Pay::get_db_writer()
+            or return error( ERR_TEMP, "Unable to get db writer." );
+        $ct = $dbh->selectrow_array( 'SELECT COUNT(*) FROM dw_paidstatus WHERE permanent = 1' )+0;
+        LJ::MemCache::set( 'numpermaccts', $ct, 60 );
+    }
 
-    return $ct;
+    # 2. figure out how many are left to purchase
+
+    my $num_available = $LJ::PERMANENT_ACCOUNT_LIMIT - $ct;
+    return $num_available > 0 ? $num_available : 0;
 }
 
 ################################################################################
--------------------------------------------------------------------------------

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