1 | <?php |
||
12 | class DatabaseLogReader { |
||
13 | |||
14 | private static $titleCache = []; |
||
15 | private $query; |
||
16 | private $log; |
||
17 | private $dbr; |
||
18 | private $titleKey; |
||
19 | private $type; |
||
20 | |||
21 | /** |
||
22 | * @param DatabaseaBase $dbr injected connection |
||
23 | * @param string $titleKey from page name |
||
24 | * @param string $type of log (default: approval) |
||
25 | */ |
||
26 | public function __construct( DatabaseBase $dbr, $titleKey, $type = 'approval' ) { |
||
31 | |||
32 | /** |
||
33 | * Take care of loading from the cache or filling the query. |
||
34 | */ |
||
35 | private function init() { |
||
36 | if ( !$this->query ) { |
||
37 | if ( !isset( self::$titleCache[ $this->titleKey ] ) ) { |
||
38 | $this->query = DatabaseLogEntry::getSelectQueryData(); |
||
39 | |||
40 | $this->query['conds'] = [ |
||
41 | 'log_type' => $this->type, |
||
42 | 'log_title' => $this->titleKey |
||
43 | ]; |
||
44 | $this->query['options'] = [ 'ORDER BY' => 'log_timestamp desc' ]; |
||
45 | self::$titleCache[ $this->titleKey ] = $this; |
||
46 | } else { |
||
47 | $cache = self::$titleCache[ $this->titleKey ]; |
||
48 | $this->query = $cache->getQuery(); |
||
49 | $this->log = $cache->getLog(); |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Fetch the results using our conditions |
||
56 | * |
||
57 | * @return IResultWrapper |
||
58 | * @throws DBError |
||
59 | */ |
||
60 | private function getLog() { |
||
76 | |||
77 | /** |
||
78 | * Fetch the query parameters for later calls |
||
79 | * |
||
80 | * @return array of parameters for SELECT call |
||
81 | */ |
||
82 | public function getQuery() { |
||
85 | |||
86 | /** |
||
87 | * @return User |
||
88 | */ |
||
89 | public function getUserForLogEntry() { |
||
96 | |||
97 | /** |
||
98 | * @return Timestamp |
||
99 | */ |
||
100 | public function getDateOfLogEntry() { |
||
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getStatusOfLogEntry() { |
||
118 | } |
||
119 |