Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DeleteArchive | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
doJob | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Job; |
4 | |
5 | use CirrusSearch\Connection; |
6 | use CirrusSearch\Updater; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\Title\Title; |
9 | |
10 | /** |
11 | * Job wrapper for deleting pages from archive. |
12 | */ |
13 | class DeleteArchive extends CirrusTitleJob { |
14 | public function __construct( Title $title, array $params ) { |
15 | // While the delete is not itself private, it can only fail on clusters |
16 | // without private data as the index does not exist. |
17 | parent::__construct( $title, [ 'private_data' => true ] + $params ); |
18 | |
19 | // Don't remove dupes since we do checks that may return different results |
20 | // Also, deletes are idempotent so it's no problem if we delete twice. |
21 | $this->removeDuplicates = false; |
22 | } |
23 | |
24 | /** |
25 | * @return bool |
26 | */ |
27 | protected function doJob() { |
28 | $docs = $this->params['docIds']; |
29 | |
30 | // Remove page IDs that still have archived revs |
31 | $archivedRevisionLookup = MediaWikiServices::getInstance()->getArchivedRevisionLookup(); |
32 | foreach ( $archivedRevisionLookup->listRevisions( $this->title ) as $rev ) { |
33 | unset( $docs[$rev->ar_page_id] ); |
34 | } |
35 | |
36 | if ( !$docs ) { |
37 | // If we have more deleted instances of the same title, no need to bother. |
38 | return true; |
39 | } |
40 | |
41 | $updater = Updater::build( $this->getSearchConfig(), $this->params['cluster'] ?? null ); |
42 | $updater->deletePages( |
43 | [ $this->title ], |
44 | array_keys( $docs ), |
45 | Connection::ARCHIVE_INDEX_SUFFIX, |
46 | [ 'private_data' => true ] |
47 | ); |
48 | |
49 | return true; |
50 | } |
51 | } |