userIds = $params['userIds']; $this->dbFactory = MWEchoDbFactory::newFromDefault(); } /** * Run the job of finding & deleting older notifications */ function run() { global $wgEchoMaxUpdateCount; $updateCount = 0; $dbw = $this->dbFactory->getEchoDb( DB_MASTER ); $notifMapper = new EchoNotificationMapper(); $targetMapper = new EchoTargetPageMapper(); foreach ( $this->userIds as $userId ) { $user = User::newFromId( $userId ); $notif = $notifMapper->fetchByUserOffset( $user, $wgEchoMaxUpdateCount ); if ( $notif ) { $dbw->startAtomic( __METHOD__ ); $res = $notifMapper->deleteByUserEventOffset( $user, $notif->getEvent()->getId() ); if ( $res ) { $res = $targetMapper->deleteByUserEventOffset( $user, $notif->getEvent()->getId() ); } $dbw->endAtomic( __METHOD__ ); if ( $res ) { $updateCount++; $notifUser = MWEchoNotifUser::newFromUser( $user ); $notifUser->resetNotificationCount( DB_MASTER ); } // Wait for slave if we are doing a lot of updates if ( $updateCount > 10 ) { $this->dbFactory->waitForSlaves(); $updateCount = 0; } } } return true; } }