Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.59% |
25 / 27 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
ListsEntriesDeleteHandler | |
92.59% |
25 / 27 |
|
75.00% |
3 / 4 |
5.01 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
postInitSetup | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
run | |
66.67% |
4 / 6 |
|
0.00% |
0 / 1 |
2.15 | |||
getParamSettings | |
100.00% |
14 / 14 |
|
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\SimpleHandler; |
11 | use MediaWiki\User\CentralId\CentralIdLookup; |
12 | use Psr\Log\LoggerInterface; |
13 | use stdClass; |
14 | use Wikimedia\ParamValidator\ParamValidator; |
15 | use Wikimedia\ParamValidator\TypeDef\NumericDef; |
16 | use Wikimedia\Rdbms\LBFactory; |
17 | |
18 | /** |
19 | * Handle DELETE requests to /readinglists/v0/lists/{id}/entries |
20 | * |
21 | * Gets reading list entries |
22 | */ |
23 | class ListsEntriesDeleteHandler extends SimpleHandler { |
24 | use ReadingListsHandlerTrait; |
25 | use ReadingListsTokenAwareHandlerTrait; |
26 | |
27 | private LBFactory $dbProvider; |
28 | |
29 | private Config $config; |
30 | |
31 | private CentralIdLookup $centralIdLookup; |
32 | |
33 | private LoggerInterface $logger; |
34 | |
35 | /** |
36 | * @param LBFactory $dbProvider |
37 | * @param Config $config |
38 | * @param CentralIdLookup $centralIdLookup |
39 | */ |
40 | public function __construct( |
41 | LBFactory $dbProvider, |
42 | Config $config, |
43 | CentralIdLookup $centralIdLookup |
44 | ) { |
45 | $this->dbProvider = $dbProvider; |
46 | $this->config = $config; |
47 | $this->centralIdLookup = $centralIdLookup; |
48 | $this->logger = LoggerFactory::getInstance( 'readinglists' ); |
49 | } |
50 | |
51 | /** |
52 | * Create the repository data access object instance. |
53 | * |
54 | * @return void |
55 | */ |
56 | public function postInitSetup() { |
57 | $this->repository = $this->createRepository( |
58 | $this->getAuthority()->getUser(), $this->dbProvider, $this->config, $this->centralIdLookup, $this->logger |
59 | ); |
60 | } |
61 | |
62 | /** |
63 | * @param int $id the list to update |
64 | * @param int $entryId the list entry to update |
65 | * @return Response |
66 | */ |
67 | public function run( int $id, int $entryId ) { |
68 | $this->checkAuthority( $this->getAuthority() ); |
69 | |
70 | $repository = $this->getRepository(); |
71 | |
72 | try { |
73 | $repository->deleteListEntry( $entryId ); |
74 | } catch ( ReadingListRepositoryException $e ) { |
75 | $this->die( $e->getMessageObject() ); |
76 | } |
77 | |
78 | // Return value is expected to be an empty json object |
79 | return $this->getResponseFactory()->createJson( new stdClass ); |
80 | } |
81 | |
82 | /** |
83 | * @return array[] |
84 | */ |
85 | public function getParamSettings() { |
86 | return [ |
87 | // The original contract required an "id" parameter as part of the path. |
88 | // It isn't actually used - entries have their own unique id sufficient to |
89 | // identify and delete the entry. But we are obligated to include it. |
90 | 'id' => [ |
91 | ParamValidator::PARAM_TYPE => 'integer', |
92 | ParamValidator::PARAM_REQUIRED => true, |
93 | Handler::PARAM_SOURCE => 'path', |
94 | NumericDef::PARAM_MIN => 1, |
95 | ], |
96 | 'entry_id' => [ |
97 | ParamValidator::PARAM_TYPE => 'integer', |
98 | ParamValidator::PARAM_REQUIRED => true, |
99 | Handler::PARAM_SOURCE => 'path', |
100 | NumericDef::PARAM_MIN => 1, |
101 | ], |
102 | ]; |
103 | } |
104 | } |