Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
TopicImportState
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 getMetadata
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 recordUpdateTime
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 commitLastUpdated
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Flow\Import;
4
5use Flow\Model\PostRevision;
6use Flow\Model\UUID;
7use Flow\Model\Workflow;
8use ReflectionProperty;
9
10class TopicImportState {
11    /**
12     * @var PageImportState
13     */
14    public $parent;
15
16    /**
17     * @var Workflow
18     */
19    public $topicWorkflow;
20
21    /**
22     * @var PostRevision
23     */
24    public $topicTitle;
25
26    /**
27     * @var string
28     */
29    protected $lastUpdated;
30
31    /**
32     * @var ReflectionProperty
33     */
34    private $workflowUpdatedProperty;
35
36    public function __construct( PageImportState $parent, Workflow $topicWorkflow, PostRevision $topicTitle ) {
37        $this->parent = $parent;
38        $this->topicWorkflow = $topicWorkflow;
39        $this->topicTitle = $topicTitle;
40
41        $this->workflowUpdatedProperty = new ReflectionProperty( Workflow::class, 'lastUpdated' );
42        $this->workflowUpdatedProperty->setAccessible( true );
43
44        $this->lastUpdated = '';
45        $this->recordUpdateTime( $topicWorkflow->getId() );
46    }
47
48    public function getMetadata() {
49        return [
50            'workflow' => $this->topicWorkflow,
51            'board-workflow' => $this->parent->boardWorkflow,
52            'topic-title' => $this->topicTitle,
53        ];
54    }
55
56    /**
57     * Notify the state about a modification action at a given time.
58     *
59     * @param UUID $uuid UUID of the modification revision.
60     */
61    public function recordUpdateTime( UUID $uuid ) {
62        $timestamp = $uuid->getTimestamp();
63        $timestamp = wfTimestamp( TS_MW, $timestamp );
64
65        if ( $timestamp > $this->lastUpdated ) {
66            $this->lastUpdated = $timestamp;
67        }
68    }
69
70    /**
71     * Saves the last updated timestamp based on calls to recordUpdateTime
72     * XXX: Kind of icky; reaching through the parent and doing a second put().
73     */
74    public function commitLastUpdated() {
75        $this->workflowUpdatedProperty->setValue(
76            $this->topicWorkflow,
77            $this->lastUpdated
78        );
79
80        $this->parent->put( $this->topicWorkflow, $this->getMetadata() );
81    }
82}