summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/ttmserver/TTMServerMessageUpdateJob.php
blob: 9f10e734454086a47c184589064e40b5f3921f63 (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
<?php
/**
 * Contains class with job for updating translation memory.
 *
 * @file
 * @author Niklas Laxström
 * @copyright Copyright © 2012-2013, Niklas Laxström
 * @license GPL-2.0+
 */

/**
 * Job for updating translation memory.
 *
 * @ingroup JobQueue
 */
class TTMServerMessageUpdateJob extends Job {
	/**
	 * @param MessageHandle $handle
	 * @return TTMServerMessageUpdateJob
	 */
	public static function newJob( MessageHandle $handle ) {
		$job = new self( $handle->getTitle() );

		return $job;
	}

	/**
	 * @param Title $title
	 * @param array $params
	 * @param int $id
	 */
	public function __construct( $title, $params = array(), $id = 0 ) {
		parent::__construct( __CLASS__, $title, $params, $id );
	}

	/**
	 * Fetch all the translations and update them.
	 */
	public function run() {
		$handle = new MessageHandle( $this->title );
		$translations = ApiQueryMessageTranslations::getTranslations( $handle );
		foreach ( $translations as $page => $data ) {
			$tTitle = Title::makeTitle( $this->title->getNamespace(), $page );
			$tHandle = new MessageHandle( $tTitle );
			TTMServer::onChange( $tHandle, $data[0], $tHandle->isFuzzy() );
		}

		return true;
	}
}