vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r15177: LJLMI-7: save history of adding friends....

Committer: vad
LJLMI-7: save history of adding friends.

A   branches/msn/cgi-bin/LJ/Friend/
A   branches/msn/cgi-bin/LJ/Friend/History.pm
Added: branches/msn/cgi-bin/LJ/Friend/History.pm
===================================================================
--- branches/msn/cgi-bin/LJ/Friend/History.pm	                        (rev 0)
+++ branches/msn/cgi-bin/LJ/Friend/History.pm	2009-05-15 03:55:03 UTC (rev 15177)
@@ -0,0 +1,74 @@
+package LJ::Friend::History;
+use strict;
+
+=head
+create table friend_history (
+    rec_id  integer unsigned unique auto_increment primary key,
+    action  varchar(24),
+    
+    uid     integer unsigned not null,
+    fid     integer unsigned not null,
+    
+    status  integer,
+    added   datetime,
+    
+    INDEX(action)
+);
+=cut
+
+sub add_record {
+    my $class = shift;
+    my %args  = @_;
+    
+    my $action = delete $args{action}
+        or die "Unknown action";
+    my $uid    = int delete $args{uid}
+        or die "userid does not provided";
+    my $fid    = int delete $args{fid}
+        or die "friendid does not provided";
+   
+    my $dbh = LJ::get_db_writer();
+    $dbh->do("
+        INSERT INTO friend_history 
+            (action, uid, fid, status, added)
+            VALUES
+            (?,?,?,?,NOW())
+        ", undef,
+        $action, $uid, $fid, "1"
+        );
+
+    die "Error adding record to friend_history: " . $dbh->err . " " . $dbh->errstr
+        if $dbh->err;
+
+    return 1;
+}
+sub log {
+    my $class = shift;
+    my %args  = @_;
+
+    my $from  = int(delete $args{from}); # 0 is ok
+    my $to    = int(delete $args{to}) || 100;
+
+    my $dbr = LJ::get_db_reader();
+    my $sth = $dbr->prepare("
+        SElECT *, UNIX_TIMESTAMP(added) as added 
+        FROM friend_history
+        WHERE
+            rec_id >= ?
+            AND rec_id <= ?
+        ORDER BY
+            rec_id asc
+    ");
+    $sth->execute($from, $to);
+    
+    my @res = ();
+    while (my $h = $sth->fetchrow_hashref){
+        push @res => $h;
+    }
+
+    return @res;
+}
+
+
+
+1;

Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments