Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MessageGroupStatsRebuildJob.php
Go to the documentation of this file.
1<?php
12use MediaWiki\MediaWikiServices;
13
24 public static function newJob( $params ) {
25 $job = new self( Title::newMainPage(), $params );
26 return $job;
27 }
28
39 public static function newRefreshGroupsJob( array $messageGroupIds ) {
40 return new self( Title::newMainPage(), [ 'cleargroups' => $messageGroupIds ] );
41 }
42
47 public function __construct( $title, $params = [] ) {
48 parent::__construct( __CLASS__, $title, $params );
49 }
50
51 public function run() {
52 $lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
53 if ( !$lb->waitForReplication() ) {
54 $this->logWarning( 'Continuing despite replication lag' );
55 }
56
57 $params = $this->params;
58 $flags = 0;
59
60 // Sanity check that this is run via JobQueue. Immediate writes are only safe when they
61 // are run in isolation, e.g. as a separate job in the JobQueue.
62 if ( defined( 'MEDIAWIKI_JOB_RUNNER' ) ) {
64 }
65
66 // This is to make sure the priority value is not read from the process cache.
67 // There is still a possibility that, due to replication lag, an old value is read.
68 MessageGroups::singleton()->clearProcessCache();
69
70 if ( isset( $params[ 'purge' ] ) && $params[ 'purge' ] ) {
72 }
73
74 if ( isset( $params[ 'groupid' ] ) ) {
75 MessageGroupStats::forGroup( $params[ 'groupid' ], $flags );
76 } elseif ( isset( $params[ 'cleargroups' ] ) ) {
77 MessageGroupStats::clearGroup( $params[ 'cleargroups' ], $flags );
78 } elseif ( isset( $params[ 'languagecode' ] ) ) {
79 MessageGroupStats::forLanguage( $params[ 'languagecode' ], $flags );
80 } else {
81 throw new InvalidArgumentException( 'No groupid or languagecode or cleargroup provided' );
82 }
83
84 return true;
85 }
86}
Factory class for accessing message groups individually by id or all of them as a list.
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.