aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/populateRevisionSha1.php
diff options
context:
space:
mode:
authorDreamy Jazz <dreamyjazzwikipedia@gmail.com>2024-08-26 09:37:37 +0100
committerDreamy Jazz <dreamyjazzwikipedia@gmail.com>2024-08-26 09:10:40 +0000
commit5f4d19f68053264f12c157d7947068f0233b23c9 (patch)
treea8aa80c91519a6b93a5d5c62787f0cbc01cfe31e /maintenance/populateRevisionSha1.php
parentb371b0623e213e2daa65ab10fd9d97de07b317e5 (diff)
downloadmediawikicore-5f4d19f68053264f12c157d7947068f0233b23c9.tar.gz
mediawikicore-5f4d19f68053264f12c157d7947068f0233b23c9.zip
Remove populateRevisionSha1.php
Why: * The populateRevisionSha1.php maintenance script last had it's update log key changed in MW 1.19 in c326cab5, and it has been added to update.php since that version. * This means that, since the script has been run via update.php since before MW 1.35, it should be possible to remove the script as all wikis will have run this script and therefore it will be skipped for all wikis (as it's in the update log). * Removing now unused maintenance scripts is important to reduce the amount of untested code in the maintenance directory and also prevents the need to update the code for migrations (e.g. using the query builders). What: * Remove the populateRevisionSha1.php maintenance script. Bug: T373238 Change-Id: Id3d46d6e0d4b8bd4aaf6d3ed01d7b759813c981a
Diffstat (limited to 'maintenance/populateRevisionSha1.php')
-rw-r--r--maintenance/populateRevisionSha1.php163
1 files changed, 0 insertions, 163 deletions
diff --git a/maintenance/populateRevisionSha1.php b/maintenance/populateRevisionSha1.php
deleted file mode 100644
index 45166df1490a..000000000000
--- a/maintenance/populateRevisionSha1.php
+++ /dev/null
@@ -1,163 +0,0 @@
-<?php
-/**
- * Fills the rev_sha1 and ar_sha1 columns of revision
- * and archive tables for revisions created before MW 1.19.
- *
- * 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
- */
-
-require_once __DIR__ . '/Maintenance.php';
-
-/**
- * Maintenance script that fills the rev_sha1 and ar_sha1 columns of revision
- * and archive tables for revisions created before MW 1.19.
- *
- * @ingroup Maintenance
- */
-class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
- public function __construct() {
- parent::__construct();
- $this->addDescription( 'Populates the rev_sha1 and ar_sha1 fields' );
- $this->setBatchSize( 200 );
- }
-
- protected function getUpdateKey() {
- return 'populate rev_sha1';
- }
-
- protected function doDBUpdates() {
- $db = $this->getDB( DB_PRIMARY );
-
- if ( !$db->tableExists( 'revision', __METHOD__ ) ) {
- $this->fatalError( "revision table does not exist" );
- } elseif ( !$db->tableExists( 'archive', __METHOD__ ) ) {
- $this->fatalError( "archive table does not exist" );
- } elseif ( !$db->fieldExists( 'revision', 'rev_sha1', __METHOD__ ) ) {
- $this->output( "rev_sha1 column does not exist\n\n", true );
- return false;
- }
-
- $revStore = $this->getServiceContainer()->getRevisionStore();
-
- $this->output( "Populating rev_sha1 column\n" );
- $rc = $this->doSha1Updates( $revStore, 'revision', 'rev_id',
- $revStore->newSelectQueryBuilder( $this->getPrimaryDB() )->joinComment(),
- 'rev'
- );
-
- $this->output( "Populating ar_sha1 column\n" );
- $ac = $this->doSha1Updates( $revStore, 'archive', 'ar_rev_id',
- $revStore->newArchiveSelectQueryBuilder( $this->getPrimaryDB() )->joinComment(),
- 'ar'
- );
-
- $this->output( "rev_sha1 and ar_sha1 population complete "
- . "[$rc revision rows, $ac archive rows].\n" );
-
- return true;
- }
-
- /**
- * @param MediaWiki\Revision\RevisionStore $revStore
- * @param string $table
- * @param string $idCol
- * @param \Wikimedia\Rdbms\SelectQueryBuilder $queryBuilder should use a primary db
- * @param string $prefix
- * @return int Rows changed
- */
- protected function doSha1Updates( $revStore, $table, $idCol, $queryBuilder, $prefix ) {
- $db = $this->getPrimaryDB();
- $batchSize = $this->getBatchSize();
- $start = $db->newSelectQueryBuilder()
- ->select( "MIN($idCol)" )
- ->from( $table )
- ->caller( __METHOD__ )->fetchField();
- $end = $db->newSelectQueryBuilder()
- ->select( "MAX($idCol)" )
- ->from( $table )
- ->caller( __METHOD__ )->fetchField();
- if ( !$start || !$end ) {
- $this->output( "...$table table seems to be empty.\n" );
-
- return 0;
- }
-
- $count = 0;
- # Do remaining chunk
- $end += $batchSize - 1;
- $blockStart = $start;
- $blockEnd = $start + $batchSize - 1;
- while ( $blockEnd <= $end ) {
- $this->output( "...doing $idCol from $blockStart to $blockEnd\n" );
-
- $res = $queryBuilder->where( [
- $db->expr( $idCol, '>=', (int)$blockStart )->and( $idCol, '<=', (int)$blockEnd ),
- $db->expr( $idCol, '!=', null ),
- "{$prefix}_sha1" => '',
- ] )->caller( __METHOD__ )->fetchResultSet();
-
- $this->beginTransaction( $db, __METHOD__ );
- foreach ( $res as $row ) {
- if ( $this->upgradeRow( $revStore, $row, $table, $idCol, $prefix ) ) {
- $count++;
- }
- }
- $this->commitTransaction( $db, __METHOD__ );
-
- $blockStart += $batchSize;
- $blockEnd += $batchSize;
- }
-
- return $count;
- }
-
- /**
- * @param MediaWiki\Revision\RevisionStore $revStore
- * @param stdClass $row
- * @param string $table
- * @param string $idCol
- * @param string $prefix
- * @return bool
- */
- protected function upgradeRow( $revStore, $row, $table, $idCol, $prefix ) {
- $db = $this->getPrimaryDB();
-
- // Create a revision and use it to get the sha1 from the content table, if possible.
- try {
- $rev = ( $table === 'archive' )
- ? $revStore->newRevisionFromArchiveRow( $row )
- : $revStore->newRevisionFromRow( $row );
- $sha1 = $rev->getSha1();
- } catch ( Exception $e ) {
- $this->output( "Data of revision with {$idCol}={$row->$idCol} unavailable!\n" );
- return false; // T24624? T22757?
- }
-
- $db->newUpdateQueryBuilder()
- ->update( $table )
- ->set( [ "{$prefix}_sha1" => $sha1 ] )
- ->where( [ $idCol => $row->$idCol ] )
- ->caller( __METHOD__ )->execute();
-
- return true;
- }
-}
-
-$maintClass = PopulateRevisionSha1::class;
-require_once RUN_MAINTENANCE_IF_MAIN;