From c244d778f4959f8e82e71f058ae4f3e470337644 Mon Sep 17 00:00:00 2001 From: betateilchen Date: Fri, 22 Aug 2014 11:52:04 +0000 Subject: [PATCH] configdb - added: automatic fileimport to migration git-svn-id: https://svn.fhem.de/fhem/trunk@6441 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_configdb.pm | 11 +++- fhem/configDB.pm | 107 +++++++++++++++++++++++++++++++++++---- 2 files changed, 106 insertions(+), 12 deletions(-) diff --git a/fhem/FHEM/98_configdb.pm b/fhem/FHEM/98_configdb.pm index 376daf249..1d74afab9 100644 --- a/fhem/FHEM/98_configdb.pm +++ b/fhem/FHEM/98_configdb.pm @@ -223,12 +223,14 @@ sub CommandConfigdb($$) { Currently the fhem modules

  • 02_RSS.pm
  • +
  • 91_eventTypes
  • 93_DbLog.pm
  • 95_holiday.pm
  • 98_SVG.pm

  • will use configDB to read their configuration data from database
    instead of formerly used configuration files inside the filesystem.
    +
    This requires you to import your configuration files from filesystem into database.

    Example:
    @@ -237,7 +239,9 @@ sub CommandConfigdb($$) { configdb fileimport www/gplot/xyz.gplot

    This does not affect the definitons of your holiday or RSS entities.
    - The given filenames in the definitions will be translated automatically to find the correct entries inside the database.
    +
    + During migration all external configfiles used in current configuration
    + will be imported aufmatically.


    Each fileimport into database will overwrite the file if it already exists in database.

    @@ -537,6 +541,7 @@ attr Melder_FAr peerIDs 00000000,2286BC03, Momentan verwenden die Module

  • 02_RSS.pm
  • +
  • 91_eventTypes
  • 93_DbLog.pm
  • 95_holiday.pm
  • 98_SVG.pm
  • @@ -551,7 +556,9 @@ attr Melder_FAr peerIDs 00000000,2286BC03, configdb fileimport www/gplot/xyz.gplot

    Dies hat keinerlei Auswirkungen auf die Definition der holiday oder RSS Instanzen.
    - Die dort verwendeten Dateinamen werden automtisch umgesetzt, um die zugehörigen Daten in der Datenbank zu finden.
    +
    + Während einer Migration werden alle in der aktuell bestehenden Konfiguration verwendeten externen
    + Konfigurationsdateien automatisch in die Datenbank importiert.


    Jeder Neuimport einer bereits in der Datenbank gespeicherten Datei überschreibt die vorherige Datei in der Datenbank.

    diff --git a/fhem/configDB.pm b/fhem/configDB.pm index 72c6e8876..f332a4797 100644 --- a/fhem/configDB.pm +++ b/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