Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
TtmServer
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 5
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 sortSuggestions
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 onDelete
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 onChange
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 onGroupChange
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TtmServer;
5
6use MediaWiki\Extension\Translate\MessageLoading\MessageHandle;
7use MediaWiki\MediaWikiServices;
8use WikiPage;
9
10/**
11 * TtmServer - The Translate extension translation memory interface
12 * Some general static methods for instantiating TtmServer and helpers.
13 * @author Niklas Laxström
14 * @license GPL-2.0-or-later
15 * @defgroup TtmServer The Translate extension translation memory interface
16 * @ingroup TTMServerp
17 */
18abstract class TtmServer {
19    protected array $config;
20
21    public function __construct( array $config ) {
22        $this->config = $config;
23    }
24
25    /**
26     * @param array[] $suggestions
27     * @return array[]
28     */
29    public static function sortSuggestions( array $suggestions ): array {
30        usort( $suggestions, static function ( array $a, array $b ) {
31            return $b['quality'] <=> $a['quality'];
32        } );
33
34        return $suggestions;
35    }
36
37    /** Hook: ArticleDeleteComplete */
38    public static function onDelete( WikiPage $wikipage ): void {
39        $handle = new MessageHandle( $wikipage->getTitle() );
40        $job = TtmServerMessageUpdateJob::newJob( $handle, 'delete' );
41        MediaWikiServices::getInstance()->getJobQueueGroup()->push( $job );
42    }
43
44    /** Called from TranslateEditAddons::onSave */
45    public static function onChange( MessageHandle $handle ): void {
46        $job = TtmServerMessageUpdateJob::newJob( $handle, 'refresh' );
47        MediaWikiServices::getInstance()->getJobQueueGroup()->push( $job );
48    }
49
50    public static function onGroupChange( MessageHandle $handle, array $old ): void {
51        if ( $old === [] ) {
52            // Don't bother for newly added messages
53            return;
54        }
55
56        $job = TtmServerMessageUpdateJob::newJob( $handle, 'rebuild' );
57        MediaWikiServices::getInstance()->getJobQueueGroup()->push( $job );
58    }
59}