mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-30 18:45:07 +00:00
Merge "Clean up and fix updateEchoSchemaForSuppression.php"
This commit is contained in:
commit
2eabf079f8
|
@ -124,4 +124,5 @@ $wgAutoloadClasses += [
|
||||||
'SpecialNotificationsFormatter' => __DIR__ . '/includes/formatters/SpecialNotificationsFormatter.php',
|
'SpecialNotificationsFormatter' => __DIR__ . '/includes/formatters/SpecialNotificationsFormatter.php',
|
||||||
'SpecialNotificationsMarkRead' => __DIR__ . '/includes/special/SpecialNotificationsMarkRead.php',
|
'SpecialNotificationsMarkRead' => __DIR__ . '/includes/special/SpecialNotificationsMarkRead.php',
|
||||||
'SuppressionMaintenanceTest' => __DIR__ . '/tests/phpunit/maintenance/SupressionMaintenanceTest.php',
|
'SuppressionMaintenanceTest' => __DIR__ . '/tests/phpunit/maintenance/SupressionMaintenanceTest.php',
|
||||||
|
'UpdateEchoSchemaForSuppression' => __DIR__ . '/maintenance/updateEchoSchemaForSuppression.php',
|
||||||
];
|
];
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
*/
|
*/
|
||||||
class EchoSuppressionRowUpdateGenerator implements RowUpdateGenerator {
|
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}
|
* {@inheritDoc}
|
||||||
|
@ -28,19 +28,19 @@ class EchoSuppressionRowUpdateGenerator implements RowUpdateGenerator {
|
||||||
*
|
*
|
||||||
* @param $callable callable
|
* @param $callable callable
|
||||||
*/
|
*/
|
||||||
public function setNewTitleFromText( $callable ) {
|
public function setNewTitleFromNsAndText( $callable ) {
|
||||||
$this->newTitleFromText = $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 $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 namespace + text, or null if invalid
|
||||||
* @return Title|null The title located for the text + namespace, or null if invalid
|
|
||||||
*/
|
*/
|
||||||
protected function newTitleFromText( $text, $defaultNamespace = NS_MAIN ) {
|
protected function newTitleFromNsAndText( $namespace, $text ) {
|
||||||
return call_user_func( $this->newTitleFromText, $text, $defaultNamespace );
|
return call_user_func( $this->newTitleFromNsAndText, $namespace, $text );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,7 @@ class EchoSuppressionRowUpdateGenerator implements RowUpdateGenerator {
|
||||||
*/
|
*/
|
||||||
protected function updatePageIdFromTitle( $row ) {
|
protected function updatePageIdFromTitle( $row ) {
|
||||||
$update = array();
|
$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 ) {
|
if ( $title !== null ) {
|
||||||
$pageId = $title->getArticleId();
|
$pageId = $title->getArticleId();
|
||||||
if ( $pageId ) {
|
if ( $pageId ) {
|
||||||
|
@ -86,7 +86,7 @@ class EchoSuppressionRowUpdateGenerator implements RowUpdateGenerator {
|
||||||
$extra = $this->extra( $row, $update );
|
$extra = $this->extra( $row, $update );
|
||||||
|
|
||||||
if ( isset( $extra['link-from-title'], $extra['link-from-namespace'] ) ) {
|
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'] );
|
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
|
// Link from page is always from a content page, if null or no article id it was
|
||||||
// somehow invalid
|
// somehow invalid
|
||||||
|
|
|
@ -14,7 +14,7 @@ require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
|
||||||
*
|
*
|
||||||
* @ingroup Maintenance
|
* @ingroup Maintenance
|
||||||
*/
|
*/
|
||||||
class UpdateEchoSchemaForSuppression extends Maintenance {
|
class UpdateEchoSchemaForSuppression extends LoggedUpdateMaintenance {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string The table to update
|
* @var string The table to update
|
||||||
|
@ -31,7 +31,11 @@ class UpdateEchoSchemaForSuppression extends Maintenance {
|
||||||
$this->setBatchSize( 500 );
|
$this->setBatchSize( 500 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function getUpdateKey() {
|
||||||
|
return __CLASS__;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doDBUpdates() {
|
||||||
global $wgEchoCluster;
|
global $wgEchoCluster;
|
||||||
|
|
||||||
$reader = new BatchRowIterator( MWEchoDbFactory::getDB( DB_SLAVE ), $this->table, $this->idField, $this->mBatchSize );
|
$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_title IS NOT NULL",
|
||||||
"event_page_id" => null,
|
"event_page_id" => null,
|
||||||
) );
|
) );
|
||||||
|
$reader->setFetchColumns( array( 'event_page_namespace', 'event_page_title', 'event_extra', 'event_type' ) );
|
||||||
|
|
||||||
$updater = new BatchRowUpdate(
|
$updater = new BatchRowUpdate(
|
||||||
$reader,
|
$reader,
|
||||||
new BatchRowWriter( MWEchoDbFactory::getDB( DB_MASTER ), $this->table, $wgEchoCluster ),
|
new BatchRowWriter( MWEchoDbFactory::getDB( DB_MASTER ), $this->table, $wgEchoCluster ),
|
||||||
new EchoSuppressionRowUpdateGenerator
|
new EchoSuppressionRowUpdateGenerator
|
||||||
);
|
);
|
||||||
$updater->setOutput( array( $this, '__internalOutput' ) );
|
$updater->setOutput( function ( $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 );
|
$this->output( $text );
|
||||||
|
} );
|
||||||
|
$updater->execute();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,12 +108,12 @@ class SuppressionMaintenanceTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
$titles = array( $providedNamespace => array( $providedText => $title ) );
|
$titles = array( $providedNamespace => array( $providedText => $title ) );
|
||||||
|
|
||||||
$gen->setNewTitleFromText( function ( $text, $defaultNamespace ) use ( $titles ) {
|
$gen->setNewTitleFromNsAndText( function ( $namespace, $text ) use ( $titles ) {
|
||||||
if ( isset( $titles[$defaultNamespace][$text] ) ) {
|
if ( isset( $titles[$namespace][$text] ) ) {
|
||||||
return $titles[$defaultNamespace][$text];
|
return $titles[$namespace][$text];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Title::newFromText( $text, $defaultNamespace );
|
return Title::makeTitleSafe( $namespace, $text );
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue