Skip to content

Commit 107209a

Browse files
committed
Show database size in system_database.php status panel.
1 parent bb3c029 commit 107209a

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

lib/Database.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,4 +952,25 @@ public function setDataFields($tablename, $id, $values)
952952

953953
$this->execute($query, $values);
954954
}
955+
956+
public function getDatabaseSize()
957+
{
958+
global $config;
959+
960+
if ($config['db']['type'] != "mysql") {
961+
throw new \Exception(_("Datenbankgröße kann nur für MySQL Datenbanken ermittelt werden!"));
962+
}
963+
964+
$query = 'SELECT '
965+
. ' ROUND(SUM(data_length + index_length) / 1024 / 1024, 3) AS `size`'
966+
. ' FROM information_schema.TABLES'
967+
. ' WHERE table_schema = "part-db"'
968+
. ' GROUP BY table_schema; ';
969+
970+
$values[] = $config['db']['name'];
971+
972+
$data = $this->query($query, $values);
973+
974+
return (float) $data[0]["size"];
975+
}
955976
}

system_database.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@
209209
}
210210
}
211211

212+
if(!$fatal_error) {
213+
try {
214+
$size = $database->getDatabaseSize();
215+
$html->setVariable("db_size", $size);
216+
} catch (Exception $e) {
217+
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red', );
218+
}
219+
}
220+
212221
try {
213222
$html->setVariable('hide_status', $fatal_error, 'boolean');
214223
if (isset($current_user) && is_object($current_user)) {

templates/nextgen/system_database.php/smarty_system_database.tpl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616

1717
<form action="" method="post" class="form-horizontal no-progbar">
18-
<table class="table">
18+
<table class="table table-sm">
1919
<thead>
2020
<tr>
2121
<th>{t}Eigenschaft{/t}</th>
@@ -40,6 +40,13 @@
4040
{$latest_version}
4141
</td>
4242
</tr>
43+
44+
{if isset($db_size)}
45+
<tr>
46+
<td>{t}Datenbank Größe{/t}</td>
47+
<td>{$db_size} MB</td>
48+
</tr>
49+
{/if}
4350
</tbody>
4451
</table>
4552

0 commit comments

Comments
 (0)