Allow setting the unread counts to 0 in the echo_unread_wikis

Bug: T127331
Change-Id: I90342c9d64277faa77a905b227148d3102d049cb
This commit is contained in:
Stephane Bisson 2016-02-18 15:30:42 -05:00
parent 4b68e4842d
commit 7dc87b9f7a

View file

@ -101,33 +101,39 @@ class EchoUnreadWikis {
return; return;
} }
if ( $alertCount || $msgCount ) { $values = array(
$values = array( 'euw_alerts' => $alertCount,
'euw_alerts' => $alertCount, 'euw_alerts_ts' => $alertCount
'euw_alerts_ts' => $alertCount ? $alertTime->getTimestamp( TS_MW )
? $alertTime->getTimestamp( TS_MW ) : static::DEFAULT_TS,
: static::DEFAULT_TS, 'euw_messages' => $msgCount,
'euw_messages' => $msgCount, 'euw_messages_ts' => $msgCount
'euw_messages_ts' => $msgCount ? $msgTime->getTimestamp( TS_MW )
? $msgTime->getTimestamp( TS_MW ) : static::DEFAULT_TS,
: static::DEFAULT_TS, );
$conditions = array(
'euw_user' => $this->id,
'euw_wiki' => $wiki,
);
if ( $alertCount === 0 && $msgCount === 0 ) {
// when they're both 0, update the existing row but don't create a new one
$dbw->update(
'echo_unread_wikis',
$values,
$conditions,
__METHOD__
); );
} else {
// when there is unread alert(s) and/or message(s), upsert the row
$dbw->upsert( $dbw->upsert(
'echo_unread_wikis', 'echo_unread_wikis',
array( $conditions + $values,
'euw_user' => $this->id,
'euw_wiki' => $wiki,
) + $values,
array( 'euw_user', 'euw_wiki' ), array( 'euw_user', 'euw_wiki' ),
$values, $values,
__METHOD__ __METHOD__
); );
} else {
// Even if there are no unread notifications, don't delete the row!
// That (empty) row helps us tell the difference between "has had
// notifications but all have been seen" (0 count, non-0 timestamp)
// and "has never had a notifications before" (row with 0 count and
// 000 timestamp or no row at all)
} }
} }
} }