20 private const MAX_TRIES = 3;
23 public function __construct( Title $title, array $params = [] ) {
24 parent::__construct(
'UpdateTranslatablePageJob', $title, $params );
38 $params[
'sections'] = [];
39 foreach ( $sections as $section ) {
40 $params[
'sections'][] = $section->serializeToArray();
43 return new self( $page->
getTitle(), $params );
46 public function run(): bool {
52 $this->logInfo(
'Starting UpdateTranslatablePageJob' );
54 $sections = $this->params[
'sections'];
55 foreach ( $sections as $index => $section ) {
59 if ( is_array( $section ) ) {
60 $sections[$index] = TranslationUnit::unserializeFromArray( $section );
69 $unitJobs = self::getTranslationUnitJobs( $page, $sections );
70 foreach ( $unitJobs as $job ) {
75 'Finished running ' . count( $unitJobs ) .
' MessageUpdate jobs for '
76 . count( $sections ) .
' sections'
79 $mwServices = MediaWikiServices::getInstance();
80 $lb = $mwServices->getDBLoadBalancerFactory();
81 if ( !$lb->waitForReplication() ) {
82 $this->logWarning(
'Continuing despite replication lag' );
90 MessageGroups::singleton()->clearProcessCache();
97 if ( $messageGroup ) {
102 usleep( 500 * 1000 );
103 }
while ( $attemptsCount <= self::MAX_TRIES );
105 if ( $messageGroup ) {
106 $messageGroup->clearCaches();
108 'Cleared caches after {attemptsCount} attempt(s)',
109 [
'attemptsCount' => $attemptsCount ]
113 'No message group found for page {pageTitle} after {attemptsCount} attempt(s)',
115 'pageTitle' => $page->
getTitle()->getPrefixedText(),
116 'attemptsCount' => self::MAX_TRIES
124 MessageGroupStats::forGroup(
126 MessageGroupStats::FLAG_NO_CACHE | MessageGroupStats::FLAG_IMMEDIATE_WRITES
128 $this->logInfo(
'Updated the message group stats' );
131 $wikiPage = $mwServices->getWikiPageFactory()->newFromTitle( $page->
getTitle() );
132 $wikiPage->doPurge();
133 $this->logInfo(
'Finished purging' );
136 $jobQueueGroup = $mwServices->getJobQueueGroup();
137 $renderJobs = self::getRenderJobs( $page );
138 $jobQueueGroup->push( $renderJobs );
139 $this->logInfo(
'Added ' . count( $renderJobs ) .
' RenderJobs to the queue' );
145 $job = RebuildMessageIndexJob::newJob();
146 $jobQueueGroup->push( $job );
148 $this->logInfo(
'Finished UpdateTranslatablePageJob' );
159 private static function getTranslationUnitJobs( TranslatablePage $page, array $units ): array {
162 $code = $page->getSourceLanguageCode();
163 $prefix = $page->getTitle()->getPrefixedText();
165 foreach ( $units as $unit ) {
166 $unitName = $unit->id;
167 $title = Title::makeTitle( NS_TRANSLATIONS,
"$prefix/$unitName/$code" );
169 $fuzzy = $unit->type ===
'changed';
170 $jobs[] = UpdateMessageJob::newJob( $title, $unit->getTextWithVariables(), $fuzzy );
181 $documentationLanguageCode = MediaWikiServices::getInstance()
183 ->get(
'TranslateDocumentationLanguageCode' );
194 foreach ( $stats as $languageCode => $languageStats ) {
195 if ( $languageStats[MessageGroupStats::TRANSLATED] > 0 && $languageCode !== $documentationLanguageCode ) {
196 $jobTitles[] = $page->
getTitle()->getSubpage( $languageCode );
202 $jobTitles = array_unique( $jobTitles );
203 foreach ( $jobTitles as $t ) {
204 if ( $nonPrioritizedJobs ) {
205 $jobs[] = RenderTranslationPageJob::newNonPrioritizedJob( $t );
207 $jobs[] = RenderTranslationPageJob::newJob( $t );