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\Exception\MWExceptionHandler; |
| 15 | use MediaWiki\Extension\DiscussionTools\ThreadItemStore; |
| 16 | use MediaWiki\Revision\RenderedRevision; |
| 17 | use MediaWiki\Storage\Hook\RevisionDataUpdatesHook; |
| 18 | use MediaWiki\Title\Title; |
| 19 | use Throwable; |
| 20 | |
| 21 | class DataUpdatesHooks implements RevisionDataUpdatesHook { |
| 22 | |
| 23 | public function __construct( |
| 24 | private readonly ThreadItemStore $threadItemStore, |
| 25 | ) { |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @param Title $title |
| 30 | * @param RenderedRevision $renderedRevision |
| 31 | * @param DeferrableUpdate[] &$updates |
| 32 | * @return bool|void |
| 33 | */ |
| 34 | public function onRevisionDataUpdates( $title, $renderedRevision, &$updates ) { |
| 35 | // This doesn't trigger on action=purge, only on automatic purge after editing a template or |
| 36 | // transcluded page, and API action=purge&forcelinkupdate=1. |
| 37 | |
| 38 | // TODO: Deduplicate the thread-item-processing done here with the Echo hook |
| 39 | // (which thread-item-processes the current and previous revisions). |
| 40 | $rev = $renderedRevision->getRevision(); |
| 41 | if ( HookUtils::isAvailableForTitle( $title ) ) { |
| 42 | $method = __METHOD__; |
| 43 | $updates[] = new MWCallableUpdate( function () use ( $rev, $method ) { |
| 44 | try { |
| 45 | $threadItemSet = HookUtils::parseRevisionParsoidHtml( $rev, $method )->getValueOrThrow(); |
| 46 | if ( !$this->threadItemStore->isDisabled() ) { |
| 47 | $this->threadItemStore->insertThreadItems( $rev, $threadItemSet ); |
| 48 | } |
| 49 | } catch ( Throwable $e ) { |
| 50 | // Catch errors, so that they don't cause other updates to fail (T315383), but log them. |
| 51 | MWExceptionHandler::logException( $e ); |
| 52 | } |
| 53 | }, __METHOD__ ); |
| 54 | } |
| 55 | } |
| 56 | } |