Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
TopicPageCreationListener
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 onAfterLoad
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 onAfterInsert
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Flow\Data\Listener;
4
5use Flow\Model\Workflow;
6use Flow\OccupationController;
7use MediaWiki\MediaWikiServices;
8use SplQueue;
9
10class TopicPageCreationListener extends AbstractListener {
11    /** @var OccupationController */
12    protected $occupationController;
13
14    /** @var SplQueue */
15    protected $deferredQueue;
16
17    /**
18     * @param OccupationController $occupationController The OccupationController to create the page with.
19     * @param SplQueue $deferredQueue Queue of callbacks to run only if commit succeeds
20     */
21    public function __construct(
22        OccupationController $occupationController,
23        SplQueue $deferredQueue
24    ) {
25        $this->occupationController = $occupationController;
26        $this->deferredQueue = $deferredQueue;
27    }
28
29    public function onAfterLoad( $object, array $old ) {
30        // Nothing
31    }
32
33    public function onAfterInsert( $object, array $new, array $metadata ) {
34        if ( !$object instanceof Workflow ) {
35            return;
36        }
37
38        // make sure this Topic:xyz page exists
39        $controller = $this->occupationController;
40        $this->deferredQueue->push( static function () use ( $controller, $object ) {
41            $controller->ensureFlowRevision(
42                MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $object->getArticleTitle() ),
43                $object
44            );
45        } );
46    }
47}