[Affelio-cvs 272] CVS update: affelio/lib/Affelio/Managing

Back to archive index

Tadashi Okoshi slash****@users*****
2005年 6月 29日 (水) 20:06:56 JST


Index: affelio/lib/Affelio/Managing/AccessLogManager.pm
diff -u affelio/lib/Affelio/Managing/AccessLogManager.pm:1.2 affelio/lib/Affelio/Managing/AccessLogManager.pm:1.3
--- affelio/lib/Affelio/Managing/AccessLogManager.pm:1.2	Wed Jun 29 19:40:17 2005
+++ affelio/lib/Affelio/Managing/AccessLogManager.pm	Wed Jun 29 20:06:56 2005
@@ -4,7 +4,7 @@
 #    http://affelio.jp/ (Japan)
 #    http://affelio.jp/ (USA and other area)
 #
-# $Id: AccessLogManager.pm,v 1.2 2005/06/29 10:40:17 slash5234 Exp $
+# $Id: AccessLogManager.pm,v 1.3 2005/06/29 11:06:56 slash5234 Exp $
 
 package Affelio::Managing::AccessLogManager;
 {
@@ -56,7 +56,7 @@
 	################################
 	#Check the table
 	################################
-	my $create_tbl_cmd = "CREATE TABLE AFuser_CORE_accesslog(timestamp INTEGER PRIMARY KEY, nickname TEXT, afid TEXT, type TEXT)";
+	my $create_tbl_cmd = "CREATE TABLE AFuser_CORE_accesslog(id INTEGER PRIMARY KEY, timestamp INTEGER, nickname TEXT, afid TEXT, type TEXT)";
 	eval{
 	    $af->{db}->do($create_tbl_cmd);
 	};
@@ -66,31 +66,50 @@
 	}
 
 	################################
-	#Remove today's past access of this user
+	#check today's past access of this user
 	################################
-	my $query1; my $sth1;
-	$query1 = "DELETE FROM AFuser_CORE_accesslog WHERE timestamp >= $today AND afid = '$afid'";
+	my $query1; my $sth1; 	$@="";
+	my @row1=();
+	$query1 = "SELECT * FROM AFuser_CORE_accesslog WHERE timestamp >= $today AND afid = '$afid'";
 	eval{
 	    $sth1 = $af->{db}->prepare($query1);
 	    $sth1->execute();
+	    @row1 = $sth1->fetchrow_array;
 	};
 	if($@){
 	    die("db");
 	}
 
-	################################
-	#Add this access
-	################################
-	my $query2; my $sth2;
-	$query2 = "insert into AFuser_CORE_accesslog(timestamp, nickname, afid, type) values ($cur_time, '$nickname', '$afid', '$type')";
-	eval{
-	    $sth2 = $af->{db}->prepare($query2);
-	    $sth2->execute();
-	};
-	if($@){
-	    die("db");
-	}
+	if(@row1 == () ){
+	    my $newid=0;
 
+	    ##############################
+	    #Get existing max ID
+	    my $query2 = 'SELECT max(id) FROM AFuser_CORE_accesslog';
+	    my $sth2 = $af->{db}->prepare($query2) or die $af->{db}->errstr;
+	    $sth2->execute or die $af->{db}->errstr;
+	    my @row2 = $sth2->fetchrow_array;
+	    my $maxid = $row2[0];
+	    if(defined($row2[0])){
+		$maxid = $row2[0];
+	    }else{
+		$maxid = 0;
+	    }
+	    $newid = $maxid+1;
+
+	    ################################
+	    #Add this access
+	    ################################
+	    my $query3; my $sth3;
+	    $query3 = "insert into AFuser_CORE_accesslog(id, timestamp, nickname, afid, type) values ($newid, $cur_time, '$nickname', '$afid', '$type')";
+	    eval{
+		$sth3 = $af->{db}->prepare($query3);
+		$sth3->execute();
+	    };
+	    if($@){
+		die("db");
+	    }
+	}
     }
 
     #######################################################################
@@ -104,9 +123,21 @@
 
 	debug_print("AccessLog::get_log: $from -> $to");
 
+	################################
+	#Check the table
+	################################
+	my $create_tbl_cmd = "CREATE TABLE AFuser_CORE_accesslog(id INTEGER PRIMARY KEY, timestamp INTEGER, nickname TEXT, afid TEXT, type TEXT)";
+	eval{
+	    $af->{db}->do($create_tbl_cmd);
+	};
+	if($@){
+	}else{
+	    debug_print("AccessLog:save: Table created.");
+	}
+
 	##############################
 	#retrieve all friend records from DB
-	my $query = "SELECT * FROM AFuser_CORE_accesslog WHERE timestamp > $from AND timestamp < $to";
+	my $query = "SELECT * FROM AFuser_CORE_accesslog WHERE timestamp > $from AND timestamp < $to order by id desc";
 	my $sth = $af->{db}->prepare($query) or die $af->{db}->errstr; 
 	$sth->execute or die $af->{db}->errstr;
 


Affelio-cvs メーリングリストの案内
Back to archive index