Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DeleteArchivedRevisions | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Delete archived (deleted from public) revisions from the database |
| 4 | * |
| 5 | * Shamelessly stolen from deleteOldRevisions.php by Rob Church :) |
| 6 | * |
| 7 | * @license GPL-2.0-or-later |
| 8 | * @file |
| 9 | * @ingroup Maintenance |
| 10 | */ |
| 11 | |
| 12 | use MediaWiki\Maintenance\Maintenance; |
| 13 | |
| 14 | // @codeCoverageIgnoreStart |
| 15 | require_once __DIR__ . '/Maintenance.php'; |
| 16 | // @codeCoverageIgnoreEnd |
| 17 | |
| 18 | /** |
| 19 | * Maintenance script to delete archived (deleted from public) revisions |
| 20 | * from the database. |
| 21 | * |
| 22 | * @ingroup Maintenance |
| 23 | */ |
| 24 | class DeleteArchivedRevisions extends Maintenance { |
| 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; |
| 63 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 64 | // @codeCoverageIgnoreEnd |