PleaseStand has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/211502

Change subject: [WIP] Combine deleteArchived{Files,Revisions}.inc into the .php 
scripts
......................................................................

[WIP] Combine deleteArchived{Files,Revisions}.inc into the .php scripts

Some of deleteArchivedFiles.php and deleteArchivedRevisions.php were
split off to deleteArchivedFiles.inc and deleteArchivedRevisions.inc
respectively in r62948 (04b2413aacfd) for use in tests.

The tests no longer use those methods, so I moved them back and inlined
them into execute(). I also did some minor cleanup -- changing direct
calls to tableName() and query() to use query builder functions and
clarifying/fixing some of the logic that was in deleteArchivedFiles.inc.

Change-Id: Ica49dcac18a9c702cffe02e562c6dff48d2d2784
---
M autoload.php
D maintenance/deleteArchivedFiles.inc
M maintenance/deleteArchivedFiles.php
D maintenance/deleteArchivedRevisions.inc
M maintenance/deleteArchivedRevisions.php
5 files changed, 86 insertions(+), 168 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/02/211502/1

diff --git a/autoload.php b/autoload.php
index c81c4bb..274c87e 100644
--- a/autoload.php
+++ b/autoload.php
@@ -311,9 +311,7 @@
        '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',
diff --git a/maintenance/deleteArchivedFiles.inc 
b/maintenance/deleteArchivedFiles.inc
deleted file mode 100644
index 0c0b34a..0000000
--- a/maintenance/deleteArchivedFiles.inc
+++ /dev/null
@@ -1,84 +0,0 @@
-<?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" );
-       }
-}
diff --git a/maintenance/deleteArchivedFiles.php 
b/maintenance/deleteArchivedFiles.php
index 286b1f2..bd8ca10 100644
--- a/maintenance/deleteArchivedFiles.php
+++ b/maintenance/deleteArchivedFiles.php
@@ -25,7 +25,6 @@
  */
 
 require_once __DIR__ . '/Maintenance.php';
-require_once __DIR__ . '/deleteArchivedFiles.inc';
 
 /**
  * Maintenance script to delete archived (non-current) files from the database.
@@ -40,18 +39,82 @@
                $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" );
        }
 }
 
diff --git a/maintenance/deleteArchivedRevisions.inc 
b/maintenance/deleteArchivedRevisions.inc
deleted file mode 100644
index ed620ee..0000000
--- a/maintenance/deleteArchivedRevisions.inc
+++ /dev/null
@@ -1,61 +0,0 @@
-<?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 );
-               }
-       }
-}
diff --git a/maintenance/deleteArchivedRevisions.php 
b/maintenance/deleteArchivedRevisions.php
index 30883ba..9924eb0 100644
--- a/maintenance/deleteArchivedRevisions.php
+++ b/maintenance/deleteArchivedRevisions.php
@@ -25,7 +25,6 @@
  */
 
 require_once __DIR__ . '/Maintenance.php';
-require_once __DIR__ . '/deleteArchivedRevisions.inc';
 
 /**
  * Maintenance script to delete archived (deleted from public) revisions
@@ -41,21 +40,24 @@
                $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 );
                }
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/211502
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica49dcac18a9c702cffe02e562c6dff48d2d2784
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: PleaseStand <pleasest...@live.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to