MediaWiki master
deleteArchivedRevisions.php
Go to the documentation of this file.
1<?php
13
14// @codeCoverageIgnoreStart
15require_once __DIR__ . '/Maintenance.php';
16// @codeCoverageIgnoreEnd
17
25 public function __construct() {
26 parent::__construct();
27 $this->addDescription(
28 "Deletes all archived revisions\nThese revisions will no longer be restorable" );
29 $this->addOption( 'delete', 'Performs the deletion' );
30 }
31
32 public function execute() {
33 $dbw = $this->getPrimaryDB();
34
35 if ( !$this->hasOption( 'delete' ) ) {
36 $count = $dbw->newSelectQueryBuilder()
37 ->select( 'COUNT(*)' )
38 ->from( 'archive' )
39 ->caller( __METHOD__ )
40 ->fetchField();
41 $this->output( "Found $count revisions to delete.\n" );
42 $this->output( "Please run the script again with the --delete option "
43 . "to really delete the revisions.\n" );
44 return;
45 }
46
47 $this->output( "Deleting archived revisions..." );
48 $dbw->newDeleteQueryBuilder()
49 ->deleteFrom( 'archive' )
50 ->where( '*' )
51 ->caller( __METHOD__ )->execute();
52 $count = $dbw->affectedRows();
53 $this->output( "done. $count revisions deleted.\n" );
54
55 if ( $count ) {
56 $this->purgeRedundantText( true );
57 }
58 }
59}
60
61// @codeCoverageIgnoreStart
62$maintClass = DeleteArchivedRevisions::class;
63require_once RUN_MAINTENANCE_IF_MAIN;
64// @codeCoverageIgnoreEnd
Maintenance script to delete archived (deleted from public) revisions from the database.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.