Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiContentTranslationDelete | |
0.00% |
0 / 39 |
|
0.00% |
0 / 6 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
30 | |||
getAllowedParams | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
needsToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isWriteMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Delete a translation |
4 | * |
5 | * @copyright See AUTHORS.txt |
6 | * @license GPL-2.0-or-later |
7 | */ |
8 | |
9 | namespace ContentTranslation\ActionApi; |
10 | |
11 | use ApiBase; |
12 | use ApiMain; |
13 | use ContentTranslation\Store\TranslationCorporaStore; |
14 | use ContentTranslation\Store\TranslationStore; |
15 | use Wikimedia\ParamValidator\ParamValidator; |
16 | |
17 | class ApiContentTranslationDelete extends ApiBase { |
18 | /** @var TranslationCorporaStore */ |
19 | private $corporaStore; |
20 | |
21 | /** @var TranslationStore */ |
22 | private TranslationStore $translationStore; |
23 | |
24 | public function __construct( |
25 | ApiMain $mainModule, $action, |
26 | TranslationCorporaStore $corporaStore, |
27 | TranslationStore $translationStore |
28 | ) { |
29 | parent::__construct( $mainModule, $action ); |
30 | $this->corporaStore = $corporaStore; |
31 | $this->translationStore = $translationStore; |
32 | } |
33 | |
34 | public function execute() { |
35 | $params = $this->extractRequestParams(); |
36 | $user = $this->getUser(); |
37 | |
38 | $block = $user->getBlock(); |
39 | if ( $block && $block->isSitewide() ) { |
40 | $this->dieBlocked( $block ); |
41 | } |
42 | |
43 | [ 'sourcetitle' => $sourceTitle, 'from' => $sourceLang, 'to' => $targetLang ] = $params; |
44 | $translation = $this->translationStore->findTranslationByUser( $user, $sourceTitle, $sourceLang, $targetLang ); |
45 | |
46 | if ( $translation === null ) { |
47 | $this->dieWithError( |
48 | [ 'apierror-invalidtitle', wfEscapeWikiText( $sourceTitle ) ] |
49 | ); |
50 | } |
51 | |
52 | if ( $translation->translation['targetURL'] !== null ) { |
53 | // Translation was once published. Don't delete, move it to published status. |
54 | $translation->translation['status'] = TranslationStore::TRANSLATION_STATUS_PUBLISHED; |
55 | $this->translationStore->updateTranslation( $translation ); |
56 | } else { |
57 | $translationId = $translation->getData()['id']; |
58 | $this->translationStore->unlinkTranslationFromTranslator( $translationId ); |
59 | $this->translationStore->deleteTranslation( $translationId ); |
60 | $this->corporaStore->deleteTranslationData( $translationId ); |
61 | } |
62 | |
63 | $result = [ 'result' => 'success' ]; |
64 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
65 | } |
66 | |
67 | public function getAllowedParams() { |
68 | return [ |
69 | 'from' => [ |
70 | ParamValidator::PARAM_REQUIRED => true, |
71 | ], |
72 | 'to' => [ |
73 | ParamValidator::PARAM_REQUIRED => true, |
74 | ], |
75 | 'sourcetitle' => [ |
76 | ParamValidator::PARAM_REQUIRED => true, |
77 | ], |
78 | ]; |
79 | } |
80 | |
81 | public function needsToken() { |
82 | return 'csrf'; |
83 | } |
84 | |
85 | public function isWriteMode() { |
86 | return true; |
87 | } |
88 | |
89 | /** |
90 | * @see ApiBase::getExamplesMessages() |
91 | * @return array |
92 | */ |
93 | protected function getExamplesMessages() { |
94 | return [ |
95 | 'action=cxdelete&from=en&to=es&sourcetitle=Food' => 'apihelp-cxdelete-example-1' |
96 | ]; |
97 | } |
98 | |
99 | } |