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