Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
MoveTranslatableBundleJob
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 newJob
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageGroupProcessing;
5
6use Job;
7use MediaWiki\Extension\Translate\PageTranslation\TranslatableBundleMover;
8use MediaWiki\Extension\Translate\Services;
9use MediaWiki\MediaWikiServices;
10use MediaWiki\Title\Title;
11use MediaWiki\User\User;
12
13/**
14 * Contains class with job for moving translation pages.
15 *
16 * @author Niklas Laxström
17 * @license GPL-2.0-or-later
18 * @ingroup PageTranslation JobQueue
19 */
20class MoveTranslatableBundleJob extends Job {
21    private TranslatableBundleMover $bundleMover;
22
23    /**
24     * @param Title $source
25     * @param Title $target
26     * @param array<string,string> $moves list of pages to be moved
27     * @param array<string,bool> $redirects a list of pages to leave redirect for
28     * @param string $reason
29     * @param User $performer
30     * @return self
31     */
32    public static function newJob(
33        Title $source,
34        Title $target,
35        array $moves,
36        array $redirects,
37        string $reason,
38        User $performer
39    ): self {
40        $params = [
41            'source' => $source->getPrefixedText(),
42            'target' => $target->getPrefixedText(),
43            'moves' => $moves,
44            'redirects' => $redirects,
45            'summary' => $reason,
46            'performer' => $performer->getName(),
47        ];
48
49        return new self( $target, $params );
50    }
51
52    public function __construct( Title $title, array $params = [] ) {
53        parent::__construct( 'MoveTranslatableBundleJob', $title, $params );
54        $this->bundleMover = Services::getInstance()->getTranslatableBundleMover();
55    }
56
57    public function run() {
58        $sourceTitle = Title::newFromText( $this->params['source'] );
59        $targetTitle = Title::newFromText( $this->params['target'] );
60
61        $userFactory = MediaWikiServices::getInstance()->getUserFactory();
62        $performer = $userFactory->newFromName( $this->params['performer'] );
63
64        $this->bundleMover->moveSynchronously(
65            $sourceTitle,
66            $targetTitle,
67            $this->params['moves'],
68            $this->params['redirects'] ?? [],
69            $performer,
70            $this->params['summary']
71        );
72
73        return true;
74    }
75}