Code

Delete most databases on startup, avoid need of ALTER TABLE (not reliable with SQLite).
authorjanw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 12 May 2009 09:11:27 +0000 (09:11 +0000)
committerjanw <janw@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 12 May 2009 09:11:27 +0000 (09:11 +0000)
References 658

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13647 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-server
gosa-si/modules/DBsqlite.pm

index aa6f576d79073686e66a46a2abbaf6a9b244ca6e..af76ab68c99b5d95c5f5d4e254eaf496409b8ad5 100755 (executable)
@@ -1812,8 +1812,7 @@ sub watch_for_new_jobs {
                                        my $res_2 = $job_db->exec_statement( $sql_statement_2 );
                                        if(defined($res_2) and defined @{$res_2}[0]) {
                                                # Set status from goto-activation to 'waiting' and update timestamp
-                                               $job_db->exec_statement("UPDATE $job_queue_tn SET status='waiting' WHERE macaddress LIKE '$macaddress' AND headertag = 'trigger_action_reinstall'");
-                                               $job_db->exec_statement("UPDATE $job_queue_tn SET timestamp='".&calc_timestamp(&get_time(), 'plus', 30)."' WHERE macaddress LIKE '$macaddress' AND headertag = 'trigger_action_reinstall'");
+                                               $job_db->exec_statement("UPDATE $job_queue_tn SET status='waiting', timestamp='".&calc_timestamp(&get_time(), 'plus', 30)."' WHERE macaddress LIKE '$macaddress' AND headertag = 'trigger_action_reinstall'");
                                        }
                                }
                                next;
@@ -3354,6 +3353,8 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1);
         # connect to incoming_db
         unlink($incoming_file_name);
         $incoming_db = GOSA::DBsqlite->new($incoming_file_name);
+        chmod(0640, $incoming_file_name);
+        chown($root_uid, $adm_gid, $incoming_file_name);
         
         # connect to gosa-si job queue
         $job_db = GOSA::DBsqlite->new($job_queue_file_name);
@@ -3361,6 +3362,7 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1);
         chown($root_uid, $adm_gid, $job_queue_file_name);
         
         # connect to known_clients_db
+        unlink($known_clients_file_name);
         $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
         chmod(0640, $known_clients_file_name);
         chown($root_uid, $adm_gid, $known_clients_file_name);
@@ -3396,7 +3398,6 @@ daemon_log($server_status_hash->{$server_status}.": $server_revision", 1);
         chown($root_uid, $adm_gid, $fai_release_file_name);
         
         # connect to packages_list_db
-        #unlink($packages_list_file_name);
         unlink($packages_list_under_construction);
         $packages_list_db = GOSA::DBsqlite->new($packages_list_file_name);
         chmod(0640, $packages_list_file_name);
index e6ec1048c289149ddeb576211a72b3b491c8b3a6..21ad1f75244642af8b04a889676d1a08bb8925a1 100644 (file)
@@ -6,6 +6,7 @@ use Carp;
 use DBI;
 use GOSA::GosaSupportDaemon;
 use Time::HiRes qw(usleep);
+use Data::Dumper;
 use Fcntl qw/:DEFAULT :flock/; # import LOCK_* constants
 
 our $col_names = {};
@@ -128,8 +129,15 @@ sub create_table {
        foreach my $col_name (@$col_names_ref) {
                push(@col_names, $col_name);
        }
-       
        $col_names->{ $table_name } = \@col_names;
+       
+       # Not activated yet
+       # Check schema
+       # if($self->check_schema($table_name)) {
+       #       $self->exec_statement("DROP TABLE $table_name");
+       #       &main::daemon_log("WARNING: Schema of table $table_name has changed! Table will be recreated!", 3);
+       # }
+
        my $col_names_string = join(", ", @col_names);
        my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )"; 
        my $res = $self->exec_statement($sql_statement);
@@ -145,6 +153,49 @@ sub create_table {
 }
 
 
+# sub check_schema {
+#      my $self = shift;
+#      my $result = 1;
+#      if(not defined($self) or ref($self) ne 'GOSA::DBsqlite') {
+#              &main::daemon_log("0 ERROR: GOSA::DBsqlite::check_schema was called static! Argument was '$self'!", 1);
+#              return $result;
+#      }
+# 
+#      my $table_name = shift || undef;
+#      my $table_columns;
+# 
+#      if($table_name and $col_names->{$table_name}) {
+#              # Query the table_info from database
+#              foreach my $column ( @{ $self->exec_statement ( "pragma table_info('$table_name')" ) } ) {
+#                      my $column_name = @$column[1];
+#                      my $data_type   = @$column[2];
+#                      $table_columns->{$column_name}= $data_type;
+#              }
+# 
+#              foreach my $column (@{$col_names->{$table_name}}) {
+#                      my ($column_name, $datatype) = split(/\s/, $column);
+#                      if(exists($table_columns->{$column_name})) {
+#                              if(lc $datatype eq lc $table_columns->{$column_name}) {
+#                                      next;
+#                              } else {
+#                                      &main::daemon_log("WARNING: Column '$column_name' has wrong datatype!", 1);
+#                                      $result = 0;
+#                              }
+#                      } else {
+#                              $result = 0;
+#                              &main::daemon_log("WARNING: Column '$column_name' is missing!", 1);
+#                              #&main::daemon_log("DEBUG Columns are not equal! Column '".$self->{db_name}.".$column_name' is missing!", 0);
+#                              #my $sql_statement = "ALTER TABLE $table_name ADD COLUMN $column_name $datatype";
+#                              #$self->exec_statement($sql_statement);
+#                              # The ALTER TABLE statement sucks completely in SQLite, so just recreate the table
+#                      }
+#              }
+#      }
+# 
+#      return $result;
+# }
+
+
 sub add_dbentry {
        my $self = shift;
        my $arg = shift;