Merge "Delete watchlist_expiry rows when clearing watchlist with job"

This commit is contained in:
jenkins-bot 2020-04-28 21:28:24 +00:00 committed by Gerrit Code Review
commit 338eb3d112
2 changed files with 38 additions and 0 deletions

View file

@ -84,6 +84,9 @@ class ClearUserWatchlistJob extends Job implements GenericParameterJob {
}
$dbw->delete( 'watchlist', [ 'wl_id' => $watchlistIds ], __METHOD__ );
if ( MediaWikiServices::getInstance()->getMainConfig()->get( 'WatchlistExpiry' ) ) {
$dbw->delete( 'watchlist_expiry', [ 'we_item' => $watchlistIds ], __METHOD__ );
}
// Commit changes and remove lock before inserting next job.
$lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();

View file

@ -73,4 +73,39 @@ class ClearUserWatchlistJobTest extends MediaWikiTestCase {
$this->assertTrue( $watchedItemStore->isWatched( $user, new TitleValue( 1, 'C' ) ) );
}
public function testRunWithWatchlistExpiry() {
// Set up.
$this->setMwGlobals( 'wgWatchlistExpiry', true );
$user = $this->getUser();
$watchedItemStore = $this->getWatchedItemStore();
// Add two watched items, one with an expiry.
$watchedItemStore->addWatch( $user, new TitleValue( 0, __METHOD__ . 'no expiry' ) );
$watchedItemStore->addWatch( $user, new TitleValue( 0, __METHOD__ . 'has expiry' ), '1 week' );
// Get the IDs of these items.
$itemIds = $this->db->selectFieldValues(
[ 'watchlist' ],
'wl_id',
[ 'wl_user' => $user->getId() ],
__METHOD__
);
// Clear the watchlist by running the job.
$job = new ClearUserWatchlistJob( [
'userId' => $user->getId(),
'maxWatchlistId' => max( $itemIds ),
] );
JobQueueGroup::singleton()->push( $job );
$this->runJobs( 1 );
// Confirm that there are now no expiry records.
$watchedCount = $this->db->selectRowCount(
'watchlist_expiry',
'*',
[ 'we_item' => $itemIds ],
__METHOD__
);
$this->assertSame( 0, $watchedCount );
}
}