2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-25 09:55:38 +00:00

configDB: add raw output for configdb info version info

git-svn-id: https://svn.fhem.de/fhem/trunk@26802 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2022-12-06 18:01:22 +00:00
parent 6df68a80ed
commit 1e27f15e2f
2 changed files with 16 additions and 11 deletions

View File

@ -177,8 +177,9 @@ sub CommandConfigdb {
}
when ('info') {
my $raw = lc($param1) eq 'raw' ? 1 : 0;
Log3('configdb', 4, "info requested.");
$ret = _cfgDB_Info('$Id$');
$ret = _cfgDB_Info('$Id$',$raw);
}
when ('list') {
@ -530,8 +531,9 @@ compare device: telnetPort in current version 0 (left) to version: 1 (right)
<br/>
<br/>
<li><code>configdb info</code></li><br/>
<li><code>configdb info [raw]</code></li><br/>
Returns some database statistics<br/>
if optional "raw" selected, version infos will be returned as json"<br/>
<pre>
--------------------------------------------------------------------------------
configDB Database Information

View File

@ -180,6 +180,8 @@
# 2022-08-06 - added attribute shortinfo for use with configdb info
# 2022-08-07 - added log a message if more than 20 versions stored
#
# 2022-12-06 - added add raw json output in configdb info
#
##############################################################################
=cut
@ -913,8 +915,9 @@ sub _cfgDB_Migrate {
# show database statistics
sub _cfgDB_Info {
my ($info2) = @_;
my ($info2,$raw) = @_;
$info2 //= 'unknown';
$raw //= 0;
my ($l, @r, $f);
for my $i (1..65){ $l .= '-';}
@ -942,7 +945,7 @@ sub _cfgDB_Info {
push @r, $l;
push @r, " loaded: ".$configDB{loaded};
my $fhem_dbh = _cfgDB_Connect;
my ($sql, $sth, @line, $row);
my ($sql, $sth, @line, $row, $countDef, $countAttr, @raw);
# read versions table statistics
@ -963,13 +966,13 @@ sub _cfgDB_Info {
$sth = $fhem_dbh->prepare( $sql );
$sth->execute();
while (@line = $sth->fetchrow_array()) {
$line[3] = "" unless defined $line[3];
$row = " Ver $line[6] saved: $line[1] $line[2] $line[3] def: ".
$fhem_dbh->selectrow_array("SELECT COUNT(*) from fhemconfig where COMMAND = 'define' and VERSIONUUID = '$line[5]'");
$row .= " attr: ".
$fhem_dbh->selectrow_array("SELECT COUNT(*) from fhemconfig where COMMAND = 'attr' and VERSIONUUID = '$line[5]'");
$row .= " tag: ".$line[8] if $line[8];
$line[3] = "" unless defined $line[3];
$countDef = $fhem_dbh->selectrow_array("SELECT COUNT(*) from fhemconfig where COMMAND = 'define' and VERSIONUUID = '$line[5]'");
$countAttr = $fhem_dbh->selectrow_array("SELECT COUNT(*) from fhemconfig where COMMAND = 'attr' and VERSIONUUID = '$line[5]'");
$row = " Ver $line[6] saved: $line[1] $line[2] $line[3] def: $countDef attr: $countAttr";
$row .= " tag: ".$line[8] if $line[8];
push @r, $row;
push @raw, {version => $line[6], saved => "$line[1] $line[2] $line[3]", def => $countDef, attr => $countAttr};
}
} else {
my $count;
@ -987,9 +990,9 @@ sub _cfgDB_Info {
$row = " filesave: $count file$f stored in database";
push @r, $row;
push @r, $l;
$fhem_dbh->disconnect();
return toJSON \@raw if $raw;
return join("\n", @r);
}