Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
TopicListEntry | |
0.00% |
0 / 27 |
|
0.00% |
0 / 6 |
110 | |
0.00% |
0 / 1 |
create | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
fromStorageRow | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
toStorageRow | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getListId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTopicWorkflowLastUpdated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Flow\Model; |
4 | |
5 | use Flow\Exception\DataModelException; |
6 | use MediaWiki\MediaWikiServices; |
7 | |
8 | // TODO: We shouldn't need this class |
9 | class TopicListEntry { |
10 | |
11 | /** |
12 | * @var UUID |
13 | */ |
14 | protected $topicListId; |
15 | |
16 | /** |
17 | * @var UUID |
18 | */ |
19 | protected $topicId; |
20 | |
21 | /** |
22 | * @var string|null |
23 | */ |
24 | protected $topicWorkflowLastUpdated; |
25 | |
26 | /** |
27 | * @param Workflow $topicList |
28 | * @param Workflow $topic |
29 | * @return TopicListEntry |
30 | */ |
31 | public static function create( Workflow $topicList, Workflow $topic ) { |
32 | $obj = new self; |
33 | $obj->topicListId = $topicList->getId(); |
34 | $obj->topicId = $topic->getId(); |
35 | $obj->topicWorkflowLastUpdated = $topic->getLastUpdated(); |
36 | return $obj; |
37 | } |
38 | |
39 | /** |
40 | * @param array $row |
41 | * @param TopicListEntry|null $obj |
42 | * @return TopicListEntry |
43 | * @throws DataModelException |
44 | */ |
45 | public static function fromStorageRow( array $row, $obj = null ) { |
46 | if ( $obj === null ) { |
47 | $obj = new self; |
48 | } elseif ( !$obj instanceof self ) { |
49 | throw new DataModelException( 'Wrong obj type: ' . get_class( $obj ), 'process-data' ); |
50 | } |
51 | $obj->topicListId = UUID::create( $row['topic_list_id'] ); |
52 | $obj->topicId = UUID::create( $row['topic_id'] ); |
53 | if ( isset( $row['workflow_last_update_timestamp'] ) ) { |
54 | $obj->topicWorkflowLastUpdated = wfTimestamp( TS_MW, $row['workflow_last_update_timestamp'] ); |
55 | } |
56 | return $obj; |
57 | } |
58 | |
59 | /** |
60 | * @param TopicListEntry $obj |
61 | * @return array |
62 | */ |
63 | public static function toStorageRow( TopicListEntry $obj ) { |
64 | $row = [ |
65 | 'topic_list_id' => $obj->topicListId->getAlphadecimal(), |
66 | 'topic_id' => $obj->topicId->getAlphadecimal(), |
67 | ]; |
68 | if ( $obj->topicWorkflowLastUpdated ) { |
69 | $dbr = MediaWikiServices::getInstance() |
70 | ->getDBLoadBalancer() |
71 | ->getConnection( DB_REPLICA ); |
72 | $row['workflow_last_update_timestamp'] = $dbr->timestamp( $obj->topicWorkflowLastUpdated ); |
73 | } |
74 | return $row; |
75 | } |
76 | |
77 | /** |
78 | * @return UUID |
79 | */ |
80 | public function getId() { |
81 | return $this->topicId; |
82 | } |
83 | |
84 | /** |
85 | * @return UUID |
86 | */ |
87 | public function getListId() { |
88 | return $this->topicListId; |
89 | } |
90 | |
91 | /** |
92 | * @return string|null |
93 | */ |
94 | public function getTopicWorkflowLastUpdated() { |
95 | return $this->topicWorkflowLastUpdated; |
96 | } |
97 | } |