Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DataUpdatesHooks | |
0.00% |
0 / 11 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onRevisionDataUpdates | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * DiscussionTools data updates hooks |
4 | * |
5 | * @file |
6 | * @ingroup Extensions |
7 | * @license MIT |
8 | */ |
9 | |
10 | namespace MediaWiki\Extension\DiscussionTools\Hooks; |
11 | |
12 | use MediaWiki\Deferred\DeferrableUpdate; |
13 | use MediaWiki\Deferred\MWCallableUpdate; |
14 | use MediaWiki\Extension\DiscussionTools\ThreadItemStore; |
15 | use MediaWiki\Revision\RenderedRevision; |
16 | use MediaWiki\Storage\Hook\RevisionDataUpdatesHook; |
17 | use MediaWiki\Title\Title; |
18 | use MWExceptionHandler; |
19 | use Throwable; |
20 | |
21 | class DataUpdatesHooks implements RevisionDataUpdatesHook { |
22 | |
23 | private ThreadItemStore $threadItemStore; |
24 | |
25 | public function __construct( |
26 | ThreadItemStore $threadItemStore |
27 | ) { |
28 | $this->threadItemStore = $threadItemStore; |
29 | } |
30 | |
31 | /** |
32 | * @param Title $title |
33 | * @param RenderedRevision $renderedRevision |
34 | * @param DeferrableUpdate[] &$updates |
35 | * @return bool|void |
36 | */ |
37 | public function onRevisionDataUpdates( $title, $renderedRevision, &$updates ) { |
38 | // This doesn't trigger on action=purge, only on automatic purge after editing a template or |
39 | // transcluded page, and API action=purge&forcelinkupdate=1. |
40 | |
41 | // TODO: Deduplicate the thread-item-processing done here with the Echo hook |
42 | // (which thread-item-processes the current and previous revisions). |
43 | $rev = $renderedRevision->getRevision(); |
44 | if ( HookUtils::isAvailableForTitle( $title ) ) { |
45 | $method = __METHOD__; |
46 | $updates[] = new MWCallableUpdate( function () use ( $rev, $method ) { |
47 | try { |
48 | $threadItemSet = HookUtils::parseRevisionParsoidHtml( $rev, $method ); |
49 | if ( !$this->threadItemStore->isDisabled() ) { |
50 | $this->threadItemStore->insertThreadItems( $rev, $threadItemSet ); |
51 | } |
52 | } catch ( Throwable $e ) { |
53 | // Catch errors, so that they don't cause other updates to fail (T315383), but log them. |
54 | MWExceptionHandler::logException( $e ); |
55 | } |
56 | }, __METHOD__ ); |
57 | } |
58 | } |
59 | } |