Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
CategoryViewerQuery | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadMetadataBatch | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
42 | |||
getResult | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace Flow\Formatter; |
4 | |
5 | use Flow\Data\ManagerGroup; |
6 | use Flow\Exception\FlowException; |
7 | use Flow\Model\PostRevision; |
8 | use Flow\Model\UUID; |
9 | use Flow\Model\Workflow; |
10 | use Wikimedia\Rdbms\IResultWrapper; |
11 | |
12 | /** |
13 | * This class is necessary so we can inject the name of |
14 | * a topic title into the category. Once we have pages |
15 | * in the topic namespace named after the topic themselves |
16 | * this can be simplified down to only pre-load the workflow |
17 | * and not the related posts. |
18 | */ |
19 | class CategoryViewerQuery { |
20 | /** |
21 | * @var PostRevision[] |
22 | */ |
23 | protected $posts = []; |
24 | |
25 | /** |
26 | * @var Workflow[] |
27 | */ |
28 | protected $workflows = []; |
29 | |
30 | /** |
31 | * @var ManagerGroup |
32 | */ |
33 | protected $storage; |
34 | |
35 | public function __construct( ManagerGroup $storage ) { |
36 | $this->storage = $storage; |
37 | } |
38 | |
39 | /** |
40 | * Accepts a result set as sent out to the CategoryViewer::doCategoryQuery |
41 | * hook. |
42 | * |
43 | * @param IResultWrapper|array $rows |
44 | */ |
45 | public function loadMetadataBatch( $rows ) { |
46 | $neededPosts = []; |
47 | $neededWorkflows = []; |
48 | foreach ( $rows as $row ) { |
49 | if ( $row->page_namespace != NS_TOPIC ) { |
50 | continue; |
51 | } |
52 | $uuid = UUID::create( strtolower( $row->page_title ) ); |
53 | if ( $uuid ) { |
54 | $alpha = $uuid->getAlphadecimal(); |
55 | $neededPosts[$alpha] = [ 'rev_type_id' => $uuid ]; |
56 | $neededWorkflows[$alpha] = $uuid; |
57 | } |
58 | } |
59 | |
60 | if ( !$neededPosts ) { |
61 | return; |
62 | } |
63 | $this->posts = $this->storage->findMulti( |
64 | 'PostRevision', |
65 | $neededPosts, |
66 | [ 'sort' => 'rev_id', 'order' => 'DESC', 'limit' => 1 ] |
67 | ); |
68 | $workflows = $this->storage->getMulti( |
69 | 'Workflow', |
70 | $neededWorkflows |
71 | ); |
72 | // @todo fixme: these should have come back with the apropriate array |
73 | // key since we passed it in above, but didn't. |
74 | foreach ( $workflows as $workflow ) { |
75 | $this->workflows[$workflow->getId()->getAlphadecimal()] = $workflow; |
76 | } |
77 | } |
78 | |
79 | public function getResult( UUID $uuid ) { |
80 | $alpha = $uuid->getAlphadecimal(); |
81 | |
82 | // Minimal set of data needed for the CategoryViewFormatter |
83 | $row = new FormatterRow; |
84 | if ( !isset( $this->posts[$alpha] ) ) { |
85 | throw new FlowException( "A required post has not been loaded: $alpha" ); |
86 | } |
87 | $row->revision = reset( $this->posts[$alpha] ); |
88 | if ( !isset( $this->workflows[$alpha] ) ) { |
89 | throw new FlowException( "A required workflow has not been loaded: $alpha" ); |
90 | } |
91 | $row->workflow = $this->workflows[$alpha]; |
92 | |
93 | return $row; |
94 | } |
95 | } |