User:AnomieBOT/source/tasks/AFDMergeFromCleaner.pm: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: General: * New function to load a task (once). * Update the various scripts to use that function. * Update metadata for all tasks. SourceUploader: * Generate a new file, User:AnomieBOT/TaskList, since I keep forgetting
AnomieBOT (talk | contribs)
Updating published sources: General: * BREAKING CHANGE: And it's a big one: ** Data store changed from (binary) Storable to (readable) JSON. update-db.pl will change an existing database. This may affect the exact values storable in the permanent sto
Line 51:
my $res;
 
$api->task('AFDMergeFromCleaner', 0, 10, qw/d::Util/);
$api->read_throttle(0);
$api->edit_throttle(10);
 
if($self->{'nextrun'}==0 && exists($api->store->{'nextrun'})){
my $t=$api->fetch(store->{'nextrun')};
$self->{'nextrun'}=$$t if(defined($t) && $$t=~/^\d+$/);
}
my $starttime=time();
Line 98 ⟶ 96:
$res=$api->query(%q);
if($res->{'code'} ne 'success'){
$selfapi->warn("Failed to retrieve transclusion list for $template: ".$res->{'error'}."\n");
$ret=60;
last MAINLOOP;
Line 118 ⟶ 116:
}
 
$selfapi->warn("Checking for $template in $title\n");
 
# WTF?
if(exists($_->{'missing'})){
$selfapi->warn("$title is missing? WTF?\n");
next;
}
Line 129 ⟶ 127:
my $tok=$api->edittoken($title);
if($tok->{'code'} eq 'shutoff'){
$selfapi->warn("Task disabled: ".$tok->{'content'}."\n");
return 300;
}
if($tok->{'code'} ne 'success'){
$selfapi->warn("Failed to get edit token for $title: ".$tok->{'error'}."\n");
$ret=60;
last MAINLOOP;
Line 144 ⟶ 142:
# First, find the template and pull out the relevant parameter
my @from=();
$selfapi->process_templates($intxt, sub {
return undef unless exists($templates{'Template:'.$_[0]});
my $f=undef;
foreach ($selfapi->process_paramlist(@{$_[1]})){
($f=$_->{'value'})=~s/^\s+|\s+$//g if $_->{'name'} eq 1;
}
Line 160 ⟶ 158:
$res=$api->query(titles => join('|',@f), redirects=>1);
if($res->{'code'} ne 'success'){
$selfapi->warn("Failed to retrieve mergefrom page list for $title: ".$res->{'error'}."\n");
$ret=60;
last MAINLOOP;
Line 186 ⟶ 184:
 
# Remove the removable templates
my $outtxt=$selfapi->process_templates($intxt, sub {
my $name=shift;
my @params=@{shift()};
Line 195 ⟶ 193:
return undef unless exists($templates{'Template:'.$name});
my $f=undef;
foreach ($selfapi->process_paramlist(@params)){
($f=$_->{'value'})=~s/^\s+|\s+$//g if $_->{'name'} eq 1;
}
Line 208 ⟶ 206:
if($outtxt ne $intxt){
my $summary="Removing obsolete {{$template}}";
$selfapi->warn("$summary in $title\n");
my $r=$api->edit($tok, $outtxt, $summary.$screwup, 1, 1);
if($r->{'code'} ne 'success'){
$selfapi->warn("Write failed on $title: ".$r->{'error'}."\n");
next;
}
Line 222 ⟶ 220:
my $tok=$api->edittoken($report);
if($tok->{'code'} eq 'shutoff'){
$selfapi->warn("Task disabled: ".$tok->{'content'}."\n");
return 300;
}
if($tok->{'code'} ne 'success'){
$selfapi->warn("Failed to get edit token for $report: ".$tok->{'error'}."\n");
$ret=60;
last;
Line 266 ⟶ 264:
if($outtxt ne $intxt){
my $summary="Updating list of non-matching merges";
$selfapi->warn("$summary in $report\n");
my $r=$api->edit($tok, $outtxt, $summary.$screwup, 1, 1);
if($r->{'code'} ne 'success'){
$selfapi->warn("Write failed on $report: ".$r->{'error'}."\n");
$ret=60;
}
Line 277 ⟶ 275:
$starttime+=$ret;
$self->{'nextrun'}=$starttime;
$api->store(->{'nextrun', \}=$starttime);
 
return $ret;