From: Will Budic Date: Mon, 2 Mar 2020 19:07:30 +0000 (+1100) Subject: Anons refelected to db from script. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=2f955e554a1a100f6f1fb5c02f13cda70015033e;p=LifeLog.git Anons refelected to db from script. --- diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index b9d40cd..d4e95c1 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -142,7 +142,7 @@ sub checkAutologinSet { } elsif(rindex ($line, "<", 18; - $BACKUP_ENABLED = substr $line, 18, $end - 17; + $BACKUP_ENABLED = substr $line, 17, $end - 17; last; #we expect as last anon to be set. } elsif(rindex ($line, "<connect($dsn, $alias, $passw, { RaiseError => 1 }) or LifeLogException->throw($DBI::errstri); - my $rv; - my $changed = 0; + my ($pst, $sql,$rv, $changed) = 0; # We live check database for available tables now only once. # If brand new database, this sill returns fine an empty array. my $pst = Settings::selectRecords($db,"SELECT name FROM sqlite_master WHERE type='table' or type='view';"); @@ -203,7 +202,16 @@ sub checkCreateTables { my $hasLogTbl = $curr_tables{'LOG'}; my $hasNotesTbl = $curr_tables{'NOTES'}; my @annons = Settings::anons(); - LifeLogException -> throw("Annons!") if (@annons==0);#We added above the backup_enabled anon if missing in script. + LifeLogException -> throw("Annons!") if (@annons==0);#We even added above the backup_enabled anon, so WTF? + + # Reflect anons to db config. + $sql = "SELECT ID, NAME, VALUE FROM CONFIG WHERE"; + foreach my $ana(@annons){$sql .= " NAME LIKE '$ana' OR";};$sql =~ s/OR$//; $sql .=';'; + $pst = Settings::selectRecords($db, $sql); + while(my @row = $pst->fetchrow_array()) { + my ($vid,$n,$sv, $dv) = ($row[0], $row[1], Settings::anon($row[1]), $row[2]); + $db->do("UPDATE CONFIG SET VALUE='$sv' WHERE ID=$vid;") if($dv ne $sv); + } # # From v.1.8 Log has changed, to have LOG to NOTES relation. # @@ -218,7 +226,7 @@ sub checkCreateTables { $db->do('CREATE TABLE life_log_login_ctr_temp_table AS SELECT * FROM LOG;'); my %notes_ids = (); if($hasNotesTbl){ - my $pst = Settings::selectRecords($db, 'SELECT rowid, DATE FROM LOG WHERE RTF > 0 ORDER BY DATE;'); + $pst = Settings::selectRecords($db, 'SELECT rowid, DATE FROM LOG WHERE RTF > 0 ORDER BY DATE;'); while(my @row = $pst->fetchrow_array()) { my $sql_date = $row[1];; $sql_date = DateTime::Format::SQLite->parse_datetime($sql_date); @@ -287,11 +295,10 @@ sub checkCreateTables { } # From v.1.6 view use server side views, for pages and correct record by ID and PID lookups. - # This should make queries faster, less convulsed, and log renumeration less needed, for accurate pagination. + # This should make queries faster, less convulsed, and log renumeration less needed for accurate pagination. if(!$curr_tables{'VW_LOG'}) { $rv = $db->do(&Settings::createVW_LOGStmt); } - # TODO if(!$curr_tables{'CAT'}) { $db->do(&Settings::createCATStmt); $changed = 1; @@ -329,7 +336,7 @@ sub checkCreateTables { if($changed){ #It is also good to run db fix (config page) to renum if this is an release update? #Release in software might not be what is in db, which counts. - #This here newxt we now update. + #This here next we now update. my @r = Settings::selectRecords($db, 'SELECT ID, VALUE FROM CONFIG WHERE NAME IS "RELEASE_VER";')->fetchrow_array(); my $did = $r[0]; my $dnm = $r[1]; @@ -373,7 +380,7 @@ sub populate { my $err = ""; my %vars = (); my @lines; - my $ttype = 0; + my $tt = 0; open(my $fh, "<:perlio", &Settings::logPath.'main.cnf' ) or LifeLogException->throw( "Can't open main.cnf: $!"); read $fh, my $content, -s $fh; @@ -385,12 +392,12 @@ sub populate { $db->begin_work(); foreach my $line (@lines) { - last if ($line =~ //); + last if ($line =~ //);#Not doing it with CNF1.0 + + if( index( $line, '<' ) == 0 ) {next;} #Migration is complex main.cnf might contain SQL alter statements. my @tick = split("`",$line); if( scalar @tick == 2 ) { @@ -420,9 +427,9 @@ $err .= "Invalid, spec'ed {uid}|{variable}`{description}-> $line\n"; }#rof } - elsif($ttype==0){ - $err .= "Invalid, spec'd entry -> $line\n"; - }elsif($ttype==1){ + elsif($tt==0){ +$err .= "Invalid, spec'd entry -> $line\n"; + }elsif($tt==1){ my @pair = $tick[0] =~ m[(\S+)\s*\|\s*(\S+\s*\S*)]g; if ( scalar(@pair)==2 ) { # In older DB versions the Category name could be different, user modified. @@ -438,8 +445,8 @@ $err .= "Invalid, spec'ed {uid}|{variable}`{description}-> $line\n"; else { $err .= "Invalid, spec'ed {uid}|{category}`{description}-> $line\n"; } - }elsif($ttype==2){ - #TODO Do we really want this? + }elsif($tt==2){ + #TODO Do we really want this? Insert into log from config script. } }elsif($inData && length($line)>0){ diff --git a/htdocs/cgi-bin/system/modules/Settings.pm b/htdocs/cgi-bin/system/modules/Settings.pm index 00eaa38..7e95807 100644 --- a/htdocs/cgi-bin/system/modules/Settings.pm +++ b/htdocs/cgi-bin/system/modules/Settings.pm @@ -50,6 +50,7 @@ our $DEBUG = 1; #201 -> '^EXCLUDES' : 0 (Used in main.cgi) sub anons {return sort keys %anons} +#Check call with defined(Settings::anon('my_anon')) sub anon {my $n=shift; return $anons{$n}} sub release {return $RELEASE_VER} @@ -136,7 +137,7 @@ sub getConfiguration { my ($db, $hsh) = @_; try { my $st = $db->prepare("SELECT ID, NAME, VALUE FROM CONFIG;"); - $st->execute(); + $st->execute(); while ( my @r = $st->fetchrow_array() ){ switch ( $r[1] ) { case "RELEASE_VER" { $RELEASE_VER = $r[2];} @@ -161,7 +162,7 @@ sub getConfiguration { } #Anons are murky grounds. -- @bud if($hsh){ - my $stIns = $db->prepare("INSERT INTO CONFIG (ID, NAME, VALUE) VALUES(?,?,?)"); + my $stIns = $db->prepare("INSERT INTO CONFIG (ID, NAME, VALUE, DESCRIPTION) VALUES(?,?,?,?)"); foreach my $key (keys %{$hsh}){ if(index($key,'$')!=0){#per spec. anons are not prefixed with an '$' as signifier. my $val = %{$hsh}{$key}; @@ -170,13 +171,13 @@ sub getConfiguration { $anons{$key} = $val; if(not defined $existing){ #Make it now config global. Note another source latter calling this subroutine - #can overwrite this, but not in the database. Where it is now set here. + #can overwrite this, but not in the database. Where it is now set by the following. #Find free ID. my @res = selectRecords($db,"SELECT MAX(ID) FROM CONFIG;")->fetchrow_array(); #ID's under 300 are reserved, for constants. my $id = $res[0]+1; while($id<300){ $id += ($id*1.61803398875); }#Golden ratio step it to best next available. - $stIns->execute(int($id), $key, $val); + $stIns->execute(int($id), $key, $val, "Anonymous application setting."); } } } @@ -389,4 +390,5 @@ sub configProperty { } } + 1; \ No newline at end of file