1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file DbInfo.php |
5
|
|
|
* @brief This file contains the DbInfo class. |
6
|
|
|
* @details |
7
|
|
|
* @author Filippo F. Fadda |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace EoC\Info; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use Meta\Extension; |
15
|
|
|
use ToolBag\Helper; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @brief This is an information only purpose class. It's used by Couch::getDbInfo() method. |
20
|
|
|
* @details Since this class uses the `TProperty` trait, you don't need to call the getter methods to obtain information |
21
|
|
|
* about database. |
22
|
|
|
* @nosubgrouping |
23
|
|
|
* |
24
|
|
|
* @cond HIDDEN_SYMBOLS |
25
|
|
|
* |
26
|
|
|
* @property string $name |
27
|
|
|
* @property int $diskSize |
28
|
|
|
* @property int $dataSize |
29
|
|
|
* @property string $diskFormatVersion |
30
|
|
|
* @property int $instanceStartTime |
31
|
|
|
* @property int $docCount |
32
|
|
|
* @property int $docDelCount |
33
|
|
|
* @property int $updateSeq |
34
|
|
|
* @property int $purgeSeq |
35
|
|
|
* @property bool $compactRunning |
36
|
|
|
* @property int $committedUpdateSeq |
37
|
|
|
* |
38
|
|
|
* @endcond |
39
|
|
|
*/ |
40
|
|
|
class DbInfo { |
41
|
|
|
use Extension\TProperty; |
42
|
|
|
|
43
|
|
|
/** @name Properties */ |
44
|
|
|
//!@{ |
|
|
|
|
45
|
|
|
|
46
|
|
|
//! Returns the database name. |
47
|
|
|
private $name; |
48
|
|
|
|
49
|
|
|
//! Gets the current size in Bytes of the database. Note: size of views indexes on disk are not included. |
50
|
|
|
private $diskSize; |
51
|
|
|
|
52
|
|
|
//! Returns the current size in Bytes of the database documents. Deleted documents or revision are not counted. |
53
|
|
|
private $dataSize; |
54
|
|
|
|
55
|
|
|
//! Gets the current version of the internal database format on disk. |
56
|
|
|
private $diskFormatVersion; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @brief Returns the timestamp of the last time the database file was opened. |
60
|
|
|
* @details This is used during the replication. When BiCouch is used this value is 0. |
61
|
|
|
*/ |
62
|
|
|
private $instanceStartTime; |
63
|
|
|
|
64
|
|
|
//! Returns the number of documents (including design documents) in the database. |
65
|
|
|
private $docCount; |
66
|
|
|
|
67
|
|
|
//! Returns the number of deleted documents (including design documents) in the database. |
68
|
|
|
private $docDelCount; |
69
|
|
|
|
70
|
|
|
//! Returns the current number of updates to the database. |
71
|
|
|
private $updateSeq; |
72
|
|
|
|
73
|
|
|
//! Returns the number of purge operations. |
74
|
|
|
private $purgeSeq; |
75
|
|
|
|
76
|
|
|
//! Indicates if a compaction is running. |
77
|
|
|
private $compactRunning; |
78
|
|
|
|
79
|
|
|
//! Returns of committed updates number. |
80
|
|
|
private $committedUpdateSeq; |
81
|
|
|
|
82
|
|
|
//!@} |
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @brief Creates an instance based on the provided JSON array. |
87
|
|
|
*/ |
88
|
|
|
public function __construct(array $info) { |
89
|
|
|
if (Helper\ArrayHelper::isAssociative($info)) { |
90
|
|
|
$this->name = $info['db_name']; |
91
|
|
|
$this->diskSize = $info['disk_size']; |
92
|
|
|
$this->dataSize = $info['data_size']; |
93
|
|
|
$this->diskFormatVersion = $info['disk_format_version']; |
94
|
|
|
$this->instanceStartTime = $info['instance_start_time']; |
95
|
|
|
$this->docCount = $info['doc_count']; |
96
|
|
|
$this->docDelCount = $info['doc_del_count']; |
97
|
|
|
$this->updateSeq = $info['update_seq']; |
98
|
|
|
$this->purgeSeq = $info['purge_seq']; |
99
|
|
|
$this->compactRunning = $info['compact_running']; |
100
|
|
|
$this->committedUpdateSeq = $info['committed_update_seq']; |
101
|
|
|
} |
102
|
|
|
else |
103
|
|
|
throw new \Exception("\$info must be an associative array."); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @brief Overrides the magic method to convert the object to a string. |
109
|
|
|
*/ |
110
|
|
|
public function __toString() { |
111
|
|
|
$buffer = "Name: ".$this->name.PHP_EOL; |
112
|
|
|
|
113
|
|
|
if ((float)$this->instanceStartTime > 0) { |
114
|
|
|
$time = Helper\TimeHelper::since($this->instanceStartTime, TRUE); |
|
|
|
|
115
|
|
|
$since = '%d days, %d hours, %d minutes, %d seconds'; |
116
|
|
|
$buffer .= "File Opened Since: ".sprintf($since, $time['days'], $time['hours'], $time['minutes'], $time['seconds']).PHP_EOL; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$buffer .= "Disk Size: ".round($this->diskSize/(1024*1024*1024), 3)." GB".PHP_EOL; |
120
|
|
|
$buffer .= "Data Size: ".round($this->dataSize/(1024*1024*1024), 3)." GB".PHP_EOL; |
121
|
|
|
$buffer .= "Disk Format Version: ".$this->diskFormatVersion.PHP_EOL; |
122
|
|
|
|
123
|
|
|
$compactRunning = ($this->compactRunning) ? 'active' : 'inactive'; |
124
|
|
|
$buffer .= "Compaction: ".$compactRunning.PHP_EOL; |
125
|
|
|
|
126
|
|
|
$buffer .= "Number of Documents: ".$this->docCount.PHP_EOL; |
127
|
|
|
$buffer .= "Number of Deleted Documents: ".$this->docDelCount.PHP_EOL; |
128
|
|
|
$buffer .= "Number of Updates: ".$this->updateSeq.PHP_EOL; |
129
|
|
|
$buffer .= "Number of Purge Operations: ".$this->purgeSeq.PHP_EOL; |
130
|
|
|
$buffer .= "Number of Committed Updates: ".$this->committedUpdateSeq.PHP_EOL; |
131
|
|
|
|
132
|
|
|
return $buffer; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
//! @cond HIDDEN_SYMBOLS |
137
|
|
|
|
138
|
|
|
public function getName() { |
139
|
|
|
return $this->name; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
public function getDiskSize() { |
144
|
|
|
return $this->diskSize; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
public function getDataSize() { |
149
|
|
|
return $this->dataSize; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
public function getDiskFormatVersion() { |
154
|
|
|
return $this->diskFormatVersion; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function getInstanceStartTime() { |
159
|
|
|
return $this->instanceStartTime; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
public function getDocCount() { |
164
|
|
|
return $this->docCount; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function getDocDelCount() { |
169
|
|
|
return $this->docDelCount; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function getUpdateSeq() { |
174
|
|
|
return $this->updateSeq; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
public function getPurgeSeq() { |
179
|
|
|
return $this->purgeSeq; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
public function getCompactRunning() { |
184
|
|
|
return $this->compactRunning; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
public function getCommittedUpdateSequence() { |
189
|
|
|
return $this->committedUpdateSeq; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
//! @endcond |
|
|
|
|
193
|
|
|
|
194
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.