'DeferredUpdates' => __DIR__ . '/includes/deferred/DeferredUpdates.php',
'DeleteAction' => __DIR__ . '/includes/actions/DeleteAction.php',
'DeleteArchivedFiles' => __DIR__ . '/maintenance/deleteArchivedFiles.php',
- 'DeleteArchivedFilesImplementation' => __DIR__ . '/maintenance/deleteArchivedFiles.inc',
'DeleteArchivedRevisions' => __DIR__ . '/maintenance/deleteArchivedRevisions.php',
- 'DeleteArchivedRevisionsImplementation' => __DIR__ . '/maintenance/deleteArchivedRevisions.inc',
'DeleteBatch' => __DIR__ . '/maintenance/deleteBatch.php',
'DeleteDefaultMessages' => __DIR__ . '/maintenance/deleteDefaultMessages.php',
'DeleteEqualMessages' => __DIR__ . '/maintenance/deleteEqualMessages.php',
+++ /dev/null
-<?php
-/**
- * Core functions for deleteArchivedFiles.php
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @ingroup Maintenance
- */
-
-/**
- * Core functions for deleteArchivedFiles.php
- *
- * @ingroup Maintenance
- */
-class DeleteArchivedFilesImplementation {
- public static function doDelete( $output, $force ) {
- # Data should come off the master, wrapped in a transaction
- $dbw = wfGetDB( DB_MASTER );
- $dbw->begin( __METHOD__ );
- $tbl_arch = $dbw->tableName( 'filearchive' );
- $repo = RepoGroup::singleton()->getLocalRepo();
- # Get "active" revisions from the filearchive table
- $output->handleOutput( "Searching for and deleting archived files...\n" );
- $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key,fa_sha1 FROM $tbl_arch" );
- $count = 0;
- foreach ( $res as $row ) {
- $key = $row->fa_storage_key;
- if ( !strlen( $key ) ) {
- $output->handleOutput( "Entry with ID {$row->fa_id} has empty key, skipping\n" );
- continue;
- }
- $group = $row->fa_storage_group;
- $id = $row->fa_id;
- $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
- if ( isset( $row->fa_sha1 ) ) {
- $sha1 = $row->fa_sha1;
- } else {
- // old row, populate from key
- $sha1 = LocalRepo::getHashFromKey( $key );
- }
- // Check if the file is used anywhere...
- $inuse = $dbw->selectField(
- 'oldimage',
- '1',
- array(
- 'oi_sha1' => $sha1,
- 'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE
- ),
- __METHOD__,
- array( 'FOR UPDATE' )
- );
- if ( $path && $repo->fileExists( $path ) && !$inuse ) {
- if ( $repo->quickPurge( $path ) ) {
- $count++;
- $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" );
- } else {
- $output->handleOutput( "Unable to remove file $path, skipping\n" );
- }
- } else {
- $output->handleOutput( "Notice - file '$key' not found in group '$group'\n" );
- if ( $force ) {
- $output->handleOutput( "Got --force, deleting DB entry\n" );
- $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" );
- }
- }
- }
- $dbw->commit( __METHOD__ );
- $output->handleOutput( "Done! [$count file(s)]\n" );
- }
-}
*/
require_once __DIR__ . '/Maintenance.php';
-require_once __DIR__ . '/deleteArchivedFiles.inc';
/**
* Maintenance script to delete archived (non-current) files from the database.
$this->addOption( 'force', 'Force deletion of rows from filearchive' );
}
- public function handleOutput( $str ) {
- return $this->output( $str );
- }
-
public function execute() {
if ( !$this->hasOption( 'delete' ) ) {
$this->output( "Use --delete to actually confirm this script\n" );
-
return;
}
- $force = $this->hasOption( 'force' );
- DeleteArchivedFilesImplementation::doDelete( $this, $force );
+
+ # Data should come off the master, wrapped in a transaction
+ $dbw = $this->getDB( DB_MASTER );
+ $dbw->begin( __METHOD__ );
+ $repo = RepoGroup::singleton()->getLocalRepo();
+
+ # Get "active" revisions from the filearchive table
+ $this->output( "Searching for and deleting archived files...\n" );
+ $res = $dbw->select(
+ 'filearchive',
+ array( 'fa_id', 'fa_storage_group', 'fa_storage_key', 'fa_sha1' ),
+ '',
+ __METHOD__
+ );
+
+ $count = 0;
+ foreach ( $res as $row ) {
+ $key = $row->fa_storage_key;
+ if ( !strlen( $key ) ) {
+ $this->output( "Entry with ID {$row->fa_id} has empty key, skipping\n" );
+ continue;
+ }
+
+ $group = $row->fa_storage_group;
+ $id = $row->fa_id;
+ $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
+ if ( isset( $row->fa_sha1 ) ) {
+ $sha1 = $row->fa_sha1;
+ } else {
+ // old row, populate from key
+ $sha1 = LocalRepo::getHashFromKey( $key );
+ }
+
+ // Check if the file is used anywhere...
+ $inuse = $dbw->selectField(
+ 'oldimage',
+ '1',
+ array(
+ 'oi_sha1' => $sha1,
+ $dbw->bitAnd( 'oi_deleted', File::DELETED_FILE ) => File::DELETED_FILE
+ ),
+ __METHOD__,
+ array( 'FOR UPDATE' )
+ );
+
+ $needForce = true;
+ if ( !$repo->fileExists( $path ) ) {
+ $this->output( "Notice - file '$key' not found in group '$group'\n" );
+ } elseif ( $inuse ) {
+ $this->output( "Notice - file '$key' is still in use\n" );
+ } elseif ( !$repo->quickPurge( $path ) ) {
+ $this->output( "Unable to remove file $path, skipping\n" );
+ continue; // don't delete even with --force
+ } else {
+ $needForce = false;
+ }
+
+ if ( $needForce ) {
+ if ( $this->hasOption( 'force' ) ) {
+ $this->output( "Got --force, deleting DB entry\n" );
+ } else {
+ continue;
+ }
+ }
+
+ $count++;
+ $dbw->delete( 'filearchive', array( 'fa_id' => $id ), __METHOD__ );
+ }
+
+ $dbw->commit( __METHOD__ );
+ $this->output( "Done! [$count file(s)]\n" );
}
}
+++ /dev/null
-<?php
-/**
- * Helper methods for the deleteArchivedRevisions.php maintenance script.
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @ingroup Maintenance
- */
-
-/**
- * Helper methods for the deleteArchivedRevisions.php maintenance script.
- *
- * @ingroup Maintenance
- */
-class DeleteArchivedRevisionsImplementation {
-
- /**
- * Perform the delete on archived revisions.
- * @param object $maint An object (typically of class Maintenance)
- * that implements two methods: handleOutput() and
- * purgeRedundantText(). See Maintenance for a description of
- * those methods.
- */
- public static function doDelete( $maint ) {
- $dbw = wfGetDB( DB_MASTER );
-
- $dbw->begin( __METHOD__ );
-
- $tbl_arch = $dbw->tableName( 'archive' );
-
- # Delete as appropriate
- $maint->handleOutput( "Deleting archived revisions... " );
- $dbw->query( "DELETE FROM $tbl_arch" );
-
- $count = $dbw->affectedRows();
- $deletedRows = $count != 0;
-
- $maint->handleOutput( "done. $count revisions deleted.\n" );
-
- # This bit's done
- # Purge redundant text records
- $dbw->commit( __METHOD__ );
- if ( $deletedRows ) {
- $maint->purgeRedundantText( true );
- }
- }
-}
*/
require_once __DIR__ . '/Maintenance.php';
-require_once __DIR__ . '/deleteArchivedRevisions.inc';
/**
* Maintenance script to delete archived (deleted from public) revisions
$this->addOption( 'delete', 'Performs the deletion' );
}
- public function handleOutput( $str ) {
- $this->output( $str );
- }
-
public function execute() {
- $this->output( "Delete archived revisions\n\n" );
- # Data should come off the master, wrapped in a transaction
- if ( $this->hasOption( 'delete' ) ) {
- DeleteArchivedRevisionsImplementation::doDelete( $this );
- } else {
- $dbw = wfGetDB( DB_MASTER );
- $res = $dbw->selectRow( 'archive', 'COUNT(*) as count', array(), __FUNCTION__ );
- $this->output( "Found {$res->count} revisions to delete.\n" );
+ $dbw = $this->getDB( DB_MASTER );
+
+ if ( !$this->hasOption( 'delete' ) ) {
+ $count = $dbw->selectField( 'archive', 'COUNT(*)', '', __METHOD__ );
+ $this->output( "Found $count revisions to delete.\n" );
$this->output( "Please run the script again with the --delete option "
. "to really delete the revisions.\n" );
+ return;
+ }
+
+ $this->output( "Deleting archived revisions... " );
+ $dbw->delete( 'archive', '*', __METHOD__ );
+ $count = $dbw->affectedRows();
+ $this->output( "done. $count revisions deleted.\n" );
+
+ if ( $count ) {
+ $this->purgeRedundantText( true );
}
}
}