Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2095] temporarily disable LJRossia crossposts #2104

Merged
merged 3 commits into from
Apr 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions cgi-bin/DW/Worker/XPostWorker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ sub work {
my $acct = DW::External::Account->get_external_account( $u, $acctid )
or return $job->failed("Unable to load account $acctid for uid $uid");

my $sclient = LJ::theschwartz();
my $notify_fail = sub {
$sclient->insert_jobs(
LJ::Event::XPostFailure->new(
$u, $acctid, $ditemid, ( $_[0] || 'Unknown error message.' )
)->fire_job
);
};

# LJRossia is temporarily broken, so skip - but we do want to notify
if ( $acct->externalsite && $acct->externalsite->{sitename} eq 'LJRossia' ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, is this really the best way of doing this?! Hardcoding like this feels pretty sad, but I guess the original design of the xpost system didn't take into account that we might want to administratively disable things? I don't recall thinking of this use case :)

my $ljr_msg = "Crossposts to LJRossia are disabled until the remote site fixes their XMLRPC protocol handler.";
$notify_fail->( $ljr_msg );
return $job->permanent_failure( $ljr_msg );
}

my $domain = $acct->externalsite ? $acct->externalsite->{domain} : 'unknown';

my $entry = LJ::Entry->new( $u, ditemid => $ditemid );
Expand All @@ -78,7 +94,6 @@ sub work {
my $start = [ gettimeofday ];
my $result = $delete ? $acct->delete_entry(\%auth, $entry) : $acct->crosspost(\%auth, $entry);

my $sclient = LJ::theschwartz();
if ($result->{success}) {
$sclient->insert_jobs(LJ::Event::XPostSuccess->new($u, $acctid, $ditemid)->fire_job );
DW::Stats::increment( 'dw.worker.crosspost.success', 1, [ "domain:$domain" ] );
Expand All @@ -97,11 +112,7 @@ sub work {
}

# Some other failure, so let's just let it go through.
$sclient->insert_jobs(
LJ::Event::XPostFailure->new(
$u, $acctid, $ditemid, ( $result->{error} || 'Unknown error message.' )
)->fire_job
);
$notify_fail->( $result->{error} );
DW::Stats::increment( 'dw.worker.crosspost.failure', 1, [ "domain:$domain" ] );
# FIXME: subroutine not implemented
# DW::Stats::timing( 'dw.worker.crosspost.failure_time', $start, [ "domain:$domain" ] );
Expand Down
36 changes: 19 additions & 17 deletions htdocs/manage/externalaccount.bml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ body<=
use strict;
{
use vars qw(%GET %POST $title $windowtitle $headextra @errors @warnings);

if ($LJ::USE_SSL && ! $LJ::IS_SSL && $FORM{ssl} ne "no") {
my $getextra = $GET{acctid} ? "?acctid=" . LJ::eurl($GET{acctid}) : "";
return BML::redirect("$LJ::SSLROOT/manage/externalaccount$getextra");
Expand Down Expand Up @@ -61,7 +61,7 @@ use strict;
$editpage = 1;
}
}

$title = $editpage ? $ML{'.title.edit'} : $ML{'.title.new'};

my $body .= qq {
Expand All @@ -86,28 +86,30 @@ use strict;
} else {
my @sitevalues;
my @sites = DW::External::Site->get_xpost_sites;

# sort the sites for the site dropdown, but also add in the protocol
# map for the options hide/show
$body .= "<script type='text/javascript'>\n";
foreach my $site (sort { $a->{sitename} cmp $b->{sitename} } @sites) {
# LJRossia is temporarily broken, so remove from list
next if $site->{sitename} eq 'LJRossia';
push @sitevalues, $site->{siteid}, $site->{sitename};
$body .= "siteProtocolMap[" . $site->{siteid} . "] = '" . $site->servicetype . "';\n";
}
$body .= "</script>\n";

# add the custom site option
push @sitevalues, '-1';
push @sitevalues, $ML{'.setting.xpost.option.site.custom'};

# the values for the protocol selection dropdown for custom sites
my %protocolselectmap;
foreach my $protocol (keys %protocols) {
$protocolselectmap{$protocol} = $protocol;
}

$body .= "<td>" . LJ::html_select({
name => "site",
name => "site",
onchange => "updateSiteSelection()",
selected => $POST{site} || '2'
}, @sitevalues);
Expand All @@ -116,7 +118,7 @@ use strict;
$body .= "<br />$servicetype_errdiv\n" if $servicetype_errdiv;

$body .= "<table summary='' id='customsite'>";

$body .= "<tr><td class='setting_label'><label for='servicetype'>" . $ML{'.setting.xpost.option.servicetype'} . "</label></td>";
$body .= "<td>" . LJ::html_select({
name => "servicetype",
Expand All @@ -137,7 +139,7 @@ use strict;

# servicename
$body .= "<tr class='customsite_all'><td class='setting_label'><label for='servicename'>" . $ML{'.setting.xpost.option.servicename'} . "</label></td>";
$body .= "<td>" . LJ::html_text({
$body .= "<td>" . LJ::html_text({
name => "servicename",
id => "servicename",
value => $POST{servicename},
Expand All @@ -149,7 +151,7 @@ use strict;
my $servicename_errdiv = errdiv(\%errs, "servicename");
$body .= "<br />$servicename_errdiv" if $servicename_errdiv;
$body .= "</td></tr>\n";

# serviceurl
$body .= "<tr class='customsite_all'><td class='setting_label'><label for='serviceurl'>" . $ML{'.setting.xpost.option.serviceurl'} . "</label></td>";
$body .= "<td>" . LJ::html_text({
Expand All @@ -165,7 +167,7 @@ use strict;
$body .= "</td></tr>\n";

$body .= "</table>"; # end customsite table
$body .= "</td></tr>\n"; # end
$body .= "</td></tr>\n"; # end
}

$body .= "<tr><td class='setting_label'><label for='username'>" . $ML{'.setting.xpost.option.username'} . "</label></td>";
Expand Down Expand Up @@ -231,22 +233,22 @@ use strict;
name => "savepassword",
value => 1,
id => "savepassword",
selected => LJ::did_post() ?
selected => LJ::did_post() ?
$POST{savepassword} :
$editpage ? $editacct->password ne "" : 1,
});
my $savepassword_errdiv = errdiv(\%errs, "savepassword");
$body .= "<br />$savepassword_errdiv" if $savepassword_errdiv;
$body .= "</td></tr>\n";

# put in the protocol option section for each protocol
foreach my $protocol_id ( keys %protocols ) {
my $protocol = $protocols{$protocol_id};
my @protocol_options = $protocol->protocol_options( $editacct, LJ::did_post() ? \%POST : undef );
if ( @protocol_options ) {
$body .= "<tbody class='protocol_options' id='" . $protocol_id . "_options'><tr><td>" . BML::ml( '.protocol.options', { protocol => $protocol->protocolid } ) . "</td>\n";
$body .="<td>";
foreach my $option ( @protocol_options ) {
foreach my $option ( @protocol_options ) {
if ( $option->{type} eq 'select' ) {
$body .= "<label for=" . $option->{opts}->{propid} . ">" . LJ::ehtml( $option->{description} ) . "</label>" . LJ::html_select( $option->{opts}, @{$option->{options}} ) . "</td>\n";
}
Expand Down Expand Up @@ -373,7 +375,7 @@ sub create_external_account {
if ( $opts{siteid} ) {
my $site = DW::External::Site->get_site_by_id( $opts{siteid} );
$protocol = DW::External::XPostProtocol->get_protocol( $site->servicetype );
} else {
} else {
$protocol = DW::External::XPostProtocol->get_protocol( $opts{servicetype} );
}
my $options = parse_options( $protocol, $extacct_info );
Expand All @@ -391,7 +393,7 @@ sub create_external_account {
return 0;
}
}

return $ok;
}

Expand All @@ -409,7 +411,7 @@ sub account_isvalid {
$proxyurl = "http://" . $externalsite->{domain} . "/interface/xmlrpc";
$protocol_id = $externalsite->servicetype;
} else {
$proxyurl = $extacct->{serviceurl};
$proxyurl = $extacct->{serviceurl};
$protocol_id = $extacct->{servicetype};
}

Expand Down