summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ee451a7)
raw | patch | inline | side by side (parent: ee451a7)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 28 Feb 2008 14:26:34 +0000 (14:26 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 28 Feb 2008 14:26:34 +0000 (14:26 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9191 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/server/events/databases.pm | [new file with mode: 0644] | patch | blob |
diff --git a/gosa-si/server/events/databases.pm b/gosa-si/server/events/databases.pm
--- /dev/null
@@ -0,0 +1,187 @@
+package databases;
+use Exporter;
+@ISA = qw(Exporter);
+my @events = (
+ "get_events",
+ "query_jobdb",
+ "query_packages_list",
+ "count_jobdb",
+ "count_packages_list",
+ "delete_jobdb_entry",
+ "clear_jobdb",
+ "update_status_jobdb_entry",
+ );
+@EXPORT = @events;
+
+use strict;
+use warnings;
+use GOSA::GosaSupportDaemon;
+use Data::Dumper;
+use utf8;
+
+BEGIN {}
+
+END {}
+
+### Start ######################################################################
+
+#&main::read_configfile($main::cfg_file, %cfg_defaults);
+
+sub get_events {
+ return \@events;
+}
+
+
+sub query_packages_list { return &query_db( @_ ) ; }
+sub query_jobdb { return &query_db( @_ ) ; }
+sub query_db {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $target = @{$msg_hash->{'target'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $table;
+ my $db;
+ if( $header =~ /query_jobdb/ ) {
+ $table = $main::job_queue_tn;
+ $db = $main::job_db;
+ } elsif( $header =~ /query_packages_list/ ) {
+ $table = $main::packages_list_tn;
+ $db = $main::packages_list_db;
+ }
+
+ # prepare sql statement and execute query
+ my $select= &get_select_statement($msg, $msg_hash);
+ my $where= &get_where_statement($msg, $msg_hash);
+ my $limit= &get_limit_statement($msg, $msg_hash);
+ my $orderby= &get_orderby_statement($msg, $msg_hash);
+ my $sql_statement= "SELECT $select FROM $table $where $orderby $limit";
+ my $res_hash = $db->select_dbentry($sql_statement);
+
+ my $out_xml = &db_res2si_msg($res_hash, $header, $target, $source);
+ my @out_msg_l = ( $out_xml );
+ return @out_msg_l;
+}
+
+
+sub count_packages_list{ return &count_db( @_ ); }
+sub count_jobdb{ return &count_db( @_ ); }
+sub count_db {
+ my ($msg, $msg_hash, $session_id) = @_;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $target = @{$msg_hash->{'target'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $table;
+ my $db;
+ if( $header =~ /count_jobdb/ ) {
+ $table = $main::job_queue_tn;
+ $db = $main::job_db;
+ } elsif( $header =~ /count_packages_list/ ) {
+ $table = $main::packages_list_tn;
+ $db = $main::packages_list_db;
+ }
+
+ # prepare sql statement and execute query
+ my $res_hash = $db->select_dbentry("SELECT * FROM $table");
+
+ my $count = keys(%{$res_hash});
+ my $out_xml= "<xml><header>answer</header><source>$target</source><target>$source</target><count>$count</count></xml>";
+ my @out_msg_l = ( $out_xml );
+ return @out_msg_l;
+}
+
+sub delete_jobdb_entry {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $target = @{$msg_hash->{'target'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+
+ # prepare query sql statement
+ my $table= $main::job_queue_tn;
+ my $where= &get_where_statement($msg, $msg_hash);
+ my $sql_statement = "DELETE FROM $table $where";
+
+ # execute db query
+ my $db_res = $main::job_db->del_dbentry($sql_statement);
+
+ my $res;
+ if( $db_res > 0 ) {
+ $res = 0 ;
+ } else {
+ $res = 1;
+ }
+
+ # prepare xml answer
+ my $out_xml = "<xml><header>answer</header><source>$target</source><target>$source</target><answer1>$res</answer1></xml>";
+ my @out_msg_l = ( $out_xml );
+ return @out_msg_l;
+
+}
+
+
+sub clear_jobdb {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $target = @{$msg_hash->{'target'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+
+ my $error= 0;
+ my $out_xml= "<xml><answer1>1</answer1></xml>";
+
+ my $table= $main::job_queue_tn;
+
+ my $sql_statement = "DELETE FROM $table";
+ my $db_res = $main::job_db->del_dbentry($sql_statement);
+ if( not $db_res > 0 ) { $error++; };
+
+ if( $error == 0 ) {
+ $out_xml = "<xml><header>answer</header><source>$target</source><target>$source</target><answer1>0</answer1></xml>";
+ }
+ my @out_msg_l = ( $out_xml );
+ return @out_msg_l;
+}
+
+
+sub update_status_jobdb_entry {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $target = @{$msg_hash->{'target'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+
+ my $error= 0;
+ my $out_xml= "<xml><header>answer</header><source>$target</source><target>$source</target><answer1>1</answer1></xml>";
+
+ my @len_hash = keys %{$msg_hash};
+ if( 0 == @len_hash) { $error++; };
+
+ # prepare query sql statement
+ if( $error == 0) {
+ my $table= $main::job_queue_tn;
+ my $where= &get_where_statement($msg, $msg_hash);
+ my $update= &get_update_statement($msg, $msg_hash);
+
+ # conditions
+ # no timestamp update if status eq waiting
+ my $res_hash = $main::job_db->select_dbentry("SELECT * FROM $table $where AND status='processing' ");
+ if( (0 != keys(%$res_hash)) && ($update =~ /timestamp/i) ) {
+ $error ++;
+ $out_xml = "<answer1>1</answer1><error_string>there is no timestamp update allowed while status is 'processing'</error_string>";
+ }
+
+ if( $error == 0 ) {
+ my $sql_statement = "UPDATE $table $update $where";
+ # execute db query
+ my $db_res = $main::job_db->update_dbentry($sql_statement);
+
+ # check success of db update
+ if( not $db_res > 0 ) { $error++; };
+
+ }
+ }
+
+ if( $error == 0) {
+ $out_xml = "<answer1>0</answer1>";
+ }
+
+ my $out_msg = sprintf("<xml><header>answer</header><source>%s</source><target>%s</target>%s</xml>", $target, $source, $out_xml);
+ my @out_msg_l = ( $out_msg );
+ return @out_msg_l;
+}
+
+1;