Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
ImportTopic | |
0.00% |
0 / 25 |
|
0.00% |
0 / 12 |
240 | |
0.00% |
0 / 1 |
getText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAuthor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRevisions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getReplies | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getTimestamp | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTopicSummary | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getSummaryId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getObjectKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLogType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLogParameters | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getLqtThreadId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isRedirectToFlow | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Flow\Import\LiquidThreadsApi; |
4 | |
5 | use ArrayIterator; |
6 | use Flow\Import\IImportSummary; |
7 | use Flow\Import\IImportTopic; |
8 | use Flow\Import\IObjectRevision; |
9 | use MediaWiki\MediaWikiServices; |
10 | |
11 | /** |
12 | * This is a bit of a weird model, acting as a revision of itself. |
13 | */ |
14 | class ImportTopic extends ImportPost implements IImportTopic, IObjectRevision { |
15 | /** |
16 | * @return string |
17 | */ |
18 | public function getText() { |
19 | return $this->apiResponse['subject']; |
20 | } |
21 | |
22 | public function getAuthor() { |
23 | return $this->apiResponse['author']['name']; |
24 | } |
25 | |
26 | public function getRevisions() { |
27 | // we only have access to a single revision of the topic |
28 | return new ArrayIterator( [ $this ] ); |
29 | } |
30 | |
31 | public function getReplies() { |
32 | $topPost = new ImportPost( $this->importSource, $this->apiResponse ); |
33 | |
34 | return new ArrayIterator( [ $topPost ] ); |
35 | } |
36 | |
37 | public function getTimestamp() { |
38 | return wfTimestamp( TS_MW, $this->apiResponse['created'] ); |
39 | } |
40 | |
41 | /** |
42 | * @return IImportSummary|null |
43 | */ |
44 | public function getTopicSummary() { |
45 | $id = $this->getSummaryId(); |
46 | if ( $id > 0 ) { |
47 | $data = $this->importSource->getPageData( $id ); |
48 | if ( isset( $data['revisions'][0] ) ) { |
49 | return new ImportSummary( $data, $this->importSource ); |
50 | } else { |
51 | return null; |
52 | } |
53 | } else { |
54 | return null; |
55 | } |
56 | } |
57 | |
58 | /** |
59 | * @return int |
60 | */ |
61 | protected function getSummaryId() { |
62 | return $this->apiResponse['summaryid']; |
63 | } |
64 | |
65 | /** |
66 | * This needs to have a different value than the same apiResponse in an ImportPost. |
67 | * The ImportPost version refers to the first response to the topic. |
68 | * @return string |
69 | */ |
70 | public function getObjectKey() { |
71 | return 'topic' . $this->importSource->getObjectKey( 'thread_id', $this->apiResponse['id'] ); |
72 | } |
73 | |
74 | public function getLogType() { |
75 | return "lqt-to-flow-topic"; |
76 | } |
77 | |
78 | public function getLogParameters() { |
79 | return [ |
80 | 'lqt_thread_id' => $this->apiResponse['id'], |
81 | 'lqt_orig_title' => $this->getTitle()->getPrefixedText(), |
82 | 'lqt_subject' => $this->getText(), |
83 | ]; |
84 | } |
85 | |
86 | public function getLqtThreadId() { |
87 | return $this->apiResponse['id']; |
88 | } |
89 | |
90 | public function isRedirectToFlow(): bool { |
91 | $lookup = MediaWikiServices::getInstance()->getRedirectLookup(); |
92 | $redirectTarget = $lookup->getRedirectTarget( $this->getTitle() ); |
93 | return $redirectTarget && $redirectTarget->inNamespace( NS_TOPIC ); |
94 | } |
95 | } |