Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
BoardHistoryBlock | |
0.00% |
0 / 35 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
validate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
commit | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
renderApi | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
30 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Block; |
4 | |
5 | use Flow\Container; |
6 | use Flow\Data\Pager\HistoryPager; |
7 | use Flow\Exception\DataModelException; |
8 | use Flow\Formatter\BoardHistoryQuery; |
9 | use Flow\Formatter\RevisionFormatter; |
10 | |
11 | class BoardHistoryBlock extends AbstractBlock { |
12 | /** @inheritDoc */ |
13 | protected $supportedGetActions = [ 'history' ]; |
14 | |
15 | /** |
16 | * @var string[] |
17 | * @todo Fill in the template names |
18 | */ |
19 | protected $templates = [ |
20 | 'history' => '', |
21 | ]; |
22 | |
23 | /** |
24 | * Board history is read-only block which should not invoke write action |
25 | * @suppress PhanPluginNeverReturnMethod LSP/ISP violation. |
26 | */ |
27 | public function validate() { |
28 | throw new DataModelException( __CLASS__ . ' should not invoke validate()', 'process-data' ); |
29 | } |
30 | |
31 | /** |
32 | * Board history is read-only block which should not invoke write action |
33 | * @suppress PhanPluginNeverReturnMethod LSP/ISP violation. |
34 | */ |
35 | public function commit() { |
36 | throw new DataModelException( __CLASS__ . ' should not invoke commit()', 'process-data' ); |
37 | } |
38 | |
39 | public function renderApi( array $options ) { |
40 | global $wgRequest; |
41 | |
42 | if ( $this->workflow->isNew() ) { |
43 | return [ |
44 | 'type' => $this->getName(), |
45 | 'revisions' => [], |
46 | 'links' => [ |
47 | ], |
48 | ]; |
49 | } |
50 | |
51 | /** @var BoardHistoryQuery $query */ |
52 | $query = Container::get( 'query.board.history' ); |
53 | /** @var RevisionFormatter $formatter */ |
54 | $formatter = Container::get( 'formatter.revision.factory' )->create(); |
55 | $formatter->setIncludeHistoryProperties( true ); |
56 | |
57 | [ $limit, /* $offset */ ] = $wgRequest->getLimitOffsetForUser( |
58 | $this->context->getUser() |
59 | ); |
60 | // don't use offset from getLimitOffset - that assumes an int, which our |
61 | // UUIDs are not |
62 | $offset = $wgRequest->getText( 'offset' ); |
63 | $offset = $offset ?: null; |
64 | |
65 | $pager = new HistoryPager( $query, $this->workflow->getId() ); |
66 | $pager->setLimit( $limit ); |
67 | $pager->setOffset( $offset ); |
68 | $pager->doQuery(); |
69 | $history = $pager->getResult(); |
70 | |
71 | $revisions = []; |
72 | foreach ( $history as $row ) { |
73 | $serialized = $formatter->formatApi( $row, $this->context, 'history' ); |
74 | if ( $serialized ) { |
75 | $revisions[$serialized['revisionId']] = $serialized; |
76 | } |
77 | } |
78 | |
79 | return [ |
80 | 'type' => $this->getName(), |
81 | 'revisions' => $revisions, |
82 | 'navbar' => $pager->getNavigationBar(), |
83 | 'links' => [ |
84 | ], |
85 | ]; |
86 | } |
87 | |
88 | public function getName() { |
89 | return 'board-history'; |
90 | } |
91 | } |