mirror of
https://github.com/fhem/fhem-mirror.git
synced 2024-11-22 09:49:50 +00:00
configDB - added: wrapper module 98_configDB.pm
to provide set/get/attr compatibility git-svn-id: https://svn.fhem.de/fhem/trunk@5162 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
f3cf5ee90f
commit
99f114e739
@ -1,6 +1,7 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
# Do not insert empty lines here, update check depends on it.
|
||||
- SVN
|
||||
- feature: added wrapper module 98_configDB (betateilchen)
|
||||
- feature: new module 70_PHTV.pm (loredo)
|
||||
- feature: JSONMETER: added statistic functions
|
||||
- feature: LightScene: added scene editor from UliM
|
||||
|
85
fhem/FHEM/98_configDB.pm
Normal file
85
fhem/FHEM/98_configDB.pm
Normal file
@ -0,0 +1,85 @@
|
||||
# $Id$
|
||||
# Wrapper module for configDB
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use feature qw/say switch/;
|
||||
|
||||
sub configDB_Initialize($) {
|
||||
my ($hash) = @_;
|
||||
$hash->{DefFn} = "configDB_Define";
|
||||
$hash->{SetFn} = "configDB_Set";
|
||||
$hash->{GetFn} = "configDB_Get";
|
||||
$hash->{AttrList} = "private:1,0 ";
|
||||
}
|
||||
|
||||
sub configDB_Define($$) {
|
||||
return "configDB not enabled!" unless $attr{global}{configfile} eq 'configDB';
|
||||
my ($hash, $def) = @_;
|
||||
my @a = split("[ \t][ \t]*", $def);
|
||||
return "Wrong syntax: use define <name> configDB" if(int(@a) != 2);
|
||||
readingsSingleUpdate($hash, 'state', 'active', 0);
|
||||
readingsSingleUpdate($hash, 'version', cfgDB_svnId, 0);
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub configDB_Set($@) {
|
||||
my ($hash, @a) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $usage = "Unknown argument, choose one of reorg recover";
|
||||
return $usage if(int(@a) < 2);
|
||||
my $ret;
|
||||
|
||||
given ($a[1]) {
|
||||
|
||||
when ('reorg') {
|
||||
$a[2] = $a[2] ? $a[2] : 3;
|
||||
$ret = cfgDB_Reorg($a[2]);
|
||||
}
|
||||
|
||||
when ('recover') {
|
||||
$a[2] = $a[2] ? $a[2] : 3;
|
||||
$ret = cfgDB_Recover($a[2]);
|
||||
}
|
||||
|
||||
default { $ret = $usage; }
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
sub configDB_Get($@) {
|
||||
|
||||
my ($hash, @a) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $usage = "Unknown argument, choose one of diff info:noArg list";
|
||||
return $usage if(int(@a) < 2);
|
||||
my $ret;
|
||||
|
||||
given ($a[1]) {
|
||||
|
||||
when ('info') {
|
||||
$ret = cfgDB_Info;
|
||||
}
|
||||
|
||||
when ('list') {
|
||||
$a[2] = $a[2] ? $a[2] : '%';
|
||||
$a[3] = $a[3] ? $a[3] : 0;
|
||||
$ret = cfgDB_List($a[2],$a[3]);
|
||||
}
|
||||
|
||||
when ('diff') {
|
||||
$ret = cfgDB_Diff($a[2],$a[3]);
|
||||
}
|
||||
|
||||
default { $ret = $usage; }
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
1;
|
@ -551,3 +551,6 @@
|
||||
|
||||
- Wed Feb 25 2014 (andreas-fey)
|
||||
- Update on pilight module for more protocols
|
||||
|
||||
- Fri Mar 07 2014 (betateilchen)
|
||||
- First officiel release of configDB via update process
|
||||
|
@ -207,6 +207,7 @@ FHEM/98_autocreate.pm rudolfkoenig http://forum.fhem.de Automatis
|
||||
FHEM/98_average.pm rudolfkoenig http://forum.fhem.de Automatisierung
|
||||
FHEM/98_backup.pm mfr69bs http://forum.fhem.de Sonstiges
|
||||
FHEM/98_cmdalias.pm rudolfkoenig http://forum.fhem.de Automatisierung
|
||||
FHEM/98_configDB.pm betateilchen http://forum.fhem.de Sonstiges
|
||||
FHEM/98_dewpoint.pm wherzig http://forum.fhem.de Automatisierung
|
||||
FHEM/98_dummy.pm rudolfkoenig http://forum.fhem.de Automatisierung
|
||||
FHEM/98_fheminfo.pm mfr69bs http://forum.fhem.de Sonstiges
|
||||
|
@ -58,6 +58,7 @@ use DBI;
|
||||
# Forward declarations for functions in fhem.pl
|
||||
#
|
||||
sub AnalyzeCommandChain($$;$);
|
||||
sub AttrVal($$$);
|
||||
sub Debug($);
|
||||
sub Log3($$$);
|
||||
|
||||
@ -387,10 +388,6 @@ sub _cfgDB_Rotate($) {
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
##################################################
|
||||
# Tools / additional functions
|
||||
#
|
||||
|
||||
# return a UUID based on DB-model
|
||||
sub _cfgDB_Uuid{
|
||||
my $fhem_dbh = _cfgDB_Connect;
|
||||
@ -402,6 +399,11 @@ sub _cfgDB_Uuid{
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
##################################################
|
||||
# Tools / Additional functions
|
||||
# not called from fhem.pl directly
|
||||
#
|
||||
|
||||
# migrate existing fhem config into database
|
||||
sub cfgDB_Migrate {
|
||||
Log3('configDB',4,'Starting migration.');
|
||||
@ -418,30 +420,31 @@ sub cfgDB_Migrate {
|
||||
|
||||
# show database statistics
|
||||
sub cfgDB_Info {
|
||||
my $l = '--------------------';
|
||||
$l .= $l;
|
||||
$l .= $l;
|
||||
$l .= "\n";
|
||||
my $r = $l;
|
||||
$r .= " configDB Database Information\n";
|
||||
$r .= $l;
|
||||
$r .= " dbconn: $cfgDB_dbconn\n";
|
||||
$r .= " dbuser: $cfgDB_dbuser\n";
|
||||
$r .= " dbpass: $cfgDB_dbpass\n";
|
||||
$r .= " dbtype: $cfgDB_dbtype\n";
|
||||
$r .= " Unknown dbmodel type in configuration file.\n" if $dbtype eq 'unknown';
|
||||
$r .= " Only Mysql, Postgresql, SQLite are fully supported.\n" if $dbtype eq 'unknown';
|
||||
$r .= $l;
|
||||
my ($l, @r);
|
||||
for my $i (1..65){ $l .= '-';}
|
||||
# $l .= "\n";
|
||||
push @r, $l;
|
||||
push @r, " configDB Database Information";
|
||||
push @r, $l;
|
||||
push @r, " ".cfgDB_svnId;
|
||||
push @r, $l;
|
||||
push @r, " dbconn: $cfgDB_dbconn";
|
||||
push @r, " dbuser: $cfgDB_dbuser" if !$attr{configDB}{private};
|
||||
push @r, " dbpass: $cfgDB_dbpass" if !$attr{configDB}{private};
|
||||
push @r, " dbtype: $cfgDB_dbtype";
|
||||
push @r, " Unknown dbmodel type in configuration file." if $dbtype eq 'unknown';
|
||||
push @r, " Only Mysql, Postgresql, SQLite are fully supported." if $dbtype eq 'unknown';
|
||||
push @r, $l;
|
||||
|
||||
my $fhem_dbh = _cfgDB_Connect;
|
||||
my ($sql, $sth, @line, $row);
|
||||
|
||||
# read versions table statistics
|
||||
# read versions table statistics
|
||||
my $count;
|
||||
$count = $fhem_dbh->selectrow_array('SELECT count(*) FROM fhemconfig');
|
||||
$r .= " fhemconfig: $count entries\n\n";
|
||||
push @r, " fhemconfig: $count entries\n";
|
||||
|
||||
# read versions creation time
|
||||
# read versions creation time
|
||||
$sql = "SELECT * FROM fhemconfig as c join fhemversions as v on v.versionuuid=c.versionuuid ".
|
||||
"WHERE COMMAND like '#created%' ORDER by v.VERSION";
|
||||
$sth = $fhem_dbh->prepare( $sql );
|
||||
@ -451,25 +454,25 @@ sub cfgDB_Info {
|
||||
$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]'");
|
||||
$r .= "$row\n";
|
||||
push @r, $row;
|
||||
}
|
||||
$r .= $l;
|
||||
push @r, $l;
|
||||
|
||||
# read state table statistics
|
||||
# read state table statistics
|
||||
$count = $fhem_dbh->selectrow_array('SELECT count(*) FROM fhemstate');
|
||||
$r .= " fhemstate: $count entries saved: ";
|
||||
# read state table creation time
|
||||
# read state table creation time
|
||||
$sth = $fhem_dbh->prepare( "SELECT * FROM fhemstate WHERE STATESTRING like '#%'" );
|
||||
$sth->execute();
|
||||
while ($row = $sth->fetchrow_array()) {
|
||||
(undef,$row) = split(/#/,$row);
|
||||
$r .= "$row\n";
|
||||
$row = " fhemstate: $count entries saved: $row";
|
||||
push @r, $row;
|
||||
}
|
||||
$r .= $l;
|
||||
push @r, $l;
|
||||
|
||||
$fhem_dbh->disconnect();
|
||||
|
||||
return $r;
|
||||
return join("\n", @r);
|
||||
}
|
||||
|
||||
# recover former config from database archive
|
||||
@ -550,7 +553,7 @@ sub cfgDB_List(;$$) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
# used from cfgDB_Diff
|
||||
# called from cfgDB_Diff
|
||||
sub _cfgDB_Diff($$$) {
|
||||
my ($fhem_dbh,$search,$searchversion) = @_;
|
||||
my ($sql, $sth, @line, $ret);
|
||||
|
Loading…
Reference in New Issue
Block a user