2016-06-02 14:44:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
|
|
|
$IP = __DIR__ . '/../../..';
|
|
|
|
}
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
2016-06-02 14:44:14 +00:00
|
|
|
|
|
|
|
class BackfillReadBundles extends Maintenance {
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->mDescription = "Backfill echo_notification.notification_read_timestamp for bundles";
|
|
|
|
|
|
|
|
$this->setBatchSize( 300 );
|
2016-12-01 21:34:43 +00:00
|
|
|
|
|
|
|
$this->requireExtension( 'Echo' );
|
2016-06-02 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
2016-06-07 13:22:43 +00:00
|
|
|
$dbFactory = MWEchoDbFactory::newFromDefault();
|
|
|
|
$dbw = $dbFactory->getEchoDb( DB_MASTER );
|
|
|
|
$dbr = $dbFactory->getEchoDb( DB_SLAVE );
|
2016-06-02 14:44:14 +00:00
|
|
|
$iterator = new BatchRowIterator(
|
|
|
|
$dbr,
|
|
|
|
'echo_notification',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'notification_user', 'notification_event' ],
|
2016-06-02 14:44:14 +00:00
|
|
|
$this->mBatchSize
|
|
|
|
);
|
2016-12-05 18:51:07 +00:00
|
|
|
$iterator->setFetchColumns( [ 'notification_bundle_display_hash', 'notification_read_timestamp' ] );
|
2016-06-07 13:22:43 +00:00
|
|
|
|
|
|
|
$unreadNonBase = $dbr->selectSQLText(
|
|
|
|
'echo_notification',
|
|
|
|
'notification_bundle_display_hash',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2016-06-07 13:22:43 +00:00
|
|
|
'notification_bundle_base' => 0,
|
|
|
|
'notification_read_timestamp IS NULL',
|
|
|
|
"notification_bundle_display_hash <> ''",
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2016-06-07 13:22:43 +00:00
|
|
|
);
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$iterator->addConditions( [
|
2016-06-02 14:44:14 +00:00
|
|
|
'notification_bundle_base' => 1,
|
|
|
|
'notification_read_timestamp IS NOT NULL',
|
2016-06-07 13:22:43 +00:00
|
|
|
"notification_bundle_display_hash IN ( $unreadNonBase )",
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
2016-06-02 14:44:14 +00:00
|
|
|
|
|
|
|
$processed = 0;
|
|
|
|
foreach ( $iterator as $batch ) {
|
|
|
|
foreach ( $batch as $row ) {
|
2016-06-07 13:22:43 +00:00
|
|
|
$userId = $row->notification_user;
|
2016-06-02 14:44:14 +00:00
|
|
|
$displayHash = $row->notification_bundle_display_hash;
|
|
|
|
$readTimestamp = $row->notification_read_timestamp;
|
|
|
|
|
|
|
|
$result = $dbw->update(
|
|
|
|
'echo_notification',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'notification_read_timestamp' => $readTimestamp ],
|
|
|
|
[
|
2016-06-07 13:22:43 +00:00
|
|
|
'notification_user' => $userId,
|
2016-06-02 14:44:14 +00:00
|
|
|
'notification_bundle_display_hash' => $displayHash,
|
2016-06-07 13:22:43 +00:00
|
|
|
'notification_bundle_base' => 0,
|
|
|
|
'notification_read_timestamp IS NULL',
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2016-06-02 14:44:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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" );
|
2016-06-07 13:22:43 +00:00
|
|
|
$dbFactory->waitForSlaves();
|
2016-06-02 14:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$maintClass = "BackfillReadBundles";
|
2017-06-20 02:41:30 +00:00
|
|
|
require_once DO_MAINTENANCE;
|