2015-12-15 15:41:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
|
|
|
$IP = __DIR__ . '/../../..';
|
|
|
|
}
|
|
|
|
require_once ( "$IP/maintenance/Maintenance.php" );
|
|
|
|
|
|
|
|
class BackfillUnreadWikis extends Maintenance {
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
2016-06-17 13:43:22 +00:00
|
|
|
$this->mDescription = "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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ) {
|
|
|
|
$iterator = new BatchRowIterator( $dbFactory->getSharedDb( DB_SLAVE ), 'echo_unread_wikis', 'euw_user', $this->mBatchSize );
|
2016-06-29 13:11:21 +00:00
|
|
|
$iterator->addConditions( array( 'euw_wiki' => wfWikiID() ) );
|
2016-06-17 14:45:28 +00:00
|
|
|
} else {
|
|
|
|
$iterator = new BatchRowIterator( wfGetDB( DB_SLAVE ), 'user', 'user_id', $this->mBatchSize );
|
|
|
|
$iterator->setFetchColumns( User::selectFields() );
|
|
|
|
}
|
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 ) {
|
2016-06-17 14:45:28 +00:00
|
|
|
$alertCount = $notifUser->getNotificationCount( true, DB_SLAVE, EchoAttributeManager::ALERT, false );
|
|
|
|
$alertUnread = $notifUser->getLastUnreadNotificationTime( true, DB_SLAVE, EchoAttributeManager::ALERT, false );
|
2016-06-17 13:43:22 +00:00
|
|
|
|
2016-06-17 14:45:28 +00:00
|
|
|
$msgCount = $notifUser->getNotificationCount( true, DB_SLAVE, EchoAttributeManager::MESSAGE, false );
|
|
|
|
$msgUnread = $notifUser->getLastUnreadNotificationTime( true, DB_SLAVE, EchoAttributeManager::MESSAGE, false );
|
2016-06-17 13:43:22 +00:00
|
|
|
|
2016-07-18 23:46:53 +00:00
|
|
|
if ( ( $alertCount !== 0 && $alertUnread === false ) || ( $msgCount !== 0 && $msgUnread === false ) ) {
|
|
|
|
// 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" );
|
2016-06-17 14:45:28 +00:00
|
|
|
$dbFactory->waitForSlaves();
|
2015-12-15 15:41:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$maintClass = "BackfillUnreadWikis";
|
|
|
|
require_once ( DO_MAINTENANCE );
|