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

[ljcom] r9406: LJSUP-6609. Modify delivery worker in pr...

Committer: gprochaev
LJSUP-6609. Modify delivery worker in prod. to be able to deliver "userheads" on beta servers

U   branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Userpics/Large.pm
U   branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/Addon.pm
U   branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/RecBillAble.pm
A   branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/UserHead.pm
U   branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem.pm
U   branches/r68.4/cgi-bin/LJ/Pay/RecBill/Item.pm
Modified: branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Userpics/Large.pm
===================================================================
--- branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Userpics/Large.pm	2010-08-26 07:03:32 UTC (rev 9405)
+++ branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/Addon/Userpics/Large.pm	2010-08-26 07:43:47 UTC (rev 9406)
@@ -1,5 +1,8 @@
 package LJ::Pay::Payment::PayItem::Addon::Userpics::Large;
 use strict;
+
+sub is_recbillable { 1 }
+
 use base "LJ::Pay::Payment::PayItem::Addon::Packed";
 sub item { return 'userpic_large'; } 
 
@@ -20,8 +23,6 @@
 
 sub get_packet_size { 70 }
 
-sub is_recbillable { 1 }
-
 sub get_item_data {
     my $self = shift;
     return \%LJ::Pay::Payment::PayItem::Addon::userpic_large;

Modified: branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/Addon.pm
===================================================================
--- branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/Addon.pm	2010-08-26 07:03:32 UTC (rev 9405)
+++ branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/Addon.pm	2010-08-26 07:43:47 UTC (rev 9406)
@@ -6,6 +6,7 @@
 use LJ::Pay::Util qw/_err _get_dbh _debug/;
 use LJ::TimeUtil;
 
+sub is_recbillable { 1 } 
 sub should_recheck_cart { return 1; }
 sub _activate_item { die 'Must be redeclared in child class'; }
 sub _adopt_item { die 'Must be redeclared in child class'; }
@@ -383,7 +384,7 @@
         $$error_ref = "Can't activate item: $$error_ref" if $error_ref;
         return;
     }
-    
+
     unless ($item_to_deliver->add_paidexp_time(
                 exp         => $exp, 
                 new_size    => $new_size, 
@@ -406,7 +407,7 @@
 sub load_paidexp_row {
     my ($class, $u) = @_;
 
-    my $item = $class->item;
+    my $item = $class->paidexp_item;
 
     # allow u/payitem objects passed optionally
     my $userid = LJ::want_userid($u);

Modified: branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/RecBillAble.pm
===================================================================
--- branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/RecBillAble.pm	2010-08-26 07:03:32 UTC (rev 9405)
+++ branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/RecBillAble.pm	2010-08-26 07:43:47 UTC (rev 9406)
@@ -106,22 +106,22 @@
 
 sub validate_recbill_fields {
     my $self = shift;
-    _err("Must be redefined in child class");
+    $self->is_recbillable ? _err("Must be redefined in child class") : 1;
 }
 
 sub load_for_recbill {
     my $self = shift;
-    _err("Must be redefined in child class");
+    $self->is_recbillable ? _err("Must be redefined in child class") : 1;
 }
 
 sub set_exptime {
     my $self = shift;
-    _err("Must be redefined in child class");
+    $self->is_recbillable ? _err("Must be redefined in child class") : 1;
 }
 
 sub set_lastmailed {
     my $self = shift;
-    _err("Must be redefined in child class");
+    $self->is_recbillable ? _err("Must be redefined in child class") : 1;
 }
 
 1;

Added: branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/UserHead.pm
===================================================================
--- branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/UserHead.pm	                        (rev 0)
+++ branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem/UserHead.pm	2010-08-26 07:43:47 UTC (rev 9406)
@@ -0,0 +1,95 @@
+package LJ::Pay::Payment::PayItem::UserHead;
+
+use strict;
+
+use base "LJ::Pay::Payment::PayItem::Addon";
+use LJ::Pay::Util qw/ _err _get_dbh/;
+
+sub item { return 'userhead'; }
+sub paidexp_item {
+    my $self = shift;
+
+    return $self->{subitem};
+}
+
+sub _adopt_item {
+    my $self = shift;
+    my %args = @_;
+
+    my $exp   = $args{exp};
+    my $u     = $args{u};
+    my $payid = $args{payid};
+    my $time  = $args{time};    ## next check date for recbill payments, undef for regular ones
+
+    return (1, 12);
+}
+
+sub is_recbillable { 0 }
+
+sub validate_user_input {
+    my ($self, $cartobj, $errs_ref, $warns_ref, $action) = @_;
+
+    unless ($self->{'rcptid'}) {
+        push @$errs_ref, LJ::Lang::ml('/pay/modify.bml.error.no_rcptid');
+        return 0;
+    }
+
+    return 1;
+}
+
+sub get_product_name {
+    my ($class, $subitem, $qty, $short) = @_;
+
+    return LJ::Lang::ml('pay.product.userhead') . ($short ? "" : " - " . "");
+}
+
+sub render_cart_item {
+    my $self = shift;
+    my $opts = shift;
+
+    my %result; # keys in hash = columns in page: name(item), type, recipient
+
+    my $subitem = $self->{subitem};
+    my ($uh_id) = $subitem =~ m#uh-(\d+)#;
+    my $uh = LJ::UserHead->get_userhead ($uh_id);
+
+    $result{name} = LJ::Lang::ml('pay.cart.item.userhead');
+    $result{type} = "<img src='".$uh->get_uh_img."'>";
+
+    return \%result;
+}
+
+sub can_belong_to {
+    return 1;
+}
+
+sub get_expire_times {
+    my ($self, $u) = @_;
+    my $userid =    ($u)        ? LJ::want_userid($u) :
+                    (ref $self) ? $self->{rcptid} :
+                    die "Userid is required";
+
+    my $dbh = _get_dbh();
+    my $res = $dbh->selectall_arrayref("SELECT item, UNIX_TIMESTAMP(expdate) as expdate, size " .
+                                                 "FROM paidexp WHERE userid=?",
+                                                 { Slice => {} }, $userid);
+
+    return [ grep { $_->{item} =~ /uh-\d+/ } @$res ];
+}
+
+sub _activate_item {
+    return 1;
+}
+
+sub _deactivate_item {
+    my $self = shift;
+    my %args = @_;
+
+    my $u = LJ::load_userid($args{u});
+    return undef unless $u;
+
+    $u->set_custom_usericon (undef);
+}
+
+1;
+

Modified: branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem.pm
===================================================================
--- branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem.pm	2010-08-26 07:03:32 UTC (rev 9405)
+++ branches/r68.4/cgi-bin/LJ/Pay/Payment/PayItem.pm	2010-08-26 07:43:47 UTC (rev 9406)
@@ -46,6 +46,7 @@
     'userpic_small' => 'LJ::Pay::Payment::PayItem::Addon::Userpics::Small',
     'userpic_large' => 'LJ::Pay::Payment::PayItem::Addon::Userpics::Large',
     'tokens'        => 'LJ::Pay::Payment::PayItem::WalletTokens',
+    'userhead'      => 'LJ::Pay::Payment::PayItem::UserHead',
 );
 
 my @FREEZABLE_CLASSES = qw/
@@ -65,6 +66,12 @@
     return $CLASSES{$item};
 }
 
+sub paidexp_item {
+    my $self = shift;
+
+    return $self->item;
+}
+
 sub new {
     my $class = shift;
 
@@ -87,7 +94,12 @@
     my $class = ref($s) || $s;
     if ($class eq 'LJ::Pay::Payment::PayItem') { 
         # parent class call -> need factory
-        my $child_class = $class->get_class_for_item($args{item}) 
+        my $item = $args{item};
+
+        ## Exception: UserHeads has a 'uh-\d+' coding in a paidexp table
+        $item = ($item =~ m#uh-\d+#) ? 'userhead' : $item;
+        ## 
+        my $child_class = $class->get_class_for_item($item) 
             or return _err("No class for item '$args{item}'");
         return $child_class->new_memonly(%args);
     } else {

Modified: branches/r68.4/cgi-bin/LJ/Pay/RecBill/Item.pm
===================================================================
--- branches/r68.4/cgi-bin/LJ/Pay/RecBill/Item.pm	2010-08-26 07:03:32 UTC (rev 9405)
+++ branches/r68.4/cgi-bin/LJ/Pay/RecBill/Item.pm	2010-08-26 07:43:47 UTC (rev 9406)
@@ -194,9 +194,12 @@
 
     return $invalid->('userid')
         unless $self->{userid} > 0;
-    return $invalid->('name')
-        unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
 
+    if ($item_obj->is_recbillable) {
+        return $invalid->('name')
+            unless $item_obj->isa('LJ::Pay::Payment::PayItem::RecBillAble');
+    }
+
     return $invalid->('exptime') unless $self->{exptime} > 0;
 
     $self->{lastmailed} = undef unless $self->{lastmailed} > 0;

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