]>
Commit | Line | Data |
---|---|---|
61d40693 A |
1 | <?php |
2 | ||
bdc5152d V |
3 | use Shaarli\History; |
4 | ||
61d40693 A |
5 | /** |
6 | * Populates a reference history | |
7 | */ | |
8 | class ReferenceHistory | |
9 | { | |
10 | private $count; | |
11 | ||
12 | private $history = []; | |
13 | ||
14 | /** | |
15 | * Populates the test DB with reference data | |
16 | */ | |
17 | public function __construct() | |
18 | { | |
19 | $this->addEntry( | |
6bc90f50 A |
20 | History::DELETED, |
21 | DateTime::createFromFormat('Ymd_His', '20170303_121216'), | |
22 | 124 | |
61d40693 A |
23 | ); |
24 | ||
25 | $this->addEntry( | |
6bc90f50 A |
26 | History::SETTINGS, |
27 | DateTime::createFromFormat('Ymd_His', '20170302_121215') | |
61d40693 A |
28 | ); |
29 | ||
30 | $this->addEntry( | |
31 | History::UPDATED, | |
32 | DateTime::createFromFormat('Ymd_His', '20170301_121214'), | |
33 | 123 | |
34 | ); | |
35 | ||
36 | $this->addEntry( | |
6bc90f50 A |
37 | History::CREATED, |
38 | DateTime::createFromFormat('Ymd_His', '20170201_121214'), | |
39 | 124 | |
61d40693 A |
40 | ); |
41 | ||
42 | $this->addEntry( | |
6bc90f50 A |
43 | History::CREATED, |
44 | DateTime::createFromFormat('Ymd_His', '20170101_121212'), | |
45 | 123 | |
61d40693 A |
46 | ); |
47 | } | |
48 | ||
49 | /** | |
50 | * Adds a new history entry | |
51 | * | |
52 | * @param string $event Event identifier | |
53 | * @param DateTime $datetime creation date | |
54 | * @param int $id optional: related link ID | |
55 | */ | |
56 | protected function addEntry($event, $datetime, $id = null) | |
57 | { | |
58 | $link = [ | |
59 | 'event' => $event, | |
60 | 'datetime' => $datetime, | |
61 | 'id' => $id, | |
62 | ]; | |
63 | $this->history[] = $link; | |
64 | $this->count++; | |
65 | } | |
66 | ||
67 | /** | |
68 | * Writes data to the datastore | |
69 | * | |
70 | * @param string $filename write history content to. | |
71 | */ | |
72 | public function write($filename) | |
73 | { | |
74 | FileUtils::writeFlatDB($filename, $this->history); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Returns the number of links in the reference data | |
79 | */ | |
80 | public function count() | |
81 | { | |
82 | return $this->count; | |
83 | } | |
84 | } |