Translate extension for MediaWiki
Loading...
Searching...
No Matches
MessageIndexRebuildJob.php
Go to the documentation of this file.
1
<?php
11
use
MediaWiki\Extension\Translate\Jobs\GenericTranslateJob
;
12
use
MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups
;
13
use MediaWiki\MediaWikiServices;
14
20
class
MessageIndexRebuildJob
extends
GenericTranslateJob
{
22
public
static
function
newJob
() {
23
$timestamp = microtime(
true
);
24
$job =
new
self
( Title::newMainPage(), [
'timestamp'
=> $timestamp ] );
25
26
return
$job;
27
}
28
33
public
function
__construct
( $title, $params = [] ) {
34
parent::__construct( __CLASS__, $title, $params );
35
$this->removeDuplicates =
true
;
36
}
37
38
public
function
run() {
39
// Make sure we have latest version of message groups from global cache.
40
// This should be pretty fast, just a few cache fetches with some post processing.
41
MessageGroups::singleton()->clearProcessCache();
42
43
// BC for existing jobs which may not have this parameter set
44
$timestamp = $this->getParams()[
'timestamp'
] ?? microtime(
true
);
45
46
try
{
47
MessageIndex::singleton()->rebuild( $timestamp );
48
}
catch
(
MessageIndexException
$e ) {
49
// Currently there is just one type of exception: lock wait time exceeded.
50
// Assuming no bugs, this is a transient issue and retry will solve it.
51
$this->logWarning( $e->getMessage() );
52
// Try again later. See ::allowRetries
53
return
false
;
54
}
55
56
return
true
;
57
}
58
60
public
function
allowRetries
() {
61
// This is the default, but added for explicitness and clarity
62
return
true
;
63
}
64
66
public
function
getDeduplicationInfo
() {
67
$info = parent::getDeduplicationInfo();
68
// The timestamp is different for every job, so ignore it. The worst that can
69
// happen is that the front cache is not cleared until a future job is created.
70
// There is a check in MessageIndex to spawn a new job if timestamp is smaller
71
// than expected.
72
//
73
// Ideally we would take the latest timestamp, but it seems that the job queue
74
// just prevents insertion of duplicate jobs instead.
75
unset( $info[
'params'
][
'timestamp'
] );
76
77
return
$info;
78
}
79
81
public
function
insertIntoJobQueue
(): void {
82
MediaWikiServices::getInstance()->getJobQueueGroup()->push( $this );
83
}
84
}
MediaWiki\Extension\Translate\Jobs\GenericTranslateJob
Generic Job class extended by other jobs.
Definition
GenericTranslateJob.php:16
MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups
Factory class for accessing message groups individually by id or all of them as a list.
Definition
MessageGroups.php:33
MessageIndexException
Definition
MessageIndexException.php:9
MessageIndexRebuildJob
Job for rebuilding message index.
Definition
MessageIndexRebuildJob.php:20
MessageIndexRebuildJob\getDeduplicationInfo
getDeduplicationInfo()
@inheritDoc
Definition
MessageIndexRebuildJob.php:66
MessageIndexRebuildJob\allowRetries
allowRetries()
@inheritDoc
Definition
MessageIndexRebuildJob.php:60
MessageIndexRebuildJob\insertIntoJobQueue
insertIntoJobQueue()
Definition
MessageIndexRebuildJob.php:81
MessageIndexRebuildJob\__construct
__construct( $title, $params=[])
Definition
MessageIndexRebuildJob.php:33
MessageIndexRebuildJob\newJob
static newJob()
Definition
MessageIndexRebuildJob.php:22
utils
MessageIndexRebuildJob.php
Generated by
1.10.0