From: Kilian Saffran Date: Tue, 27 Mar 2018 07:27:48 +0000 (+0200) Subject: check schema verification and added backup of db to modify X-Git-Tag: 3.18.2 X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=2fcf97de8dca518cddd41420974b77aebd5154bc;p=creorga.git check schema verification and added backup of db to modify --- diff --git a/Tools/creorgadb.pl b/Tools/creorgadb.pl index 0f849b1..7957dd4 100644 --- a/Tools/creorgadb.pl +++ b/Tools/creorgadb.pl @@ -4,16 +4,19 @@ use strict; use File::Basename; use Getopt::Long; use Data::Dumper; +use File::Copy qw/copy/; +use Time::Local; use utf8; use lib ('.'); use sqlite; + my $dbfile = ""; my $templatedb = ""; GetOptions("dbfile|db=s" => \$dbfile, "template|t=s" => \$templatedb ); -#-db "C:\\Users\\ksaff\\DKS\\projects\\Creorga\\DevCreches\\9475a95d-e2ad-4586-8432-d44a604b3fd3.sqlite" -t "C:\\Users\\ksaff\\Workspace\\creorga\\app\\defaults\\profile\\creorga.sqlite" +#-db "C:\\Users\\ksaff\\Workspace\\creorga\\test\\f4ebb982-498b-11e4-96ae-4302fce0f26a.sqlite" -t "C:\\Users\\ksaff\\Workspace\\creorga\\app\\defaults\\profile\\creorga.sqlite" sub getcoldef($){ my $strddl = shift; @@ -22,8 +25,8 @@ sub getcoldef($){ my $bi = index($curddl,'(')+1; my $ei = rindex($curddl,')'); - $curddl = substr($curddl,$bi,length($curddl)-$bi-(length($curddl)-$ei));#curddl.substring(curddl.indexOf('(')+1,curddl.lastIndexOf(')')).trim().replace(/\s+/g," "); - my @colsfull = split(/,/,$curddl);# curddl =curddl.replace(new RegExp("\\b(" + appdb.keywords.join("|") + ")\\b", "g"), ""); + $curddl = substr($curddl,$bi,length($curddl)-$bi-(length($curddl)-$ei)); + my @colsfull = split(/,/,$curddl); my $tblobj = (); foreach my $c (@colsfull){ $c =~ s/^\s+//; @@ -37,11 +40,27 @@ sub getcoldef($){ return $tblobj; } +sub getcudatetime2(){ + + my @cdate = localtime(); + $cdate[5] = $cdate[5] +1900; + my $utime = timelocal($cdate[0],$cdate[1],$cdate[2],$cdate[3],$cdate[4],$cdate[5]); + return $utime; +} + if ((! -e $dbfile) || (! -e $templatedb)) { print "incomplete input!\n"; exit(1); } - +print "DB:".$dbfile."\n"; +print "Template-DB:".$templatedb."\n"; +#make backup first: +print "Backup Database:\n"; +my $dbdestfile = dirname($dbfile).'/'.substr(basename($dbfile),0,-7)."_".&getcudatetime2().'.bkp.sqlite'; +copy($dbfile,$dbdestfile); +if (! -e $dbdestfile){ + exit(5); +} my $db = sqlite->new($templatedb); my $dbdefsql = "SELECT type, name,tbl_name,sql FROM sqlite_master order by name,tbl_name,type;"; @@ -96,7 +115,7 @@ foreach my $pd (sort {$a <=> $b} keys(%{$defdbschemacfg})){ my $stexec = 0; for(my $s=0;$sdbexec($ainssql[$s]); } } @@ -131,7 +150,7 @@ foreach my $pd (sort {$a <=> $b} keys(%{$defdbschemacfg})){ my $stexec = 0; for(my $s=0;$sdbexec($ainssql[$s]); } } @@ -147,51 +166,4 @@ if ($bvaccum == 1) { print "Exec vacuum;\n"; $db->dbexec("vacuum;"); } -# check_defaultdata: function(){ -# -# appdb.closeConnection(); -# //dump("Local DBFile: " + appdb.dbFile.path + "\n"); -# var tables = ['creche','groups','workinghours','vacancy','costs','planningtemplate']; -# for (var t in tables) { -# var sql = "select count(*) as cnt from "+ tables[t]+";"; -# -# var res = appdb.dbquery(sql); -# -# if ((res) && (res.sqldata[0].cnt == '0')) { -# dump(sql + " --> "+JSON.stringify(res)+ "\n"); -# var inssql = []; -# if (tables[t] == 'creche') { -# inssql.push("INSERT INTO creche (crechename, adress, city, country, zip, maxchilds, uuid, minage, maxage) VALUES ('"+curcfg.name+"', '', '', 'Luxembourg', '', 28, '"+ curcfg.uuid +"', 2, 84);"); -# } else if (tables[t] == 'groups') { -# var sinssql = "INSERT INTO groups (grpname, maxchilds, minage, maxage, uuid) VALUES "; -# sinssql += "('Groupe Bébé', 6, 2, 12, '"+ appdb.generate_uuid() +"'),"; -# sinssql += "('Groupe plus 1 an ', 6, 12, 24, '"+ appdb.generate_uuid() +"'),"; -# sinssql += "('Groupe de 2 ans à 3 ans', 8, 24, 36, '"+ appdb.generate_uuid() +"'),"; -# sinssql += "('Groupe de 3 à 4 ans ', 8, 36, 48, '"+ appdb.generate_uuid() +"'),"; -# sinssql += "('Groupe plus 4 ans ( Scolaires)', 11, 48, 84, '"+ appdb.generate_uuid() +"');" -# inssql.push(sinssql); -# } else if (tables[t] == 'workinghours') { -# inssql.push("INSERT INTO workinghours (uuid, datestart, montimeopen, montimeclose, tuetimeopen, tuetimeclose, wedtimeopen, wedtimeclose, thutimeopen, thutimeclose, fritimeopen, fritimeclose, sattimeopen, sattimeclose, suntimeopen, suntimeclose, crecheuuid) VALUES ('"+appdb.generate_uuid()+"', strftime(\"%Y\",date('now','-1 year')) || '-01-01', '07:00', '19:00', '07:00', '19:00', '07:00', '19:00', '07:00', '19:00', '07:00', '19:00', null, null, null, null, '"+ curcfg.uuid+"');"); -# -# } else if (tables[t] == 'costs') { -# var sinssql = "INSERT INTO costs (startdate, costsperhour, weeklyhourslimit, dailylunchcosts, uuid) VALUES "; -# sinssql += "('2015-01-01', 0.0, 0.0, 0.0, '"+ appdb.generate_uuid()+"');"; -# inssql.push(sinssql); -# } else if (tables[t] == 'planningtemplate') { -# //dump("Planningtemplate\n"); -# var sinssql = "INSERT INTO planningtemplate (uuid, montimebegin, montimeend, monlunch, tuetimebegin, tuetimeend, tuelunch, wedtimebegin, wedtimeend, wedlunch, thutimebegin, thutimeend, thulunch, fritimebegin, fritimeend, frilunch, templatename) VALUES "; -# sinssql += "('"+ appdb.generate_uuid()+"', '08:00', '18:00', 1, '08:00', '18:00', 1, '08:00', '18:00', 1, '08:00', '18:00', 1, '08:00', '18:00',1, 'plain temps (60h)'),"; -# sinssql += "('"+ appdb.generate_uuid()+"', '08:00', '13:00', 1, '08:00', '13:00', 1, '08:00', '13:00', 1, '08:00', '13:00', 1, '08:00', '13:00',1,'matin (30h)'),"; -# sinssql += "('"+ appdb.generate_uuid()+"', '13:00', '18:00', 1, '13:00', '18:00', 1, '13:00', '18:00', 1, '13:00', '18:00', 1, '13:00', '18:00',1, 'après-midi (30h)');"; -# inssql.push(sinssql); -# //dump(inssql + "\n"); -# } -# for (var i in inssql){ -# appdb.dbexec_silent(inssql[i]); -# } -# //dump("Set default Data:" + inssql + "\n"); -# -# } -# } -# } diff --git a/app_v3/chrome/content/js/init.js b/app_v3/chrome/content/js/init.js index 93738d9..8269823 100644 --- a/app_v3/chrome/content/js/init.js +++ b/app_v3/chrome/content/js/init.js @@ -31,11 +31,11 @@ else { } // else { //// if (apppref.getpreference("support.autobackup") === true) { -//// tools.backup(); -//// } -//// if (system.fileexists(system.profilerootdir() + system.sep() + '/checkschema.txt')){ -//// appdb.check_schema(); +//// //// } + if (system.fileexists(system.profilerootdir() + system.sep() + '/checkschema.txt')){ + appdb.check_schema(); + } // } navigation.load_deck(2); }