ItSpiderman has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/347387 )
Change subject: Add script for fixing oldimage table ...................................................................... Add script for fixing oldimage table In some cases oldimage table contains value without NS prefix which causes files not to be moved when moving withing NS (renaming). Field oi_name always contain correct name (current name) with NS Field oi_archive_name in this case contains TS!Name_without prefix This script identifies such cases and adds NS to oi_archive_name (taken from oi_name in the same row). Needs cherry-picking to at least REL1_27 Change-Id: Ie88a716c95e6887a8450c4d439116f8b61a6ba69 ERM: #4275 --- A maintenance/fixOldImage.php 1 file changed, 78 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NSFileRepo refs/changes/87/347387/1 diff --git a/maintenance/fixOldImage.php b/maintenance/fixOldImage.php new file mode 100644 index 0000000..192080f --- /dev/null +++ b/maintenance/fixOldImage.php @@ -0,0 +1,78 @@ +<?php + +require_once( dirname(dirname(dirname(dirname(__DIR__)))) . '/maintenance/Maintenance.php' ); + +class FixOldImage extends Maintenance { + protected $mDBName; + + function __construct() { + parent::__construct(); + $this->addOption( 'db', 'DB to run script on', true, true ); + } + + function execute() { + $this->mDBName = $this->getOption( 'db' ); + + $dbw = wfGetDB( DB_MASTER ); + $dbw->selectDB( $this->mDBName ); + print( "USING DB: " . $dbw->getDBName() . "\n" ); + $images = $dbw->select( 'oldimage', + array( 'oi_name', 'oi_archive_name' ), + array(), + __METHOD__ + ); + + $count = 0; + $log = ''; + foreach( $images as $image ) { + $nameBits = explode( ':', $image->oi_name ); + $nameNS = ''; + $nameName = $image->oi_name; + if( count( $nameBits ) == 2 ) { + $nameNS = $nameBits[0]; + $nameName = $nameBits[1]; + } + + $archiveName = explode( '!', $image->oi_archive_name )[1]; + $archiveBits = explode( ':', $archiveName ); + $archiveNS = ''; + if( count( $archiveBits ) == 2 ) { + $archiveNS = $archiveBits[0]; + $archiveName = $archiveBits[1]; + } + + if( $nameNS === $archiveNS && $nameName == $archiveName ) { + continue; + } + + if( $nameNS != $archiveNS && $nameName != $archiveName ) { + continue; + } + $title = Title::newFromText( $image->oi_name, NS_FILE ); + $repo = RepoGroup::singleton()->getRepo( 'local' ); + $file = OldLocalFile::newFromArchiveName( $title, $repo, $image->oi_archive_name ); + if( !$file->exists() ) { + continue; + } + + print( "NAME: ns-" . $nameNS . ' name-' . $nameName . ' ARCHIVE: ns-' . $archiveNS . ' name-' . $archiveName . "\n" ); + $log .= $nameNS . ";" . $nameName . ";" . $archiveNS . ";" . $archiveName . "\n"; + $dbw->update( + 'oldimage', + array( + 'oi_archive_name = ' . $dbw->strreplace( 'oi_archive_name', + $dbw->addQuotes( $archiveName ), $dbw->addQuotes( $image->oi_name ) ) + ), + array( 'oi_name' => $image->oi_name ), + __METHOD__ + ); + + $count++; + } + #file_put_contents( '/tmp/fixOldImagesLog.log', $log ); + print( "Total " . $count . " images altered\n" ); + } +} + +$maintClass = 'FixOldImage'; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- To view, visit https://gerrit.wikimedia.org/r/347387 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie88a716c95e6887a8450c4d439116f8b61a6ba69 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/NSFileRepo Gerrit-Branch: master Gerrit-Owner: ItSpiderman <d.savulje...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits