mediawiki-extensions-Echo/maintenance/backfillReadBundles.php
Kunal Mehta aaf061c725 build: Updating mediawiki/mediawiki-codesniffer to 0.9.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.FunctionComment.ExtraParamComment
* MediaWiki.Commenting.FunctionComment.MissingParamComment
* MediaWiki.Commenting.FunctionComment.MissingParamName
* MediaWiki.Commenting.FunctionComment.MissingParamTag
* MediaWiki.Commenting.FunctionComment.MissingReturn
* MediaWiki.Commenting.FunctionComment.ParamNameNoMatch
* MediaWiki.Commenting.FunctionComment.WrongStyle
* MediaWiki.FunctionComment.Missing.Protected
* MediaWiki.FunctionComment.Missing.Public
* MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
* MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment

Change-Id: I8401abf121a7413fa191d7bc535e0ddd6cf8c3f7
2017-06-22 14:13:28 +00:00

81 lines
2.1 KiB
PHP

<?php
$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";
class BackfillReadBundles extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = "Backfill echo_notification.notification_read_timestamp for bundles";
$this->setBatchSize( 300 );
$this->requireExtension( 'Echo' );
}
public function execute() {
$dbFactory = MWEchoDbFactory::newFromDefault();
$dbw = $dbFactory->getEchoDb( DB_MASTER );
$dbr = $dbFactory->getEchoDb( DB_SLAVE );
$iterator = new BatchRowIterator(
$dbr,
'echo_notification',
[ 'notification_user', 'notification_event' ],
$this->mBatchSize
);
$iterator->setFetchColumns( [ 'notification_bundle_display_hash', 'notification_read_timestamp' ] );
$unreadNonBase = $dbr->selectSQLText(
'echo_notification',
'notification_bundle_display_hash',
[
'notification_bundle_base' => 0,
'notification_read_timestamp IS NULL',
"notification_bundle_display_hash <> ''",
]
);
$iterator->addConditions( [
'notification_bundle_base' => 1,
'notification_read_timestamp IS NOT NULL',
"notification_bundle_display_hash IN ( $unreadNonBase )",
] );
$processed = 0;
foreach ( $iterator as $batch ) {
foreach ( $batch as $row ) {
$userId = $row->notification_user;
$displayHash = $row->notification_bundle_display_hash;
$readTimestamp = $row->notification_read_timestamp;
$result = $dbw->update(
'echo_notification',
[ 'notification_read_timestamp' => $readTimestamp ],
[
'notification_user' => $userId,
'notification_bundle_display_hash' => $displayHash,
'notification_bundle_base' => 0,
'notification_read_timestamp IS NULL',
]
);
if ( !$result ) {
$this->output( "Failed to set read_timestamp on notifications with bundle_display_hash: $displayHash\n" );
}
$processed += $dbw->affectedRows();
}
$this->output( "Updated $processed notifications.\n" );
$dbFactory->waitForSlaves();
}
}
}
$maintClass = "BackfillReadBundles";
require_once DO_MAINTENANCE;