wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[ljcom] r8420: LJSUP-4203

Committer: gprochaev
LJSUP-4203

After prorate userpic item will be a userpic_large item with size = 1

U   trunk/cgi-bin/LJ/Pay/RecBill/Item.pm
U   trunk/cgi-bin/LJ/Pay/RecBill.pm
Modified: trunk/cgi-bin/LJ/Pay/RecBill/Item.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/RecBill/Item.pm	2010-04-01 17:14:11 UTC (rev 8419)
+++ trunk/cgi-bin/LJ/Pay/RecBill/Item.pm	2010-04-02 04:43:37 UTC (rev 8420)
@@ -167,7 +167,20 @@
     return @items;
 }
 
+# simply delete the item
+sub remove_from_recbill {
+    my LJ::Pay::RecBill::Item $self = shift
+        or return _err("invalid arguments");
 
+    my $dbh = _get_dbh();
+    $dbh->do("DELETE FROM recbill_items WHERE item=? AND userid=?",
+             undef, $self->get_name, $self->get_userid);
+    return _err($dbh->errstr) if $dbh->err;
+
+    return 1;
+}
+
+
 ##############################################################################
 # Class methods
 #

Modified: trunk/cgi-bin/LJ/Pay/RecBill.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/RecBill.pm	2010-04-01 17:14:11 UTC (rev 8419)
+++ trunk/cgi-bin/LJ/Pay/RecBill.pm	2010-04-02 04:43:37 UTC (rev 8420)
@@ -639,6 +639,23 @@
     return $log->save;
 }
 
+sub remove_item {
+    _debug("LJ::Pay::RecBill::add_item");
+    my LJ::Pay::RecBill $self = shift
+        or return _err("invalid fields");
+
+    # did the caller pass a pre-made item?
+    my $it = $_[0];
+
+    $it->remove_from_recbill
+        or return _err("unable to delete item");
+
+    @{$self->{items}} = grep { $_->get_name ne $it->get_name } $self->get_items;
+
+    return 1;
+}
+
+
 sub add_item {
     _debug("LJ::Pay::RecBill::add_item");
     my LJ::Pay::RecBill $self = shift
@@ -1184,7 +1201,7 @@
         my ($item, $len, $amt) = @$_;
 
         my $it = $self->get_item($item)
-            or return _err("unknown item" => $item);
+            or return _err("unknown item " => $item);
 
         my $pi = $pmt->add_item
             (
@@ -1463,6 +1480,21 @@
         #       at a higher level.
 
         foreach my $it (@items) {
+            next unless $it->get_name eq 'userpic';
+            my $it_l = LJ::Pay::RecBill::Item->new (userid => $it->get_userid, name => "userpic_large", size => $it->get_size, exptime => $it->get_exptime, daysleft => $it->get_daysleft, lastmailed => $it->get_lastmailed, recflag => $it->get_recflag);
+            $it_l->save;
+            $self->remove_item ($it);
+            $it = $it_l;
+            # manual rename userpic item in paidexp table
+            $dbh->do("UPDATE paidexp SET item = 'userpic_large', size = 1 WHERE item = 'userpic' AND userid = ?", undef, LJ::want_userid($u));
+            delete $self->{item_idx}->{'userpic'};
+
+            $self->{items} = \@items;
+            $self->{item_idx}->{$_->{name}} = $_
+                    foreach @items;
+        }
+
+        foreach my $it (@items) {
             my $item = $it->get_name;
             my $exp  = $it->get_exptime;
             my $daysleft_in_sec = $it->get_daysleft * 60*60*24;
@@ -1481,10 +1513,9 @@
                 my $prorate_len = $next_check - _max($exp, $now);
                 my $price_prorate_len = $prorate_len < $daysleft_in_sec ? 0 : $prorate_len - $daysleft_in_sec;
                 _debug("prorate_len: $prorate_len; next_check:$next_check; max:" . _max($exp, $now) . "; price_prorate_len:$price_prorate_len");
-                my $price = $self->calc_item_extension_price($item, $prorate_len - $daysleft_in_sec)
+                my $price = $self->calc_item_extension_price($it, $prorate_len - $daysleft_in_sec)
                     or return _err();
 
-                $item = 'userpic_large' if $item eq 'userpic';
                 push @to_extend, [ $item, $prorate_len, $price ];
                 _debug("push: [ $item, $prorate_len, $price ]");
             } else {
@@ -1715,15 +1746,14 @@
     my LJ::Pay::RecBill $self = shift
         or return _err("invalid arguments");
 
-    my ($item, $prorate_len) = @_;
-    return _err("invalid arguments") unless $item;
+    my ($it, $prorate_len) = @_;
+    return _err("invalid arguments") unless $it;
 
+    my $item = $it->get_name;
+
     my $u = $self->{u};
 
     # find the base price before any prorating is done
-    my $it = $self->get_item($item)
-        or return _err("invalid item");
-
     my $item_obj = $it->get_shop_item( qty => $self->{bill_interval});
     my $price = $item_obj->get_item_base_price(user => $u, expiring => 1);
     return _err("unable to calculate base price for item" => $item)

Tags: ljcom, pm, wisest-owl
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