Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
TeardownHandler | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
postInitSetup | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
validate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
getParamSettings | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\ReadingLists\Rest; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | use MediaWiki\Extension\ReadingLists\ReadingListRepositoryException; |
7 | use MediaWiki\Logger\LoggerFactory; |
8 | use MediaWiki\Rest\Handler; |
9 | use MediaWiki\Rest\Response; |
10 | use MediaWiki\Rest\Validator\Validator; |
11 | use MediaWiki\User\CentralId\CentralIdLookup; |
12 | use Psr\Log\LoggerInterface; |
13 | use stdClass; |
14 | use Wikimedia\Rdbms\LBFactory; |
15 | |
16 | /** |
17 | * Tears down reading lists for the logged-in user |
18 | */ |
19 | class TeardownHandler extends Handler { |
20 | use ReadingListsHandlerTrait; |
21 | use ReadingListsTokenAwareHandlerTrait; |
22 | |
23 | private LBFactory $dbProvider; |
24 | |
25 | private Config $config; |
26 | |
27 | private CentralIdLookup $centralIdLookup; |
28 | |
29 | private LoggerInterface $logger; |
30 | |
31 | /** |
32 | * @param LBFactory $dbProvider |
33 | * @param Config $config |
34 | * @param CentralIdLookup $centralIdLookup |
35 | */ |
36 | public function __construct( |
37 | LBFactory $dbProvider, |
38 | Config $config, |
39 | CentralIdLookup $centralIdLookup |
40 | ) { |
41 | $this->dbProvider = $dbProvider; |
42 | $this->config = $config; |
43 | $this->centralIdLookup = $centralIdLookup; |
44 | $this->logger = LoggerFactory::getInstance( 'readinglists' ); |
45 | } |
46 | |
47 | /** |
48 | * Create the repository data access object instance. |
49 | * |
50 | * @return void |
51 | */ |
52 | public function postInitSetup() { |
53 | $this->repository = $this->createRepository( |
54 | $this->getAuthority()->getUser(), $this->dbProvider, $this->config, $this->centralIdLookup, $this->logger |
55 | ); |
56 | } |
57 | |
58 | /** |
59 | * @inheritDoc |
60 | */ |
61 | public function validate( Validator $restValidator ) { |
62 | parent::validate( $restValidator ); |
63 | $this->validateToken(); |
64 | } |
65 | |
66 | /** |
67 | * @return Response |
68 | */ |
69 | public function execute() { |
70 | $this->checkAuthority( $this->getAuthority() ); |
71 | |
72 | try { |
73 | $this->getRepository()->teardownForUser(); |
74 | } catch ( ReadingListRepositoryException $e ) { |
75 | $this->die( $e->getMessageObject() ); |
76 | } |
77 | |
78 | // For historical compatibility, response must be an empty object. |
79 | return $this->getResponseFactory()->createJson( new stdClass() ); |
80 | } |
81 | |
82 | /** |
83 | * @return array|array[] |
84 | */ |
85 | public function getParamSettings() { |
86 | return [] + $this->getReadingListsTokenParamDefinition() + $this->getTokenParamDefinition(); |
87 | } |
88 | } |