mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-27 17:20:40 +00:00
Clean up and fix updateEchoSchemaForSuppression.php
This script was supposed to be run in production in 2013, but that never happened. It was also never added to update.php. * Use makeTitleSafe instead of newFromText, for correctness * Fetch the columns that the update generator needs * Replace wrapper for private method with closure * Make the maintenance script logged Bug: T136427 Bug: T50059 Change-Id: I6c2972120189f035483b5ca49610c008c4ba2c88
This commit is contained in:
parent
848c814c09
commit
99377e5525
|
@ -122,4 +122,5 @@ $wgAutoloadClasses += [
|
|||
'SpecialNotificationsFormatter' => __DIR__ . '/includes/formatters/SpecialNotificationsFormatter.php',
|
||||
'SpecialNotificationsMarkRead' => __DIR__ . '/includes/special/SpecialNotificationsMarkRead.php',
|
||||
'SuppressionMaintenanceTest' => __DIR__ . '/tests/phpunit/maintenance/SupressionMaintenanceTest.php',
|
||||
'UpdateEchoSchemaForSuppression' => __DIR__ . '/maintenance/updateEchoSchemaForSuppression.php',
|
||||
];
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
*/
|
||||
class EchoSuppressionRowUpdateGenerator implements RowUpdateGenerator {
|
||||
/**
|
||||
* @var callable Hack to allow replacing Title::newFromText in tests
|
||||
* @var callable Hack to allow replacing Title::makeTitleSafe in tests
|
||||
*/
|
||||
protected $newTitleFromText = array( 'Title', 'newFromText' );
|
||||
protected $newTitleFromNsAndText = array( 'Title', 'makeTitleSafe' );
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -28,19 +28,19 @@ class EchoSuppressionRowUpdateGenerator implements RowUpdateGenerator {
|
|||
*
|
||||
* @param $callable callable
|
||||
*/
|
||||
public function setNewTitleFromText( $callable ) {
|
||||
$this->newTitleFromText = $callable;
|
||||
public function setNewTitleFromNsAndText( $callable ) {
|
||||
$this->newTitleFromNsAndText = $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hackish method of mocking Title::newFromText for tests
|
||||
* Hackish method of mocking Title::makeTitleSafe for tests
|
||||
*
|
||||
* @param $namespace integer The namespace of the page to look up
|
||||
* @param $text string The page name to look up
|
||||
* @param $defaultNamespace integer The default namespace of the page to look up
|
||||
* @return Title|null The title located for the text + namespace, or null if invalid
|
||||
* @return Title|null The title located for the namespace + text, or null if invalid
|
||||
*/
|
||||
protected function newTitleFromText( $text, $defaultNamespace = NS_MAIN ) {
|
||||
return call_user_func( $this->newTitleFromText, $text, $defaultNamespace );
|
||||
protected function newTitleFromNsAndText( $namespace, $text ) {
|
||||
return call_user_func( $this->newTitleFromNsAndText, $namespace, $text );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +53,7 @@ class EchoSuppressionRowUpdateGenerator implements RowUpdateGenerator {
|
|||
*/
|
||||
protected function updatePageIdFromTitle( $row ) {
|
||||
$update = array();
|
||||
$title = $this->newTitleFromText( $row->event_page_title, $row->event_page_namespace );
|
||||
$title = $this->newTitleFromNsAndText( $row->event_page_namespace, $row->event_page_title );
|
||||
if ( $title !== null ) {
|
||||
$pageId = $title->getArticleId();
|
||||
if ( $pageId ) {
|
||||
|
@ -86,7 +86,7 @@ class EchoSuppressionRowUpdateGenerator implements RowUpdateGenerator {
|
|||
$extra = $this->extra( $row, $update );
|
||||
|
||||
if ( isset( $extra['link-from-title'], $extra['link-from-namespace'] ) ) {
|
||||
$title = $this->newTitleFromText( $extra['link-from-title'], $extra['link-from-namespace'] );
|
||||
$title = $this->newTitleFromNsAndText( $extra['link-from-namespace'], $extra['link-from-title'] );
|
||||
unset( $extra['link-from-title'], $extra['link-from-namespace'] );
|
||||
// Link from page is always from a content page, if null or no article id it was
|
||||
// somehow invalid
|
||||
|
|
|
@ -14,7 +14,7 @@ require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
|
|||
*
|
||||
* @ingroup Maintenance
|
||||
*/
|
||||
class UpdateEchoSchemaForSuppression extends Maintenance {
|
||||
class UpdateEchoSchemaForSuppression extends LoggedUpdateMaintenance {
|
||||
|
||||
/**
|
||||
* @var string The table to update
|
||||
|
@ -31,7 +31,11 @@ class UpdateEchoSchemaForSuppression extends Maintenance {
|
|||
$this->setBatchSize( 500 );
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
public function getUpdateKey() {
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
public function doDBUpdates() {
|
||||
global $wgEchoCluster;
|
||||
|
||||
$reader = new BatchRowIterator( MWEchoDbFactory::getDB( DB_SLAVE ), $this->table, $this->idField, $this->mBatchSize );
|
||||
|
@ -39,22 +43,18 @@ class UpdateEchoSchemaForSuppression extends Maintenance {
|
|||
"event_page_title IS NOT NULL",
|
||||
"event_page_id" => null,
|
||||
) );
|
||||
$reader->setFetchColumns( array( 'event_page_namespace', 'event_page_title', 'event_extra', 'event_type' ) );
|
||||
|
||||
$updater = new BatchRowUpdate(
|
||||
$reader,
|
||||
new BatchRowWriter( MWEchoDbFactory::getDB( DB_MASTER ), $this->table, $wgEchoCluster ),
|
||||
new EchoSuppressionRowUpdateGenerator
|
||||
);
|
||||
$updater->setOutput( array( $this, '__internalOutput' ) );
|
||||
$updater->setOutput( function ( $text ) {
|
||||
$this->output( $text );
|
||||
} );
|
||||
$updater->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use only. parent::output() is a protected method, only way to access it from
|
||||
* a callback in php5.3 is to make a public function. In 5.4 can replace with a Closure.
|
||||
*/
|
||||
public function __internalOutput( $text ) {
|
||||
$this->output( $text );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,12 +108,12 @@ class SuppressionMaintenanceTest extends MediaWikiTestCase {
|
|||
|
||||
$titles = array( $providedNamespace => array( $providedText => $title ) );
|
||||
|
||||
$gen->setNewTitleFromText( function ( $text, $defaultNamespace ) use ( $titles ) {
|
||||
if ( isset( $titles[$defaultNamespace][$text] ) ) {
|
||||
return $titles[$defaultNamespace][$text];
|
||||
$gen->setNewTitleFromNsAndText( function ( $namespace, $text ) use ( $titles ) {
|
||||
if ( isset( $titles[$namespace][$text] ) ) {
|
||||
return $titles[$namespace][$text];
|
||||
}
|
||||
|
||||
return Title::newFromText( $text, $defaultNamespace );
|
||||
return Title::makeTitleSafe( $namespace, $text );
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue