журнал (shhh) wrote in changelog,
журнал
shhh
changelog

[livejournal] r22485: LJSUP-13017: Paid Repost in update.bml a...

Committer: nnikulochkina
LJSUP-13017: Paid Repost in update.bml and editjournal.bml
U   trunk/bin/upgrading/en.dat
U   trunk/cgi-bin/ljprotocol.pl
U   trunk/cgi-bin/weblib.pl
Modified: trunk/bin/upgrading/en.dat
===================================================================
--- trunk/bin/upgrading/en.dat	2012-07-23 10:48:43 UTC (rev 22484)
+++ trunk/bin/upgrading/en.dat	2012-07-23 13:11:44 UTC (rev 22485)
@@ -9441,6 +9441,7 @@
 xmlrpc.error.158=You have no rights to make this entry sticky
 xmlrpc.error.159=Cannot create scheduled entry containing paid repost button
 xmlrpc.error.160=Cannot create or edit paid repost offer
+xmlrpc.error.161=Cannot revoke paid repost offer
 xmlrpc.error.200=Missing required argument(s)
 xmlrpc.error.201=Unknown method
 xmlrpc.error.202=Too many arguments

Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2012-07-23 10:48:43 UTC (rev 22484)
+++ trunk/cgi-bin/ljprotocol.pl	2012-07-23 13:11:44 UTC (rev 22485)
@@ -75,6 +75,7 @@
      "158" => E_TEMP,
      "159" => E_PERM,
      "160" => E_TEMP,
+     "161" => E_PERM,    
 
      # Client Errors
      "200" => E_PERM,
@@ -2832,9 +2833,9 @@
         unless ( $offer_id ) {
             LJ::delete_entry($uowner, $jitemid, undef, $anum); # roll-back
             return fail($err,160,$error);
+        } else {
+            $req->{props}->{repost_offer} = $offer_id;
         }
-        
-        $req->{props}->{repost_offer} = $offer_id;
     }
 
     # Entry tags
@@ -3269,11 +3270,27 @@
     my %curprops;
     LJ::load_log_props2($dbcm, $ownerid, [ $itemid ], \%curprops);
 
-    # edit or create repost_offer
-    my $repost_offer;
 
-    if (defined $req->{repost_budget} && LJ::is_enabled("paid_repost") ) {
+    # create, edit, revoke repost offer
+    my ($repost_offer, $repost_offer_action);
+    
+    if( LJ::is_enabled("paid_repost") 
+        && $req->{revoke_repost_offer} 
+        && $curprops{$itemid}->{repost_offer} ) {
 
+        # cannot revoke repost offer via api
+        return fail($err,222) unless $flags->{noauth};
+
+        $repost_offer_action = 'revoke';
+
+        $repost_offer = LJ::Pay::Repost::Offer->get_repost_offer(
+            $posterid,
+            $curprops{$itemid}->{repost_offer},
+        );
+    }
+
+    if (LJ::is_enabled("paid_repost") && defined $req->{repost_budget} && !$req->{revoke_repost_offer}) {
+      
         # cannot create or edit repost offer via api
         return fail($err,222) unless $flags->{noauth};
 
@@ -3297,10 +3314,18 @@
         return fail($err,160,$error) unless $res;
       
         if ($repost_offer->{id}) {
-            # no need to update repost offer
-            undef $repost_offer if ($previous->budget == $repost_offer->{budget});
+
+            unless ($repost_offer->{budget} == $previous->budget) {
+                $repost_offer_action = 'edit';
+                $repost_offer = $previous;
+            } else {
+                # no need to update repost offer
+                undef $repost_offer;
+            }
+
         } else {
-            # no need to create repost offer
+            $repost_offer_action = 'create';
+            # no need to create repost offer with zero budget
             undef $repost_offer unless $repost_offer->{budget};
         }
     }
@@ -3455,33 +3480,29 @@
 
     # update or create repost offer
     if ($repost_offer) {
-        my $error = '';
+        my ($error, $warning); 
 
-        unless($repost_offer->{id}) {
-            my $offer_id = LJ::Pay::Repost::Offer->create(
-                \$error,
-                %$repost_offer,
-            );
+        if($repost_offer_action eq 'create') {
 
-            unless ($offer_id) {
-                my $warning;
+            my $offer_id = LJ::Pay::Repost::Offer->create(\$error, %$repost_offer) or 
                 fail(\$warning,160,$error);
-                push @{$res->{warnings} ||= []}, error_message($warning); 
-            }
+            
+            $req->{props}->{repost_offer} = $offer_id if $offer_id;
+            
+        } elsif($repost_offer_action eq 'edit') {
+            
+            $repost_offer->mark_active if $repost_offer->inactive;
 
-            $req->{props}->{repost_offer} = $offer_id;
-        } else {
-            my $res = LJ::Pay::Repost::Offer->set_budget(
-                \$error,
-                $repost_offer,
-            );
-              
-            unless ($res) {
-                my $warning;
+            $repost_offer->set_budget(\$error, int $req->{repost_budget}) or 
                 fail(\$warning,160,$error);
-                push @{$res->{warnings} ||= []}, error_message($warning);
-            }
+       
+        } elsif($repost_offer_action eq 'revoke') {
+            
+            $repost_offer->revoke(\$error) or 
+                fail(\$warning,161,$error);
         }
+
+        push @{$res->{warnings} ||= []}, error_message($warning) if $warning;
     }
 
 

Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl	2012-07-23 10:48:43 UTC (rev 22484)
+++ trunk/cgi-bin/weblib.pl	2012-07-23 13:11:44 UTC (rev 22485)
@@ -1158,7 +1158,7 @@
                 prop_opt_preformatted prop_opt_nocomments prop_opt_lockcomments
                 prop_current_location prop_current_coords
                 prop_taglist prop_qotdid prop_give_features 
-                repost_budget)) {
+                repost_budget revoke_repost_offer)) {
         $req->{$_} = $POST->{$_};
     }
 

Tags: dat, livejournal, nikulochkina, nnikulochkina, pl
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