[livejournal] r22482: LJSUP-13017: Paid Repost in update.bml a...
Committer: nnikulochkina
LJSUP-13017: Paid Repost in update.bml and editjournal.bmlU trunk/cgi-bin/LJ/Entry.pm U trunk/cgi-bin/ljprotocol.pl U trunk/cgi-bin/weblib.pl U trunk/htdocs/editjournal.bml U trunk/htdocs/update.bml
Modified: trunk/cgi-bin/LJ/Entry.pm
===================================================================
--- trunk/cgi-bin/LJ/Entry.pm 2012-07-23 09:27:42 UTC (rev 22481)
+++ trunk/cgi-bin/LJ/Entry.pm 2012-07-23 10:11:51 UTC (rev 22482)
@@ -2603,6 +2603,8 @@
# delete all comments
LJ::delete_all_comments($u, 'L', $jitemid);
+
+ $u->clear_prop('dupsig_post');
return 1;
}
Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl 2012-07-23 09:27:42 UTC (rev 22481)
+++ trunk/cgi-bin/ljprotocol.pl 2012-07-23 10:11:51 UTC (rev 22482)
@@ -23,6 +23,7 @@
LJ::PersonalStats::Ratings::Posts
LJ::PersonalStats::Ratings::Journals
LJ::API::RateLimiter
+ LJ::Pay::Repost::Offer
);
use LJ::TimeUtil;
@@ -72,6 +73,8 @@
"156" => E_TEMP,
"157" => E_TEMP,
"158" => E_TEMP,
+ "159" => E_PERM,
+ "160" => E_TEMP,
# Client Errors
"200" => E_PERM,
@@ -96,6 +99,7 @@
"219" => E_PERM,
"220" => E_PERM,
"221" => E_PERM,
+ "222" => E_PERM,
# Access Errors
"300" => E_TEMP,
@@ -2419,6 +2423,28 @@
return fail($err,103,$error) if $error;
}
+ my $repost_offer;
+
+ if ($req->{'repost_budget'} && LJ::is_enabled("paid_repost")) {
+
+ # cannot create paid repost via api
+ return fail($err,222) unless $flags->{noauth};
+
+ $repost_offer = {
+ userid => $posterid,
+ journalid => $ownerid,
+ budget => $req->{repost_budget},
+ };
+
+ my $error = '';
+ my $res = LJ::Pay::Repost::Offer->check(
+ \$error,
+ $repost_offer,
+ );
+
+ return fail($err,160,$error) unless $res;
+ }
+
# convert RTE lj-embeds to normal lj-embeds
$event = LJ::EmbedModule->transform_rte_post($event);
@@ -2520,6 +2546,8 @@
if ( $req->{'custom_time'} && LJ::DelayedEntry::is_future_date($req) ) {
return fail($err, 215) unless $req->{tz};
+ return fail($err, 159) if $repost_offer;
+
# if posting to a moderated community, store and bail out here
if ( !LJ::DelayedEntry::can_post_to($uowner, $u, $req)) {
return fail($err, 322);
@@ -2788,6 +2816,24 @@
LJ::delete_entry($uowner, $jitemid, undef, $anum); # roll-back
return fail($err,501,"logsec2:$msg");
}
+ }
+
+ if ($repost_offer) {
+ my $error = '';
+
+ $repost_offer->{jitemid} = $jitemid;
+
+ my $offer_id = LJ::Pay::Repost::Offer->create(
+ \$error,
+ %$repost_offer,
+ );
+
+ unless ( $offer_id ) {
+ LJ::delete_entry($uowner, $jitemid, undef, $anum); # roll-back
+ return fail($err,160,$error);
+ }
+
+ $req->{props}->{repost_offer} = $offer_id;
}
# Entry tags
@@ -3039,6 +3085,8 @@
return fail( $err, 217 ) if $req->{itemid} || $req->{anum};
return fail( $err, 215 ) unless $req->{tz};
+ return fail($err, 159) if $req->{repost_budget};
+
$req->{ext}->{flags} = $flags;
$req->{usejournal} = $req->{usejournal} || '';
@@ -3061,7 +3109,7 @@
return $res;
}
-
+
# updating an entry:
return undef
unless common_event_validation($req, $err, $flags);
@@ -3220,6 +3268,42 @@
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") ) {
+
+ # cannot create or edit repost offer via api
+ return fail($err,222) unless $flags->{noauth};
+
+ $repost_offer = {
+ id => $curprops{$itemid}->{repost_offer},
+ userid => $posterid,
+ journalid => $ownerid,
+ jitemid => $itemid,
+ budget => int $req->{repost_budget},
+ };
+
+ my $previous;
+
+ my $error = '';
+ my $res = LJ::Pay::Repost::Offer->check(
+ \$error,
+ $repost_offer,
+ \$previous,
+ );
+
+ 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});
+ } else {
+ # no need to create repost offer
+ undef $repost_offer unless $repost_offer->{budget};
+ }
+ }
+
# make post sticky
if ( $req->{sticky} ) {
if( $uowner->get_sticky_entry_id() != $itemid ) {
@@ -3368,6 +3452,38 @@
my $res = { 'itemid' => $itemid };
+ # update or create repost offer
+ if ($repost_offer) {
+ my $error = '';
+
+ unless($repost_offer->{id}) {
+ my $offer_id = LJ::Pay::Repost::Offer->create(
+ \$error,
+ %$repost_offer,
+ );
+
+ unless ($offer_id) {
+ my $warning;
+ fail(\$warning,160,$error);
+ push @{$res->{warnings} ||= []}, error_message($warning);
+ }
+
+ $req->{props}->{repost_offer} = $offer_id;
+ } else {
+ my $res = LJ::Pay::Repost::Offer->set_budget(
+ \$error,
+ $repost_offer,
+ );
+
+ unless ($res) {
+ my $warning;
+ fail(\$warning,160,$error);
+ push @{$res->{warnings} ||= []}, error_message($warning);
+ }
+ }
+ }
+
+
# handle tags if they're defined
if ($do_tags) {
my $tagerr = "";
@@ -4060,6 +4176,10 @@
# replycounts cease being transferred in props
delete $props{$itemid}->{'replycount'};
+ unless ($flags->{noauth}) {
+ delete $props{$itemid}->{repost_offer};
+ }
+
my $evt = $evt_from_itemid{$itemid};
$evt->{'props'} = {};
Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl 2012-07-23 09:27:42 UTC (rev 22481)
+++ trunk/cgi-bin/weblib.pl 2012-07-23 10:11:51 UTC (rev 22482)
@@ -1157,7 +1157,8 @@
prop_opt_screening prop_opt_noemail
prop_opt_preformatted prop_opt_nocomments prop_opt_lockcomments
prop_current_location prop_current_coords
- prop_taglist prop_qotdid prop_give_features)) {
+ prop_taglist prop_qotdid prop_give_features
+ repost_budget)) {
$req->{$_} = $POST->{$_};
}
Modified: trunk/htdocs/editjournal.bml
===================================================================
--- trunk/htdocs/editjournal.bml 2012-07-23 09:27:42 UTC (rev 22481)
+++ trunk/htdocs/editjournal.bml 2012-07-23 10:11:51 UTC (rev 22482)
@@ -13,6 +13,7 @@
use LJ::Widget::Fotki::Upload;
use LJ::Widget::Calendar;
use List::Util;
+ use LJ::Pay::Repost::Offer;
my $title = BML::ml('.title');
@@ -577,6 +578,14 @@
'opt_backdated' => $entry_obj->prop('opt_backdated'),
};
+ if($entry_obj->prop('repost_offer')) {
+ my $offer = LJ::Pay::Repost::Offer->get_repost_offer(
+ $entry_obj->posterid,
+ $entry_obj->prop('repost_offer'),
+ );
+ $entry->{'repost_budget'} = $offer->budget if $offer && $offer->is_active;
+ }
+
for (my $i = 1; $i <= $res{'prop_count'}; $i++) {
$entry->{"prop_" . $res{"prop_${i}_name"}} = $res{"prop_${i}_value"};
}
Modified: trunk/htdocs/update.bml
===================================================================
--- trunk/htdocs/update.bml 2012-07-23 09:27:42 UTC (rev 22481)
+++ trunk/htdocs/update.bml 2012-07-23 10:11:51 UTC (rev 22482)
@@ -343,6 +343,7 @@
'qid' => $qid,
'albums_id' => $POST{'albums_id'} || $GET{'albums_id'},
'photos_id' => $POST{'photos_id'} || $GET{'photos_id'},
+ 'repost_budget' => $POST{'repost_budget'},
};
if ($remote) {
@@ -528,6 +529,7 @@
'custom_time' => $custom_time,
'tz' => $timezone,
'posttype' => $type,
+ 'repost_budget' => $POST{'repost_budget'},
);
$flags->{'use_custom_time'} = 1;
