16require_once __DIR__ .
'/Maintenance.php';
30 parent::__construct();
31 $this->
addDescription(
'Applies an existing change tag to revisions and/or log entries.' );
33 $this->
addOption(
'tag',
'Tag to apply. Must already be defined.',
true,
true );
34 $this->
addOption(
'revisions',
'A list of revision IDs to tag, separated by comma.',
false,
true );
35 $this->
addOption(
'logs',
'A list of log entry IDs to tag, separated by comma.',
false,
true );
43 if ( !in_array( $tag, $changeTagsStore->listDefinedTags(),
true ) ) {
44 $this->
fatalError(
"Tag '$tag' is not defined; define it before applying it." );
49 if ( !$revIds && !$logIds ) {
50 $this->
fatalError(
'Specify at least one of --revisions or --logs.' );
54 $applied += $this->tagTargets( $changeTagsStore, $tag, $revIds,
'revision' );
55 $applied += $this->tagTargets( $changeTagsStore, $tag, $logIds,
'logging' );
57 $this->
output(
"Applied '$tag' to $applied target(s).\n" );
70 private function tagTargets(
ChangeTagsStore $changeTagsStore,
string $tag, array $ids,
string $table ): int {
75 $isLog = $table ===
'logging';
76 $idField = $isLog ?
'log_id' :
'rev_id';
77 $existing = array_map(
82 ->where( [ $idField => $ids ] )
83 ->caller( __METHOD__ )
87 $missing = array_diff( $ids, $existing );
89 $this->
output(
"Skipping $table IDs that do not exist: " . implode(
', ', $missing ) .
"\n" );
93 foreach ( array_chunk( $existing, $this->
getBatchSize() ) as $batch ) {
95 foreach ( $batch as $id ) {
96 if ( $changeTagsStore->addTags( $tag,
null, $isLog ?
null : $id, $isLog ? $id : null ) ) {
108require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined('MW_SETUP_CALLBACK'))
Applies an existing change tag to revisions and/or log entries.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
getReplicaDB(string|false $virtualDomain=false)
parseIntList( $text)
Utility function to parse a string (perhaps from a command line option) into a list of integers (perh...
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Update the CREDITS list by merging in the list of git commit authors.