21 public function __construct( Title $title, array $params = [] ) {
22 parent::__construct(
'UpdateTranslatablePageJob', $title, $params );
36 $params[
'sections' ] = [];
37 foreach ( $sections as $section ) {
38 $params[
'sections' ][] = $section->serializeToArray();
41 return new self( $page->
getTitle(), $params );
44 public function run(): bool {
50 $this->logInfo(
'Starting UpdateTranslatablePageJob' );
52 $sections = $this->params[
'sections' ];
53 foreach ( $sections as $index => $section ) {
57 if ( is_array( $section ) ) {
58 $sections[ $index ] = TranslationUnit::unserializeFromArray( $section );
67 $unitJobs = self::getTranslationUnitJobs( $page, $sections );
68 foreach ( $unitJobs as $job ) {
73 'Finished running ' . count( $unitJobs ) .
' MessageUpdate jobs for '
74 . count( $sections ) .
' sections'
77 $mwServices = MediaWikiServices::getInstance();
78 $lb = $mwServices->getDBLoadBalancerFactory();
79 if ( !$lb->waitForReplication() ) {
80 $this->logWarning(
'Continuing despite replication lag' );
87 MessageGroups::singleton()->clearProcessCache();
91 $this->logInfo(
'Cleared caches' );
98 MessageGroupStats::FLAG_NO_CACHE | MessageGroupStats::FLAG_IMMEDIATE_WRITES
100 $this->logInfo(
'Updated the message group stats' );
103 $wikiPage = $mwServices->getWikiPageFactory()->newFromTitle( $page->
getTitle() );
104 $wikiPage->doPurge();
105 $this->logInfo(
'Finished purging' );
108 $jobQueueGroup = $mwServices->getJobQueueGroup();
109 $renderJobs = self::getRenderJobs( $page );
110 $jobQueueGroup->push( $renderJobs );
111 $this->logInfo(
'Added ' . count( $renderJobs ) .
' RenderJobs to the queue' );
118 $jobQueueGroup->push( $job );
120 $this->logInfo(
'Finished UpdateTranslatablePageJob' );
131 private static function getTranslationUnitJobs( TranslatablePage $page, array $units ): array {
134 $code = $page->getSourceLanguageCode();
135 $prefix = $page->getTitle()->getPrefixedText();
137 foreach ( $units as $unit ) {
138 $unitName = $unit->id;
139 $title = Title::makeTitle( NS_TRANSLATIONS,
"$prefix/$unitName/$code" );
141 $fuzzy = $unit->type ===
'changed';
162 foreach ( $stats as $languageCode => $languageStats ) {
163 if ( $languageStats[MessageGroupStats::TRANSLATED] > 0 ) {
164 $jobTitles[] = $page->
getTitle()->getSubpage( $languageCode );
170 $jobTitles = array_unique( $jobTitles );
171 foreach ( $jobTitles as $t ) {
172 $jobs[] = RenderTranslationPageJob::newJob( $t );