MediaWiki master
deleteArchivedRevisions.php
Go to the documentation of this file.
1<?php
27
28// @codeCoverageIgnoreStart
29require_once __DIR__ . '/Maintenance.php';
30// @codeCoverageIgnoreEnd
31
39 public function __construct() {
40 parent::__construct();
41 $this->addDescription(
42 "Deletes all archived revisions\nThese revisions will no longer be restorable" );
43 $this->addOption( 'delete', 'Performs the deletion' );
44 }
45
46 public function execute() {
47 $dbw = $this->getPrimaryDB();
48
49 if ( !$this->hasOption( 'delete' ) ) {
50 $count = $dbw->newSelectQueryBuilder()
51 ->select( 'COUNT(*)' )
52 ->from( 'archive' )
53 ->caller( __METHOD__ )
54 ->fetchField();
55 $this->output( "Found $count revisions to delete.\n" );
56 $this->output( "Please run the script again with the --delete option "
57 . "to really delete the revisions.\n" );
58 return;
59 }
60
61 $this->output( "Deleting archived revisions..." );
62 $dbw->newDeleteQueryBuilder()
63 ->deleteFrom( 'archive' )
64 ->where( '*' )
65 ->caller( __METHOD__ )->execute();
66 $count = $dbw->affectedRows();
67 $this->output( "done. $count revisions deleted.\n" );
68
69 if ( $count ) {
70 $this->purgeRedundantText( true );
71 }
72 }
73}
74
75// @codeCoverageIgnoreStart
76$maintClass = DeleteArchivedRevisions::class;
77require_once RUN_MAINTENANCE_IF_MAIN;
78// @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.
addDescription( $text)
Set the description text.