<?php
-
/**
- * Maintenance script to delete revisions which refer to a nonexisting page
- * Sometimes manual deletion done in a rush leaves crap in the database
+ * Delete revisions which refer to a nonexisting page.
+ * Sometimes manual deletion done in a rush leaves crap in the database.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
+ * @file
* @ingroup Maintenance
* @author Rob Church <robchur@gmail.com>
* @todo More efficient cleanup of text records
*/
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
+/**
+ * Maintenance script that deletes revisions which refer to a nonexisting page.
+ *
+ * @ingroup Maintenance
+ */
class DeleteOrphanedRevisions extends Maintenance {
public function __construct() {
parent::__construct();
$report = $this->hasOption( 'report' );
$dbw = wfGetDB( DB_MASTER );
- $dbw->begin();
+ $dbw->begin( __METHOD__ );
list( $page, $revision ) = $dbw->tableNamesN( 'page', 'revision' );
# Find all the orphaned revisions
# Stash 'em all up for deletion (if needed)
$revisions = array();
- foreach ( $res as $row )
+ foreach ( $res as $row ) {
$revisions[] = $row->rev_id;
+ }
$count = count( $revisions );
$this->output( "found {$count}.\n" );
# Nothing to do?
if ( $report || $count == 0 ) {
- $dbw->commit();
+ $dbw->commit( __METHOD__ );
exit( 0 );
}
$this->output( "done.\n" );
# Close the transaction and call the script to purge unused text records
- $dbw->commit();
+ $dbw->commit( __METHOD__ );
$this->purgeRedundantText( true );
}
* Do this inside a transaction
*
* @param $id Array of revision id values
- * @param $dbw Database class (needs to be a master)
+ * @param $dbw DatabaseBase class (needs to be a master)
*/
private function deleteRevs( $id, &$dbw ) {
- if ( !is_array( $id ) )
+ if ( !is_array( $id ) ) {
$id = array( $id );
+ }
$dbw->delete( 'revision', array( 'rev_id' => $id ), __METHOD__ );
}
}
$maintClass = "DeleteOrphanedRevisions";
-require_once( RUN_MAINTENANCE_IF_MAIN );
-
+require_once RUN_MAINTENANCE_IF_MAIN;