Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
CompleteExternalTranslationMaintenanceScript.php
1<?php
2
3declare( strict_types = 1 );
4
6
7use Maintenance;
9use MediaWiki\Logger\LoggerFactory;
10use MediaWiki\MediaWikiServices;
12
19 public function __construct() {
20 parent::__construct();
21 $this->addDescription(
22 'Check and run MessageIndexRebuild and MessageGroupStats update once ' .
23 'MessageUpdateJobs are done. Intended to be run periodically'
24 );
25 $this->requireExtension( 'Translate' );
26 }
27
28 public function execute() {
29 $mwServices = MediaWikiServices::getInstance();
30 $config = $mwServices->getMainConfig();
31
32 if ( !$config->get( 'TranslateGroupSynchronizationCache' ) ) {
33 $this->fatalError( 'GroupSynchronizationCache is not enabled' );
34 }
35
36 $logger = LoggerFactory::getInstance( 'Translate.GroupSynchronization' );
37 $groupSyncCache = Services::getInstance()->getGroupSynchronizationCache();
38 $groupsInSync = $groupSyncCache->getGroupsInSync();
39 if ( !$groupsInSync ) {
40 $logger->info( 'All message groups are in sync' );
41 return;
42 }
43
44 $logger->info( 'Group synchronization is in progress' );
45
46 $groupsInProgress = [];
47 foreach ( $groupsInSync as $groupId ) {
48 $groupResponse = $groupSyncCache->getSynchronizationStatus( $groupId );
49
50 if ( $groupResponse->isDone() ) {
51 $groupSyncCache->endSync( $groupId );
52 continue;
53 }
54
55 if ( $groupResponse->hasTimedOut() ) {
56 $remainingMessages = $groupResponse->getRemainingMessages();
57 $logger->warning(
58 'MessageUpdateJobs timed out for group - {groupId}; ' .
59 'Messages - {messages}; ' .
60 'Jobs remaining - {jobRemaining}',
61 [
62 'groupId' => $groupId ,
63 'jobRemaining' => count( $remainingMessages ),
64 'messages' => implode( ', ', array_keys( $remainingMessages ) )
65 ]
66 );
67
68 $count = count( $remainingMessages );
69 wfLogWarning( "MessageUpdateJob timed out for group $groupId with $count message(s) remaining" );
70 $groupSyncCache->forceEndSync( $groupId );
71
72 $groupSyncCache->addGroupErrors( $groupResponse );
73
74 } else {
75 $groupsInProgress[] = $groupId;
76 }
77 }
78
79 if ( !$groupsInProgress ) {
80 // No groups in progress.
81 $logger->info( 'All message groups are now in sync.' );
82 $mwServices->getJobQueueGroup()->push( MessageIndexRebuildJob::newJob() );
83 }
84
85 $logger->info(
86 "Script completed successfully. " .
87 "{inProgressGroupCount} group synchronization(s) is/are in progress",
88 [
89 'inProgressGroupCount' => count( $groupsInProgress )
90 ]
91 );
92 }
93}
Minimal service container.
Definition Services.php:44
Job for rebuilding message index.
Finds external changes for file based message groups.