mediawiki-extensions-Echo/maintenance/backfillReadBundles.php
Aaron Schulz deb5057dc6 Avoid use of IDatabase::update return value
Change-Id: I7f3a0f169cfac9190b796b45aabb1b9cb7670a9d
2018-10-26 12:41:49 -07:00

77 lines
2 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_REPLICA );
$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;
$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',
]
);
$processed += $dbw->affectedRows();
}
$this->output( "Updated $processed notifications.\n" );
$dbFactory->waitForSlaves();
}
}
}
$maintClass = "BackfillReadBundles";
require_once RUN_MAINTENANCE_IF_MAIN;