Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MessageGroupStatsRebuildJob.php
Go to the documentation of this file.
1<?php
11use MediaWiki\MediaWikiServices;
12
23 public static function newJob( $params ) {
24 $job = new self( Title::newMainPage(), $params );
25 return $job;
26 }
27
38 public static function newRefreshGroupsJob( array $messageGroupIds ) {
39 return new self( Title::newMainPage(), [ 'cleargroups' => $messageGroupIds ] );
40 }
41
46 public function __construct( $title, $params = [] ) {
47 parent::__construct( __CLASS__, $title, $params );
48 }
49
50 public function run() {
51 $lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
52 if ( !$lb->waitForReplication() ) {
53 $this->logWarning( 'Continuing despite replication lag' );
54 }
55
56 $params = $this->params;
57 $flags = 0;
58
59 // Sanity check that this is run via JobQueue. Immediate writes are only safe when they
60 // are run in isolation, e.g. as a separate job in the JobQueue.
61 if ( defined( 'MEDIAWIKI_JOB_RUNNER' ) ) {
63 }
64
65 // This is to make sure the priority value is not read from the process cache.
66 // There is still a possibility that, due to replication lag, an old value is read.
67 MessageGroups::singleton()->clearProcessCache();
68
69 if ( isset( $params[ 'purge' ] ) && $params[ 'purge' ] ) {
71 }
72
73 if ( isset( $params[ 'groupid' ] ) ) {
74 MessageGroupStats::forGroup( $params[ 'groupid' ], $flags );
75 } elseif ( isset( $params[ 'cleargroups' ] ) ) {
76 MessageGroupStats::clearGroup( $params[ 'cleargroups' ], $flags );
77 } elseif ( isset( $params[ 'languagecode' ] ) ) {
78 MessageGroupStats::forLanguage( $params[ 'languagecode' ], $flags );
79 } else {
80 throw new InvalidArgumentException( 'No groupid or languagecode or cleargroup provided' );
81 }
82
83 return true;
84 }
85}
Job for rebuilding message group stats.
static newRefreshGroupsJob(array $messageGroupIds)
Force updating of message group stats for given groups.
static clearGroup( $id, int $flags=0)
Recalculate stats for given group(s).
static forLanguage( $code, $flags=0)
Returns stats for all groups in given language.
const FLAG_IMMEDIATE_WRITES
Do not defer updates. Meant for jobs like MessageGroupStatsRebuildJob.
const FLAG_NO_CACHE
Ignore cached values. Useful for updating stale values.
static forGroup( $id, $flags=0)
Returns stats for all languages in given group.