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