Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiSectionTranslationDelete | |
0.00% |
0 / 38 |
|
0.00% |
0 / 6 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
getAllowedParams | |
0.00% |
0 / 14 |
|
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 section translation |
4 | * |
5 | * @copyright See AUTHORS.txt |
6 | * @license GPL-2.0-or-later |
7 | */ |
8 | |
9 | namespace ContentTranslation\ActionApi; |
10 | |
11 | use ContentTranslation\Store\SectionTranslationStore; |
12 | use ContentTranslation\Store\TranslationCorporaStore; |
13 | use ContentTranslation\Store\TranslationStore; |
14 | use MediaWiki\Api\ApiBase; |
15 | use MediaWiki\Api\ApiMain; |
16 | use Wikimedia\ParamValidator\ParamValidator; |
17 | |
18 | class ApiSectionTranslationDelete extends ApiBase { |
19 | private TranslationCorporaStore $corporaStore; |
20 | private TranslationStore $translationStore; |
21 | private SectionTranslationStore $sectionTranslationStore; |
22 | |
23 | public function __construct( |
24 | ApiMain $mainModule, |
25 | string $action, |
26 | TranslationCorporaStore $corporaStore, |
27 | SectionTranslationStore $sectionTranslationStore, |
28 | TranslationStore $translationStore |
29 | ) { |
30 | parent::__construct( $mainModule, $action ); |
31 | $this->corporaStore = $corporaStore; |
32 | $this->translationStore = $translationStore; |
33 | $this->sectionTranslationStore = $sectionTranslationStore; |
34 | } |
35 | |
36 | public function execute() { |
37 | $params = $this->extractRequestParams(); |
38 | $user = $this->getUser(); |
39 | |
40 | $block = $user->getBlock(); |
41 | if ( $block && $block->isSitewide() ) { |
42 | $this->dieBlocked( $block ); |
43 | } |
44 | |
45 | $sectionTranslationId = $params['sectiontranslationid']; |
46 | $translationId = $params['translationid']; |
47 | $sectionId = $params['sectionid']; |
48 | // delete all corpora translation units associated with this draft section translation |
49 | $this->corporaStore->deleteTranslationDataBySectionId( $translationId, $sectionId ); |
50 | // delete the section translation from the database |
51 | $this->sectionTranslationStore->deleteTranslationById( $sectionTranslationId ); |
52 | |
53 | // if no other corpora units are associated with the "parent" translation id, update the |
54 | // status of the "parent" translation to "deleted" and remove the association with the |
55 | // current translator from inside the "cx_translators" table |
56 | if ( !$this->corporaStore->countByTranslationId( $translationId ) ) { |
57 | $this->translationStore->unlinkTranslationFromTranslator( $translationId ); |
58 | $this->translationStore->deleteTranslation( $translationId ); |
59 | } |
60 | |
61 | $result = [ 'result' => 'success' ]; |
62 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
63 | } |
64 | |
65 | public function getAllowedParams() { |
66 | return [ |
67 | 'sectiontranslationid' => [ |
68 | ParamValidator::PARAM_TYPE => 'integer', |
69 | ParamValidator::PARAM_REQUIRED => true, |
70 | ], |
71 | 'translationid' => [ |
72 | ParamValidator::PARAM_TYPE => 'integer', |
73 | ParamValidator::PARAM_REQUIRED => true, |
74 | ], |
75 | 'sectionid' => [ |
76 | ParamValidator::PARAM_TYPE => 'string', |
77 | ParamValidator::PARAM_REQUIRED => true, |
78 | ], |
79 | ]; |
80 | } |
81 | |
82 | public function needsToken() { |
83 | return 'csrf'; |
84 | } |
85 | |
86 | public function isWriteMode() { |
87 | return true; |
88 | } |
89 | |
90 | /** |
91 | * @see ApiBase::getExamplesMessages() |
92 | * @return array |
93 | */ |
94 | protected function getExamplesMessages() { |
95 | return [ |
96 | 'action=sxdelete&translationid=1§ionid=100_20' => 'apihelp-sxdelete-example-1' |
97 | ]; |
98 | } |
99 | |
100 | } |