26 use Wikimedia\Assert\Assert;
44 if ( !$user->
getId() ) {
45 throw new RuntimeException(
"Got anonymous user" );
54 Assert::parameterType( __CLASS__, $update,
'$update' );
55 '@phan-var UserEditCountUpdate $update';
57 foreach ( $update->infoByUser as $userId => $info ) {
58 if ( !isset( $this->infoByUser[$userId] ) ) {
59 $this->infoByUser[$userId] = $info;
61 $this->infoByUser[$userId]->merge( $info );
70 $mwServices = MediaWikiServices::getInstance();
71 $lb = $mwServices->getDBLoadBalancer();
73 $editTracker = $mwServices->getUserEditTracker();
76 (
new AutoCommitUpdate( $dbw, __METHOD__,
function () use ( $lb, $dbw, $fname, $editTracker ) {
77 foreach ( $this->infoByUser as $userId => $info ) {
78 $dbw->newUpdateQueryBuilder()
80 ->
set( [
'user_editcount=user_editcount+' . (
int)$info->getIncrement() ] )
81 ->where( [
'user_id' => $userId,
'user_editcount IS NOT NULL' ] )
82 ->caller( $fname )->execute();
84 if ( $dbw->affectedRows() == 0 ) {
88 $dbr = $lb->getConnectionRef( DB_REPLICA );
91 $dbr->flushSnapshot( $fname );
92 $lb->waitForPrimaryPos( $dbr );
93 $editTracker->initializeUserEditCount( $info->getUser() );
97 $editTracker->clearUserEditCache( $info->getUser() );
101 $hookRunner =
new HookRunner( $mwServices->getHookContainer() );
102 $hookRunner->onUserEditCountUpdate( array_values( $this->infoByUser ) );
if(!defined('MW_SETUP_CALLBACK'))
Deferrable Update for closure/callback updates that should use auto-commit mode.
Helper class for UserEditCountUpdate.
Handles increment the edit count for a given set of users.
__construct(UserIdentity $user, $increment)
doUpdate()
Commits the provided user edit count increments to the database.
merge(MergeableUpdate $update)
Merge this enqueued update with a new MergeableUpdate of the same qualified class name.
Interface that deferrable updates should implement.
Interface that deferrable updates can implement to signal that updates can be combined.