summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/scripts/refresh-translatable-pages.php
blob: c5e0b1065105b780aad97623361b7aa09af441d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
 * Script to ensure all translation pages are up to date.
 *
 * @author Niklas Laxström
 * @license GPL-2.0-or-later
 * @file
 */

// Standard boilerplate to define $IP
if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
	$IP = getenv( 'MW_INSTALL_PATH' );
} else {
	$dir = __DIR__;
	$IP = "$dir/../../..";
}
require_once "$IP/maintenance/Maintenance.php";

/**
 * Script to ensure all translation pages are up to date
 * @since 2013-04
 */
class RefreshTranslatablePages extends Maintenance {
	public function __construct() {
		parent::__construct();
		$this->mDescription = 'Ensure all translation pages are up to date.';
		$this->setBatchSize( 300 );
		$this->addOption( 'jobqueue', 'Use JobQueue (asynchronous)' );
	}

	public function execute() {
		$groups = MessageGroups::singleton()->getGroups();
		$counter = 0;
		$useJobQueue = $this->hasOption( 'jobqueue' );

		/** @var MessageGroup $group */
		foreach ( $groups as $group ) {
			if ( !$group instanceof WikiPageMessageGroup ) {
				continue;
			}

			$counter++;
			if ( ( $counter % $this->mBatchSize ) === 0 ) {
				wfWaitForSlaves();
			}

			$page = TranslatablePage::newFromTitle( $group->getTitle() );
			$jobs = TranslationsUpdateJob::getRenderJobs( $page );
			if ( $useJobQueue ) {
				JobQueueGroup::singleton()->push( $jobs );
			} else {
				foreach ( $jobs as $job ) {
					$job->run();
				}
			}
		}

		if ( $useJobQueue ) {
			$this->output( "Queued refresh for $counter translatable pages.\n" );
		} else {
			$this->output( "Refreshed $counter translatable pages.\n" );
		}
	}
}

$maintClass = RefreshTranslatablePages::class;
require_once RUN_MAINTENANCE_IF_MAIN;