Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DeleteBadTags
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3$IP = getenv( 'MW_INSTALL_PATH' );
4if ( $IP === false ) {
5    $IP = __DIR__ . '/../../..';
6}
7require_once "$IP/maintenance/Maintenance.php";
8
9class DeleteBadTags extends Maintenance {
10    public function __construct() {
11        parent::__construct();
12        $this->addDescription( 'Delete empty Code Review tags' );
13        $this->addOption( 'dry-run', 'Don\'t actually delete bad tags, just compile statistics.' );
14        $this->requireExtension( 'CodeReview' );
15    }
16
17    public function execute() {
18        $dbw = wfGetDB( DB_PRIMARY );
19        $dbw->begin( __METHOD__ );
20        $dbw->delete( 'code_tags', [ 'ct_tag' => '' ], __METHOD__ );
21        $count = $dbw->affectedRows();
22
23        $this->output( "Deleting empty tags...\n" );
24        if ( !$this->getOption( 'dry-run' ) ) {
25            $dbw->commit( __METHOD__ );
26            $this->output( "$count bad tags deleted. Done!\n" );
27        } else {
28            $dbw->rollback( __METHOD__ );
29            $this->output( "$count bad tags. Not committed!\n" );
30        }
31    }
32}
33
34$maintClass = DeleteBadTags::class;
35require_once RUN_MAINTENANCE_IF_MAIN;