2015-12-15 15:41:21 +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";
|
2015-12-15 15:41:21 +00:00
|
|
|
|
|
|
|
class BackfillUnreadWikis extends Maintenance {
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
2019-03-27 05:07:48 +00:00
|
|
|
$this->addDescription( "Backfill echo_unread_wikis table" );
|
2016-06-17 14:45:28 +00:00
|
|
|
$this->addOption( 'rebuild', 'Only recompute already-existing rows' );
|
2015-12-15 15:41:21 +00:00
|
|
|
$this->setBatchSize( 300 );
|
2016-12-01 21:34:43 +00:00
|
|
|
$this->requireExtension( 'Echo' );
|
2015-12-15 15:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
2016-06-17 14:45:28 +00:00
|
|
|
$dbFactory = MWEchoDbFactory::newFromDefault();
|
|
|
|
$lookup = CentralIdLookup::factory();
|
2015-12-15 15:41:21 +00:00
|
|
|
|
2016-06-17 14:45:28 +00:00
|
|
|
$rebuild = $this->hasOption( 'rebuild' );
|
|
|
|
if ( $rebuild ) {
|
2020-06-27 10:05:03 +00:00
|
|
|
$iterator = new BatchRowIterator(
|
|
|
|
$dbFactory->getSharedDb( DB_REPLICA ),
|
|
|
|
'echo_unread_wikis',
|
|
|
|
'euw_user',
|
|
|
|
$this->mBatchSize
|
|
|
|
);
|
2016-12-05 18:51:07 +00:00
|
|
|
$iterator->addConditions( [ 'euw_wiki' => wfWikiID() ] );
|
2016-06-17 14:45:28 +00:00
|
|
|
} else {
|
2017-10-12 19:45:53 +00:00
|
|
|
$userQuery = User::getQueryInfo();
|
|
|
|
$iterator = new BatchRowIterator(
|
|
|
|
wfGetDB( DB_REPLICA ), $userQuery['tables'], 'user_id', $this->mBatchSize
|
|
|
|
);
|
|
|
|
$iterator->setFetchColumns( $userQuery['fields'] );
|
|
|
|
$iterator->addJoinConditions( $userQuery['joins'] );
|
2016-06-17 14:45:28 +00:00
|
|
|
}
|
2015-12-15 15:41:21 +00:00
|
|
|
|
2016-01-19 03:14:34 +00:00
|
|
|
$processed = 0;
|
2015-12-15 15:41:21 +00:00
|
|
|
foreach ( $iterator as $batch ) {
|
|
|
|
foreach ( $batch as $row ) {
|
2016-06-17 14:45:28 +00:00
|
|
|
if ( $rebuild ) {
|
|
|
|
$user = $lookup->localUserFromCentralId( $row->euw_user, CentralIdLookup::AUDIENCE_RAW );
|
|
|
|
} else {
|
|
|
|
$user = User::newFromRow( $row );
|
|
|
|
}
|
|
|
|
if ( !$user ) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-15 15:41:21 +00:00
|
|
|
|
|
|
|
$notifUser = MWEchoNotifUser::newFromUser( $user );
|
2016-06-17 13:43:22 +00:00
|
|
|
$uw = EchoUnreadWikis::newFromUser( $user );
|
|
|
|
if ( $uw ) {
|
2018-05-31 23:11:57 +00:00
|
|
|
$alertCount = $notifUser->getNotificationCount( EchoAttributeManager::ALERT, false );
|
|
|
|
$alertUnread = $notifUser->getLastUnreadNotificationTime( EchoAttributeManager::ALERT, false );
|
2016-06-17 13:43:22 +00:00
|
|
|
|
2018-05-31 23:11:57 +00:00
|
|
|
$msgCount = $notifUser->getNotificationCount( EchoAttributeManager::MESSAGE, false );
|
|
|
|
$msgUnread = $notifUser->getLastUnreadNotificationTime( EchoAttributeManager::MESSAGE, false );
|
2016-06-17 13:43:22 +00:00
|
|
|
|
2020-06-27 10:05:03 +00:00
|
|
|
if ( ( $alertCount !== 0 && $alertUnread === false ) ||
|
|
|
|
( $msgCount !== 0 && $msgUnread === false )
|
|
|
|
) {
|
2016-07-18 23:46:53 +00:00
|
|
|
// If there are alerts, there should be an alert timestamp (same for messages).
|
|
|
|
|
|
|
|
// Otherwise, there is a race condition between the two values, indicating there's already
|
|
|
|
// just been an updateCount call, so we can skip this user.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-17 13:43:22 +00:00
|
|
|
$uw->updateCount( wfWikiID(), $alertCount, $alertUnread, $msgCount, $msgUnread );
|
|
|
|
}
|
2015-12-15 15:41:21 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 03:14:34 +00:00
|
|
|
$processed += count( $batch );
|
|
|
|
$this->output( "Updated $processed users.\n" );
|
2020-06-09 01:09:44 +00:00
|
|
|
$dbFactory->waitForReplicas();
|
2015-12-15 15:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 14:14:15 +00:00
|
|
|
$maintClass = BackfillUnreadWikis::class;
|
2018-03-17 20:55:20 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|