mirror of
https://github.com/fhem/fhem-mirror.git
synced 2024-11-22 09:49:50 +00:00
configdb - added: automatic fileimport to migration
git-svn-id: https://svn.fhem.de/fhem/trunk@6441 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
0ae57aaa98
commit
4d5b39114f
@ -223,12 +223,14 @@ sub CommandConfigdb($$) {
|
||||
Currently the fhem modules<br/>
|
||||
<br/>
|
||||
<li>02_RSS.pm</li>
|
||||
<li>91_eventTypes</li>
|
||||
<li>93_DbLog.pm</li>
|
||||
<li>95_holiday.pm</li>
|
||||
<li>98_SVG.pm</li>
|
||||
<br/>
|
||||
will use configDB to read their configuration data from database<br/>
|
||||
instead of formerly used configuration files inside the filesystem.<br/>
|
||||
<br/>
|
||||
This requires you to import your configuration files from filesystem into database.<br/>
|
||||
<br/>
|
||||
Example:<br/>
|
||||
@ -237,7 +239,9 @@ sub CommandConfigdb($$) {
|
||||
<code>configdb fileimport www/gplot/xyz.gplot</code><br/>
|
||||
<br/>
|
||||
<b>This does not affect the definitons of your holiday or RSS entities.</b><br/>
|
||||
The given filenames in the definitions will be translated automatically to find the correct entries inside the database.<br/>
|
||||
<br/>
|
||||
<b>During migration all external configfiles used in current configuration<br/>
|
||||
will be imported aufmatically.</b><br>
|
||||
<br/>
|
||||
Each fileimport into database will overwrite the file if it already exists in database.<br/>
|
||||
<br/>
|
||||
@ -537,6 +541,7 @@ attr Melder_FAr peerIDs 00000000,2286BC03,
|
||||
Momentan verwenden die Module<br/>
|
||||
<br/>
|
||||
<li>02_RSS.pm</li>
|
||||
<li>91_eventTypes</li>
|
||||
<li>93_DbLog.pm</li>
|
||||
<li>95_holiday.pm</li>
|
||||
<li>98_SVG.pm</li>
|
||||
@ -551,7 +556,9 @@ attr Melder_FAr peerIDs 00000000,2286BC03,
|
||||
<code>configdb fileimport www/gplot/xyz.gplot</code><br/>
|
||||
<br/>
|
||||
<b>Dies hat keinerlei Auswirkungen auf die Definition der holiday oder RSS Instanzen.</b><br/>
|
||||
Die dort verwendeten Dateinamen werden automtisch umgesetzt, um die zugehörigen Daten in der Datenbank zu finden.<br/>
|
||||
<br>
|
||||
<b>Während einer Migration werden alle in der aktuell bestehenden Konfiguration verwendeten externen<br/>
|
||||
Konfigurationsdateien automatisch in die Datenbank importiert.</b></br>
|
||||
<br/>
|
||||
Jeder Neuimport einer bereits in der Datenbank gespeicherten Datei überschreibt die vorherige Datei in der Datenbank.<br/>
|
||||
<br/>
|
||||
|
107
fhem/configDB.pm
107
fhem/configDB.pm
@ -84,6 +84,8 @@
|
||||
# 2014-05-20 - removed no longer needed functions for file handling
|
||||
# changed code improvement; use strict; use warnings;
|
||||
#
|
||||
# 2014-08-22 - added automatic fileimport during migration
|
||||
#
|
||||
##############################################################################
|
||||
#
|
||||
|
||||
@ -450,6 +452,74 @@ sub cfgDB_SaveState() {
|
||||
return;
|
||||
}
|
||||
|
||||
# import existing files during migration
|
||||
sub cfgDB_MigrationImport() {
|
||||
|
||||
my ($ret, $filename, @files, @def);
|
||||
|
||||
# find eventTypes file
|
||||
$filename = '';
|
||||
@def = '';
|
||||
@def = _cfgDB_findDef('TYPE=eventTypes');
|
||||
foreach $filename (@def) {
|
||||
next unless $filename;
|
||||
push @files, $filename;
|
||||
}
|
||||
|
||||
# import templateDB.gplot
|
||||
$filename = $attr{global}{modpath};
|
||||
$filename .= "/www/gplot/templateDB.gplot";
|
||||
push @files, $filename;
|
||||
|
||||
# find used gplot files
|
||||
$filename ='';
|
||||
@def = '';
|
||||
@def = _cfgDB_findDef('TYPE=SVG','GPLOTFILE');
|
||||
foreach $filename (@def) {
|
||||
next unless $filename;
|
||||
push @files, "./www/gplot/".$filename.".gplot";
|
||||
}
|
||||
|
||||
# find DbLog configs
|
||||
$filename ='';
|
||||
@def = '';
|
||||
@def = _cfgDB_findDef('TYPE=DbLog','CONFIGURATION');
|
||||
foreach $filename (@def) {
|
||||
next unless $filename;
|
||||
push @files, $filename;
|
||||
}
|
||||
|
||||
# find RSS layouts
|
||||
$filename ='';
|
||||
@def = '';
|
||||
@def = _cfgDB_findDef('TYPE=RSS','LAYOUTFILE');
|
||||
foreach $filename (@def) {
|
||||
next unless $filename;
|
||||
push @files, $filename;
|
||||
}
|
||||
|
||||
# find holiday files
|
||||
$filename ='';
|
||||
@def = '';
|
||||
@def = _cfgDB_findDef('TYPE=holiday','NAME');
|
||||
foreach $filename (@def) {
|
||||
next unless $filename;
|
||||
push @files, "./FHEM/".$filename.".holiday";
|
||||
}
|
||||
|
||||
# do the import
|
||||
$filename = '';
|
||||
foreach $filename (@files) {
|
||||
if ( -r $filename ) {
|
||||
my $filesize = -s $filename;
|
||||
_cfgDB_binFileimport($filename,$filesize);
|
||||
$ret .= "importing: $filename\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
# return SVN Id, called by fhem's CommandVersion
|
||||
sub cfgDB_svnId() {
|
||||
return "# ".'$Id$'
|
||||
@ -599,21 +669,23 @@ sub _cfgDB_Uuid() {
|
||||
sub _cfgDB_Migrate() {
|
||||
my $ret;
|
||||
$ret = "Starting migration...\n";
|
||||
Log3('configDB',4,'Starting migration.');
|
||||
$ret .= "Processing: database initialization.\n";
|
||||
Log3('configDB',4,'Processing: cfgDB_Init.');
|
||||
Log3('configDB',4,'Starting migration');
|
||||
$ret .= "Processing: database initialization\n";
|
||||
Log3('configDB',4,'Processing: cfgDB_Init');
|
||||
cfgDB_Init;
|
||||
$ret .= "Processing: save config.\n";
|
||||
Log3('configDB',4,'Processing: cfgDB_SaveCfg.');
|
||||
$ret .= "Processing: save config\n";
|
||||
Log3('configDB',4,'Processing: cfgDB_SaveCfg');
|
||||
cfgDB_SaveCfg;
|
||||
$ret .= "Processing: save state.\n";
|
||||
Log3('configDB',4,'Processing: cfgDB_SaveState.');
|
||||
$ret .= "Processing: save state\n";
|
||||
Log3('configDB',4,'Processing: cfgDB_SaveState');
|
||||
cfgDB_SaveState;
|
||||
$ret .= "Migration completed.\n\n";
|
||||
Log3('configDB',4,'Migration finished.');
|
||||
$ret .= "Processing: fileimport\n";
|
||||
Log3('configDB',4,'Processing: cfgDB_MigrationImport');
|
||||
$ret .= cfgDB_MigrationImport;
|
||||
$ret .= "Migration completed\n\n";
|
||||
Log3('configDB',4,'Migration completed.');
|
||||
$ret .= _cfgDB_Info;
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
# show database statistics
|
||||
@ -798,6 +870,21 @@ sub _cfgDB_Diff($$) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
# find DEF, input supports devspec definitions
|
||||
sub _cfgDB_findDef($;$) {
|
||||
my ($search,$internal) = @_;
|
||||
$internal = 'DEF' unless defined($internal);
|
||||
|
||||
my @ret;
|
||||
my @etDev = devspec2array($search);
|
||||
foreach my $d (@etDev) {
|
||||
next unless $d;
|
||||
push @ret, $defs{$d}{$internal};
|
||||
}
|
||||
|
||||
return @ret;
|
||||
}
|
||||
|
||||
##################################################
|
||||
# functions used for file handling
|
||||
# called by 98_configdb.pm
|
||||
|
Loading…
Reference in New Issue
Block a user