Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r22589: LJSUP-13229 (refactor userlog code into ...

Committer: ailyin
LJSUP-13229 (refactor userlog code into LJ::User::Userlog / LJ::User::UserlogRecord)
U   trunk/bin/misc/set_comm_supermaintainer.pl
U   trunk/bin/worker/find-sendmail-problems
U   trunk/bin/worker/friending_queue
U   trunk/cgi-bin/LJ/Console/Command/BanSet.pm
U   trunk/cgi-bin/LJ/Console/Command/BanUnset.pm
U   trunk/cgi-bin/LJ/Console/Command/SetOwner.pm
U   trunk/cgi-bin/LJ/Event/SecurityAttributeChanged.pm
U   trunk/cgi-bin/LJ/Message.pm
U   trunk/cgi-bin/LJ/NotificationInbox.pm
U   trunk/cgi-bin/LJ/Poll.pm
A   trunk/cgi-bin/LJ/User/Userlog.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/
A   trunk/cgi-bin/LJ/User/UserlogRecord/AccountCreate.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/AccountStatus.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/BanSet.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/BanUnset.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/DeleteDelayedEntry.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/DeleteEntry.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/DeleteUserpic.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/EmailChange.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/EmailPost.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/FlushFriendsActivitiesQueue.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/FriendInviteSent.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/InboxMassDelete.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/MaintainerAdd.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/MaintainerRemove.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/MassPrivacyChange.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/PasswordChange.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/PasswordReset.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/PasswordResetRequest.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/RevokeEmailValidation.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/SetOwner.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/SpamSet.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord/SpamUnset.pm
A   trunk/cgi-bin/LJ/User/UserlogRecord.pm
U   trunk/cgi-bin/LJ/User.pm
U   trunk/cgi-bin/LJ/Userpic.pm
U   trunk/cgi-bin/communitylib.pl
U   trunk/cgi-bin/ljemailgateway.pl
U   trunk/cgi-bin/ljprotocol.pl
U   trunk/cgi-bin/weblib.pl
U   trunk/htdocs/admin/userlog.bml
U   trunk/htdocs/changeemail.bml
U   trunk/htdocs/changepassword.bml
U   trunk/htdocs/community/leave.bml
U   trunk/htdocs/community/members.bml
U   trunk/htdocs/community/pending.bml
U   trunk/htdocs/delcomment.bml
U   trunk/htdocs/editjournal.bml
U   trunk/htdocs/editprivacy.bml
U   trunk/htdocs/editsyndi.bml
U   trunk/htdocs/friends/invite.bml
U   trunk/htdocs/inbox/index.bml
U   trunk/htdocs/inbox/markspam.bml
U   trunk/htdocs/lostinfo.bml
U   trunk/htdocs/manage/comments/index.bml
U   trunk/htdocs/manage/profile/index.bml
U   trunk/htdocs/support/see_request.bml
U   trunk/htdocs/talkmulti.bml
U   trunk/htdocs/tools/endpoints/changerelation.bml
U   trunk/htdocs/tools/endpoints/esn_inbox.bml
U   trunk/htdocs/tools/recent_emailposts.bml
Modified: trunk/bin/misc/set_comm_supermaintainer.pl
===================================================================
--- trunk/bin/misc/set_comm_supermaintainer.pl	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/bin/misc/set_comm_supermaintainer.pl	2012-08-07 15:03:40 UTC (rev 22589)
@@ -176,7 +176,9 @@
         my $user = $alive_maintainers[0];
         _log "Set user ".$user->user." as supermaintainer for ".$comm->user."\n";
         unless ($no_job) {
-            $comm->log_event('set_owner', { actiontarget => $user->{userid}, remote => $system });
+            LJ::User::UserlogRecord::SetOwner->create( $comm,
+                'ownerid' => $user->userid, 'remote' => $system );
+
             LJ::statushistory_add($comm, $system, 'set_owner', "LJ script set owner as ".$user->{user});
             LJ::set_rel($c_id, $user->{userid}, 'S')
                 or die "Can't set 'owner' status for community " . $comm->{'user'} . "\n";
@@ -189,7 +191,9 @@
         if ($u) {
             _log "Set user ".$u->user." as supermaintainer for ".$comm->user."\n";
             unless ($no_job) {
-                $comm->log_event('set_owner', { actiontarget => $u->{userid}, remote => $system });
+                LJ::User::UserlogRecord::SetOwner->create( $comm,
+                    'ownerid' => $u->userid, 'remote' => $system );
+
                 LJ::set_rel($c_id, $u->{userid}, 'S')
                     or die "Can't set 'owner' status for community " . $comm->{'user'} . "\n";
                 _send_email_to_sm ($comm, $u->{userid});
@@ -263,14 +267,18 @@
 sub _check_maintainers {
     my $comm = shift;
 
-    my $dbcr = LJ::get_cluster_reader($comm)
-        or die "Unable to get user cluster reader.";
-    $dbcr->{RaiseError} = 1;
+    my $create_records = LJ::User::Userlog->get_records(
+        $comm, 'action' => 'account_create' );
 
-    my $sth = $dbcr->prepare("SELECT action, actiontarget, remoteid FROM userlog WHERE userid = ? AND action = ? ORDER BY logtime ASC");
-    $sth->execute($comm->{userid}, 'account_create');
+    my $row;
+    if ( $create_records && @$create_records ) {
+        my ($record) = @$create_records;
+        $row = {
+            'action'   => $record->action,
+            'remoteid' => $record->remoteid,
+        };
+    }
 
-    my $row = $sth->fetchrow_hashref;
     if ($row) {
         my $u_id = $row->{'remoteid'};
         my $u = LJ::load_userid ($u_id);

Modified: trunk/bin/worker/find-sendmail-problems
===================================================================
--- trunk/bin/worker/find-sendmail-problems	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/bin/worker/find-sendmail-problems	2012-08-07 15:03:40 UTC (rev 22589)
@@ -30,11 +30,11 @@
                     if ($u->is_validated) {
                         $complete = 0;
                     } else {
-                        $u->log_event('revoke_validation',
-                            {
-                                email   => $email,
-                                message => $emails->{$email}->{message}
-                            });
+                        LJ::User::UserlogRecord::RevokeEmailValidation->create(
+                            $u,
+                            'email'   => $email,
+                            'message' => $emails->{$email}->{'message'},
+                        );
                         warn "Validation for user with id $uid and email <$email>".
                             " has been revoked.\n"
                                 if LJ::NewWorker::Manual::SendEmailErrorsFind->verbose;

Modified: trunk/bin/worker/friending_queue
===================================================================
--- trunk/bin/worker/friending_queue	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/bin/worker/friending_queue	2012-08-07 15:03:40 UTC (rev 22589)
@@ -93,7 +93,7 @@
     my $u = LJ::load_userid($uid);
     ## remove all 
     LJ::FriendQueue->empty($u->userid);
-    $u->log_event("flush_friends_activities_q");
+    LJ::User::UserlogRecord::FlushFriendsActivitiesQueue->create($u);
 
     $job->completed;
 }

Modified: trunk/cgi-bin/LJ/Console/Command/BanSet.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/BanSet.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/Console/Command/BanSet.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -53,8 +53,10 @@
         if scalar(@$banlist) >= ($LJ::MAX_BANS || 5000);
 
     LJ::set_rel($journal, $banuser, 'B');
-    $journal->log_event('ban_set', { actiontarget => $banuser->id, remote => $remote });
 
+    LJ::User::UserlogRecord::BanSet->create( $journal,
+        'bannedid' => $banuser->userid, 'remote' => $remote );
+
     LJ::run_hooks('ban_set', $journal, $banuser);
 
     return $self->print("User " . $banuser->user . " banned from " . $journal->user);

Modified: trunk/cgi-bin/LJ/Console/Command/BanUnset.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/BanUnset.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/Console/Command/BanUnset.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -85,8 +85,10 @@
     my ($remote, $journal, $banuser) = @_;
 
     LJ::clear_rel($journal, $banuser, 'B');
-    $journal->log_event('ban_unset', { actiontarget => $banuser->id, remote => $remote });
 
+    LJ::User::UserlogRecord::BanUnset->create( $journal,
+        'bannedid' => $banuser->userid, 'remote' => $remote );
+
     LJ::run_hooks('ban_unset', $journal, $banuser);
 
 

Modified: trunk/cgi-bin/LJ/Console/Command/SetOwner.pm
===================================================================
--- trunk/cgi-bin/LJ/Console/Command/SetOwner.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/Console/Command/SetOwner.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -49,7 +49,8 @@
         }
     }
 
-    $c->log_event('set_owner', { actiontarget => $u->{userid}, remote => $remote });
+    LJ::User::UserlogRecord::SetOwner->create( $journal,
+        'ownerid' => $u->userid, 'remote' => $remote );
 
     ## Close election poll if exist and open
     my $poll_id = $c->prop("election_poll_id");
@@ -67,8 +68,10 @@
     LJ::set_rel($c->{userid}, $u->{userid}, 'S');
     ## Set a new supermaintainer as maintainer too.
     LJ::set_rel($c->{userid}, $u->{userid}, 'A');
-    $c->log_event('maintainer_add', { actiontarget => $u->{userid}, remote => $remote });
 
+    LJ::User::UserlogRecord::MaintainerAdd->create( $journal,
+        'maintid' => $u->userid, 'remote' => $remote );
+
     $self->print("User '$user' setted as supermaintainer for '$comm'". $reason);
 
     return 1;

Modified: trunk/cgi-bin/LJ/Event/SecurityAttributeChanged.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/SecurityAttributeChanged.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/Event/SecurityAttributeChanged.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -23,6 +23,7 @@
         # $action == 1 -- deleted
         my $extra = (1 == $action) ? 'new=D&old=V' : 'new=V&old=D';
 
+        # TODO: change this to use LJ::User::Userlog
         my $dbr = LJ::get_cluster_reader($u);
         my $sth = $dbr->prepare(
             "SELECT logtime, ip".
@@ -168,6 +169,7 @@
     my $_get_params_from_logtime = sub {
         my ($u, $logtime) = @_;
 
+        # TODO: change this to use LJ::User::Userlog
         my $userid = $u->{userid};
         my $dbr = LJ::get_cluster_reader($u);
         my ($datetime, $remoteid, $ip, $uniq) = $dbr->selectrow_array(

Modified: trunk/cgi-bin/LJ/Message.pm
===================================================================
--- trunk/cgi-bin/LJ/Message.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/Message.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -818,8 +818,10 @@
     return 0 if $dbh->err;
 
     LJ::set_rel($self->_orig_u, $self->other_u, 'D');                                                                                                               
-    $self->_orig_u->log_event('spam_set', { actiontarget => $self->otherid });    
 
+    LJ::User::UserlogRecord::SpamSet->create( $self->_orig_u,
+        'spammerid' => $self->otherid );
+
     $self->_orig_u->ban_user($self->other_u);    
             
     return 1;

Modified: trunk/cgi-bin/LJ/NotificationInbox.pm
===================================================================
--- trunk/cgi-bin/LJ/NotificationInbox.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/NotificationInbox.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -601,12 +601,13 @@
     my $u = $self->u;
     my $interface = $opts{'interface'};
 
-    $u->log_event('inbox_massdel', {
-                         remote => $u,
-                         actiontarget => scalar @items,
-                         method => 'delete_all',
-                         view   => $view,  
-                         via    => $interface, });
+    LJ::User::UserlogRecord::InboxMassDelete->create( $u,
+        'remote' => $u,
+        'items'  => scalar @items,
+        'method' => 'delete_all',
+        'view'   => $view,
+        'via'    => $interface,
+    );
 
     # Delete items
     foreach my $item (@items) {

Modified: trunk/cgi-bin/LJ/Poll.pm
===================================================================
--- trunk/cgi-bin/LJ/Poll.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/Poll.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -841,7 +841,8 @@
             $self->close_poll;
 
             my $system = LJ::load_user('system');
-            $comm->log_event('set_owner', { actiontarget => $winner->{userid}, remote => $system });
+            LJ::User::UserlogRecord::SetOwner->create( $comm,
+                'ownerid' => $winner->userid, 'remote' => $system );
 
             LJ::statushistory_add($comm, $system, 'set_owner', "Poll set owner as ".$winner->{user});
 

Added: trunk/cgi-bin/LJ/User/Userlog.pm
===================================================================
--- trunk/cgi-bin/LJ/User/Userlog.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/Userlog.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,53 @@
+package LJ::User::Userlog;
+use strict;
+use warnings;
+
+use LJ::User::UserlogRecord;
+
+# opts: action, limit
+# returns an arrayref of LJ::User::UserlogRecord
+sub get_records {
+    my ( $class, $u, %opts ) = @_;
+
+    my $limit = int( $opts{'limit'} || 10_000 );
+
+    my $dbr = LJ::get_cluster_reader($u);
+    my $rows;
+
+    my $actions = $opts{'actions'};
+    if ( my $action = $opts{'action'} ) {
+        $actions = [$action];
+    }
+
+    if ($actions) {
+        my $sql_in = join( ',', ('?') x @$actions );
+        $rows = $dbr->selectall_arrayref(
+            "SELECT * FROM userlog WHERE userid=? AND action IN ($sql_in) " .
+            "ORDER BY logtime DESC LIMIT $limit",
+            { 'Slice' => {} }, $u->userid, @$actions,
+        );
+    } else {
+        $rows = $dbr->selectall_arrayref(
+            "SELECT * FROM userlog WHERE userid=? " .
+            "ORDER BY logtime DESC LIMIT $limit",
+            { 'Slice' => {} }, $u->userid,
+        );
+    }
+
+    my @records = map { LJ::User::UserlogRecord->new(%$_) } @$rows;
+
+    # hack: make account_create the last record (pretend that is's always the
+    # one with the least timestamp)
+    my ( @ret, @account_create_records );
+    while ( my $record = shift @records ) {
+        if ( $record->action eq 'account_create' ) {
+            push @account_create_records, $record;
+        } else {
+            push @ret, $record;
+        }
+    }
+    push @ret, @account_create_records;
+    return \@ret;
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/AccountCreate.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/AccountCreate.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/AccountCreate.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,10 @@
+package LJ::User::UserlogRecord::AccountCreate;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action      {'account_create'}
+sub description {'Account created'}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/AccountStatus.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/AccountStatus.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/AccountStatus.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,39 @@
+package LJ::User::UserlogRecord::AccountStatus;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'accountstatus'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'extra'} = {
+        'old' => delete $data{'old'},
+        'new' => delete $data{'new'},
+    };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $extra = $self->extra_unpacked;
+
+    my $old_status = $extra->{'old'};
+    my $new_status = $extra->{'new'};
+
+    if ( $old_status eq 'V' && $new_status eq 'D' ) {
+        return 'Account deleted';
+    }
+
+    if ( $old_status eq 'D' && $new_status eq 'V' ) {
+        return 'Account undeleted';
+    }
+
+    return "Account status changed ($old_status to $new_status)";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/BanSet.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/BanSet.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/BanSet.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,28 @@
+package LJ::User::UserlogRecord::BanSet;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'ban_set'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'bannedid'};
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetuserid = $self->actiontarget;
+    if ( my $targetu = LJ::load_userid($targetuserid) ) {
+        return 'Banned ' . $targetu->ljuser_display;
+    }
+
+    return "Banned a bogus user ($targetuserid)";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/BanUnset.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/BanUnset.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/BanUnset.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,28 @@
+package LJ::User::UserlogRecord::BanUnset;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'ban_unset'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'bannedid'};
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetuserid = $self->actiontarget;
+    if ( my $targetu = LJ::load_userid($targetuserid) ) {
+        return 'Unbanned ' . $targetu->ljuser_display;
+    }
+
+    return "Unbanned a bogus user ($targetuserid)";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/DeleteDelayedEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/DeleteDelayedEntry.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/DeleteDelayedEntry.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,29 @@
+package LJ::User::UserlogRecord::DeleteDelayedEntry;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'delete_delayed_entry'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'delayedid'};
+    $data{'extra'}        = { 'method' => delete $data{'method'} };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetid = $self->actiontarget;
+
+    my $extra    = $self->extra_unpacked;
+    my $method   = $extra->{'method'};
+
+    return "Deleted delayed entry $targetid via $method";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/DeleteEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/DeleteEntry.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/DeleteEntry.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,29 @@
+package LJ::User::UserlogRecord::DeleteEntry;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'delete_entry'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'ditemid'};
+    $data{'extra'}        = { 'method' => delete $data{'method'} };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetid = $self->actiontarget;
+
+    my $extra    = $self->extra_unpacked;
+    my $method   = $extra->{'method'};
+
+    return "Deleted entry $targetid via $method";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/DeleteUserpic.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/DeleteUserpic.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/DeleteUserpic.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,26 @@
+package LJ::User::UserlogRecord::DeleteUserpic;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'delete_userpic'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'extra'} = { 'picid' => delete $data{'picid'} };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $extra = $self->extra_unpacked;
+    my $picid = $extra->{'picid'};
+
+    return "Deleted userpic #$picid";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/EmailChange.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/EmailChange.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/EmailChange.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,26 @@
+package LJ::User::UserlogRecord::EmailChange;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'email_change'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'extra'} = { 'new' => delete $data{'new'} };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $extra     = $self->extra_unpacked;
+    my $new_email = $extra->{'new'};
+
+    return 'Email address changed to: ' . $self->_format_email($new_email);
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/EmailPost.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/EmailPost.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/EmailPost.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,10 @@
+package LJ::User::UserlogRecord::EmailPost;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action      {'emailpost'}
+sub description {'User posted via email gateway'}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/FlushFriendsActivitiesQueue.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/FlushFriendsActivitiesQueue.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/FlushFriendsActivitiesQueue.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,10 @@
+package LJ::User::UserlogRecord::FlushFriendsActivitiesQueue;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action      {'flush_friends_activities_q'}
+sub description {'Flushed the queue of friends activities'}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/FriendInviteSent.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/FriendInviteSent.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/FriendInviteSent.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,26 @@
+package LJ::User::UserlogRecord::FriendInviteSent;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'friend_invite_sent'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'extra'} = { 'extra' => delete $data{'recipient'} };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $extra     = $self->extra_unpacked;
+    my $recipient = $extra->{'extra'};
+
+    return "Friend invite sent to $recipient";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/InboxMassDelete.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/InboxMassDelete.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/InboxMassDelete.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,35 @@
+package LJ::User::UserlogRecord::InboxMassDelete;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'inbox_massdel'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'items'};
+
+    $data{'extra'} = {
+        'method' => delete $data{'method'},
+        'view'   => delete $data{'view'},
+        'via'    => delete $data{'via'},
+    };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $count  = $self->actiontarget;
+
+    my $extra  = $self->extra_unpacked;
+    my $method = $extra->{'via'};
+    my $view   = $extra->{'view'};
+
+    return "Mass-deleted $count inbox messages via '$method' in '$view'";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/MaintainerAdd.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/MaintainerAdd.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/MaintainerAdd.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,28 @@
+package LJ::User::UserlogRecord::MaintainerAdd;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'maintainer_add'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'maintid'};
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetuserid = $self->actiontarget;
+    if ( my $targetu = LJ::load_userid($targetuserid) ) {
+        return 'Added maintainer ' . $targetu->ljuser_display;
+    }
+
+    return "Added maintainer: a bogus user ($targetuserid)";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/MaintainerRemove.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/MaintainerRemove.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/MaintainerRemove.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,28 @@
+package LJ::User::UserlogRecord::MaintainerRemove;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'maintainer_remove'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'maintid'};
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetuserid = $self->actiontarget;
+    if ( my $targetu = LJ::load_userid($targetuserid) ) {
+        return 'Removed maintainer ' . $targetu->ljuser_display;
+    }
+
+    return "Removed maintainer: a bogus user ($targetuserid)";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/MassPrivacyChange.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/MassPrivacyChange.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/MassPrivacyChange.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,34 @@
+package LJ::User::UserlogRecord::MassPrivacyChange;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'mass_privacy_change'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'extra'} = {
+        's_security' => delete $data{'s_security'},
+        'e_security' => delete $data{'e_security'},
+        's_unixtime' => delete $data{'s_unixtime'},
+        'e_unixtime' => delete $data{'e_unixtime'},
+    };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $extra      = $self->extra_unpacked;
+    my $s_security = $extra->{'s_security'};
+    my $e_security = $extra->{'e_security'};
+
+    # TODO: parse out e_unixtime and s_unixtime and display?
+    # see: htdocs/editprivacy.bml, LJ::MassPrivacy
+    return "Entry privacy updated (from $s_security to $e_security)";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/PasswordChange.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/PasswordChange.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/PasswordChange.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,10 @@
+package LJ::User::UserlogRecord::PasswordChange;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action      {'password_change'}
+sub description {'User changed password'}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/PasswordReset.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/PasswordReset.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/PasswordReset.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,10 @@
+package LJ::User::UserlogRecord::PasswordReset;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action      {'password_reset'}
+sub description {'User reset password via lost password email'}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/PasswordResetRequest.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/PasswordResetRequest.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/PasswordResetRequest.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,46 @@
+package LJ::User::UserlogRecord::PasswordResetRequest;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'pwd_reset_req'}
+
+my %EmailStateMap = (
+    'A' => 'current, validated',
+    'T' => 'current, transitioning',
+    'N' => 'current, non-validated',
+    'P' => 'previously-validated',
+);
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'extra'} = {
+        'email'       => delete $data{'email'},
+        'email_state' => delete $data{'email_state'},
+        'time'        => delete $data{'time'},
+    };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $extra               = $self->extra_unpacked;
+
+    my $email               = $extra->{'email'};
+    my $email_display       = $self->_format_email($email);
+
+    my $email_state         = $extra->{'email_state'};
+    my $email_state_display = $EmailStateMap{$email_state} || $email_state;
+
+    my $time                = $extra->{'time'};
+    my $time_display        = scalar gmtime $time;
+
+    return "Requested a password reset email to $email_display; " .
+        "$email_state_display; added on $time_display.";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/RevokeEmailValidation.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/RevokeEmailValidation.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/RevokeEmailValidation.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,30 @@
+package LJ::User::UserlogRecord::RevokeEmailValidation;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'revoke_validation'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'extra'} = {
+        'email'   => delete $data{'email'},
+        'message' => delete $data{'message'},
+    };
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $extra   = $self->extra_unpacked;
+    my $email   = $extra->{'email'};
+    my $message = $extra->{'message'};
+
+    return "Validation of $email revoked: $message";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/SetOwner.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/SetOwner.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/SetOwner.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,28 @@
+package LJ::User::UserlogRecord::SetOwner;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'set_owner'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'ownerid'};
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetuserid = $self->actiontarget;
+    if ( my $targetu = LJ::load_userid($targetuserid) ) {
+        return 'Set owner to ' . $targetu->ljuser_display;
+    }
+
+    return "Set owner to bogus user ($targetuserid)";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/SpamSet.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/SpamSet.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/SpamSet.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,28 @@
+package LJ::User::UserlogRecord::SpamSet;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'spam_set'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'spammerid'};
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetuserid = $self->actiontarget;
+    if ( my $targetu = LJ::load_userid($targetuserid) ) {
+        return 'Marked ' . $targetu->ljuser_display . ' as spammer';
+    }
+
+    return "Marked a bogus user ($targetuserid) as spammer";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord/SpamUnset.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord/SpamUnset.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord/SpamUnset.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,28 @@
+package LJ::User::UserlogRecord::SpamUnset;
+use strict;
+use warnings;
+
+use base qw( LJ::User::UserlogRecord );
+
+sub action {'spam_unset'}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+
+    $data{'actiontarget'} = delete $data{'spammerid'};
+
+    return %data;
+}
+
+sub description {
+    my ($self) = @_;
+
+    my $targetuserid = $self->actiontarget;
+    if ( my $targetu = LJ::load_userid($targetuserid) ) {
+        return 'Unmarked ' . $targetu->ljuser_display . ' as spammer';
+    }
+
+    return "Unmarked a bogus user ($targetuserid) as spammer";
+}
+
+1;

Added: trunk/cgi-bin/LJ/User/UserlogRecord.pm
===================================================================
--- trunk/cgi-bin/LJ/User/UserlogRecord.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/User/UserlogRecord.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -0,0 +1,143 @@
+package LJ::User::UserlogRecord;
+use strict;
+use warnings;
+
+use base qw( Class::Accessor );
+__PACKAGE__->mk_accessors( qw(
+    userid u logtime actiontarget remoteid
+    remote ip uniq extra extra_unpacked
+) );
+
+my @SubclassesList = map { __PACKAGE__ . '::' . $_ } qw(
+    AccountCreate
+    AccountStatus
+    BanSet
+    BanUnset
+    CustomRatingsScreen
+    CustomRatingsUnscreen
+    DeleteDelayedEntry
+    DeleteEntry
+    DeleteUserpic
+    DeleteVGift
+    DeleteVGiftRow
+    EmailChange
+    EmailPost
+    FlushFriendsActivitiesQueue
+    FriendInviteSent
+    InboxMassDelete
+    MaintainerAdd
+    MaintainerRemove
+    MassPrivacyChange
+    PasswordChange
+    PasswordReset
+    PasswordResetRequest
+    PicsAlbumDelete
+    PicsPhotoDelete
+    PicsTagDelete
+    RevokeEmailValidation
+    S2StyleChange
+    SetOwner
+    SpamSet
+    SpamUnset
+    TryNBuyUpgrade
+    TwitterFailed
+    TwitterSkipped
+    TwitterSuccess
+    UserpicResizer
+);
+
+my %ActionToSubclassMap;
+
+foreach my $subclass (@SubclassesList) {
+    my $filename = $subclass . '.pm';
+    $filename =~ s{::}{/}g;
+
+    my $load_res = eval { require $filename; 1 };
+    unless ($load_res) {
+        warn "Couldn't load $subclass: $@";
+        next;
+    }
+
+    $ActionToSubclassMap{ $subclass->action } = $subclass;
+}
+
+sub new {
+    my ( $class, %data ) = @_;
+
+    $data{'u'}      = LJ::load_userid( $data{'userid'} );
+    $data{'remote'} = LJ::load_userid( $data{'remoteid'} )
+        if $data{'remoteid'};
+
+    if ( $data{'extra'} && $data{'extra'} ne '' ) {
+        my $extra_unpacked = {};
+        LJ::decode_url_string( $data{'extra'}, $extra_unpacked );
+        $data{'extra_unpacked'} = $extra_unpacked;
+    }
+
+    my $subclass = $ActionToSubclassMap{ $data{'action'} } || $class;
+    return bless \%data, $subclass;
+}
+
+sub action {''}
+
+sub description {
+    my ($self) = @_;
+
+    my $action = $self->{'action'};
+    my $ret    = "Unknown action $action";
+
+    if ( my $extra = $self->extra ) {
+        $ret .= " ($extra)";
+    }
+
+    return $ret;
+}
+
+sub _format_email {
+    my ( $self, $email ) = @_;
+
+    my $cmd = LJ::eurl("finduser $email");
+    return qq{<a href="$LJ::SITEROOT/admin/console/?prefill=$cmd">$email</a>};
+}
+
+# args: logtime, remote, remote_ip, remote_uniq, extra
+# all args are optional
+# returns void
+sub create {
+    my ( $class, $u, %data ) = @_;
+
+    my $action = $class->action;
+    die 'no action for LJ::User::UserlogRecord::create' unless $action;
+
+    %data = $class->translate_create_data(%data);
+
+    my $remoteid;
+    if ( my $remote = $data{'remote'} || LJ::get_remote() ) {
+        $remoteid = $remote->userid;
+    }
+
+    my $ip   = $data{'remote_ip'}   || LJ::get_remote_ip();
+    my $uniq = $data{'remote_uniq'} || eval { LJ::Request->notes('uniq') };
+
+    my $arg_extra = $data{'extra'} || {};
+    my $extra = LJ::encode_url_string($arg_extra);
+
+    my $dbh = LJ::get_cluster_master($u);
+    $dbh->do(
+        'INSERT INTO userlog ' .
+        'SET userid=?, logtime=?, action=?, actiontarget=?, ' .
+        'remoteid=?, ip=?, uniq=?, extra=?',
+        undef,
+        $u->userid, $data{'logtime'} || time, $action, $data{'actiontarget'},
+        $remoteid, $ip, $uniq, $extra,
+    );
+
+    return;
+}
+
+sub translate_create_data {
+    my ( $class, %data ) = @_;
+    return %data;
+}
+
+1;

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/User.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -32,6 +32,7 @@
 use LJ::TimeUtil;
 use LJ::User::InfoHistory;
 use LJ::User::PropStorage;
+use LJ::User::Userlog;
 use LJ::Response::CachedTemplate;
 use LJ::PersonalStats::DB;
 
@@ -96,7 +97,7 @@
                           'email' => $email, 'password' => $password, %LJ::USER_INIT });
 
     my $remote = LJ::get_remote();
-    $u->log_event('account_create', { remote => $remote });
+    LJ::User::UserlogRecord::AccountCreate->create( $u, 'remote' => $remote );
 
     while (my ($name, $val) = each %LJ::USERPROP_INIT) {
         $u->set_prop($name, $val);
@@ -218,7 +219,10 @@
     LJ::set_rel($u, $remote, "A");  # maintainer
 
     LJ::set_rel($u, $remote, "S");  # supermaintainer
-    $u->log_event('set_owner', { actiontarget => $remote->{userid}, remote => $remote });
+
+    LJ::User::UserlogRecord::SetOwner->create( $u,
+        'ownerid' => $remote->userid, 'remote' => $remote );
+
     LJ::statushistory_add($u, $remote, 'set_owner', "Set supermaintainer on created time as " . $remote->{user});
 
     LJ::set_rel($u, $remote, "M") if $opts{moderated} =~ /^[AF]$/; # moderator if moderated
@@ -1442,7 +1446,7 @@
 
     # record create information
     my $remote = LJ::get_remote();
-    $u->log_event('account_create', { remote => $remote });
+    LJ::User::UserlogRecord::AccountCreate->create( $u, 'remote' => $remote );
 
     return $u;
 }
@@ -4372,16 +4376,15 @@
 # in order from newest to oldest
 sub get_previous_statusvis {
     my $u = shift;
-    
-    my $extra = $u->selectcol_arrayref(
-        "SELECT extra FROM userlog WHERE userid=? AND action='accountstatus' ORDER BY logtime DESC",
-        undef, $u->{userid});
+
+    my $records = LJ::User::Userlog->get_records( $u,
+        'action' => 'accountstatus' );
+
     my @statusvis;
-    foreach my $e (@$extra) {
-        my %fields;
-        LJ::decode_url_string($e, \%fields, []);
-        push @statusvis, $fields{old};
+    foreach my $record (@$records) {
+        push @statusvis, $record->extra_unpacked->{'old'};
     }
+
     return @statusvis;
 }
 
@@ -4401,12 +4404,13 @@
             R        # renamed
                                 )$/x;
 
-    # log the change to userlog
-    $u->log_event('accountstatus', {
-            # remote looked up by log_event
-            old => $u->statusvis,
-            new => $statusvis,
-        }) if $u->clusterid; # purged user can get suspended, but have no clusterid at that moment
+    # log the change to userlog, but only in case we have a valid clusterid;
+    # this check addresses the case when an expunged user gets suspended
+    if ( $u->clusterid ) {
+        # remote looked up by create()
+        LJ::User::UserlogRecord::AccountStatus->create( $u,
+            'old' => $u->statusvis, 'new' => $statusvis );
+    }
 
     # do update
     my $ret = LJ::update_user($u, { statusvis => $statusvis,
@@ -5275,7 +5279,9 @@
     my ($u, $ban_u) = @_;
 
     my $remote = LJ::get_remote();
-    $u->log_event('ban_set', { actiontarget => $ban_u->id, remote => $remote });
+    LJ::User::UserlogRecord::BanSet->create( $u,
+        'bannedid' => $ban_u->userid, 'remote' => $remote );
+
     LJ::run_hooks('ban_set', $u, $ban_u);
 
     return LJ::set_rel($u->id, $ban_u->id, 'B');
@@ -5287,8 +5293,11 @@
     LJ::set_rel_multi(map { [$u->id, $_, 'B'] } @banlist);
 
     my $us = LJ::load_userids(@banlist);
+    my $remote = LJ::get_remote();
     foreach my $banuid (@banlist) {
-        $u->log_event('ban_set', { actiontarget => $banuid, remote => LJ::get_remote() });
+        LJ::User::UserlogRecord::BanSet->create( $u,
+            'bannedid' => $banuid, 'remote' => $remote );
+
         LJ::run_hooks('ban_set', $u, $us->{$banuid}) if $us->{$banuid};
     }
 
@@ -5301,8 +5310,11 @@
     LJ::clear_rel_multi(map { [$u->id, $_, 'B'] } @unbanlist);
 
     my $us = LJ::load_userids(@unbanlist);
+    my $remote = LJ::get_remote();
     foreach my $banuid (@unbanlist) {
-        $u->log_event('ban_unset', { actiontarget => $banuid, remote => LJ::get_remote() });
+        LJ::User::UserlogRecord::BanUnset->create( $u,
+            'bannedid' => $banuid, 'remote' => $remote );
+
         LJ::run_hooks('ban_unset', $u, $us->{$banuid}) if $us->{$banuid};
     }
 

Modified: trunk/cgi-bin/LJ/Userpic.pm
===================================================================
--- trunk/cgi-bin/LJ/Userpic.pm	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/LJ/Userpic.pm	2012-08-07 15:03:40 UTC (rev 22589)
@@ -761,7 +761,7 @@
     }
     $fail->() if $@;
 
-    $u->log_event('delete_userpic', { picid => $picid });
+    LJ::User::UserlogRecord::DeleteUserpic->create( $u, 'picid' => $picid );
 
     # best-effort on deleteing the blobs
     # TODO: we could fire warnings if they fail, then if $LJ::DIE_ON_WARN is set,

Modified: trunk/cgi-bin/communitylib.pl
===================================================================
--- trunk/cgi-bin/communitylib.pl	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/communitylib.pl	2012-08-07 15:03:40 UTC (rev 22589)
@@ -383,7 +383,13 @@
             $flag_set_owner_error = 1;
         } else {
             LJ::set_rel($cu->{userid}, $u->{userid}, $edgelist{$_}) if $args->{$_};
-            $cu->log_event('maintainer_add', { actiontarget => $u->{userid}, remote => LJ::load_userid($maintid) || $u }) if $_ eq 'admin' && $args->{$_};
+
+            if ( $_ eq 'admin' && $args->{$_} ) {
+                LJ::User::UserlogRecord::MaintainerAdd->create( $cu,
+                    'maintid' => $u->userid,
+                    'remote'  => LJ::load_userid($maintid) || $u,
+                );
+            }
         }
     }
 

Modified: trunk/cgi-bin/ljemailgateway.pl
===================================================================
--- trunk/cgi-bin/ljemailgateway.pl	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/ljemailgateway.pl	2012-08-07 15:03:40 UTC (rev 22589)
@@ -731,7 +731,7 @@
 {
     my ( $u, $info ) = @_;
     chomp $info->{s};
-    $u->log_event( 'emailpost', $info );
+    LJ::User::UserlogRecord::EmailPost->create( $u, 'extra' => $info );
     return;
 }
 

Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/ljprotocol.pl	2012-08-07 15:03:40 UTC (rev 22589)
@@ -906,7 +906,10 @@
         my $poster = $comment->poster;
         LJ::Talk::mark_comment_as_spam( $journal, $comment->jtalkid );
         LJ::set_rel($journal, $poster, 'D');
-        $journal->log_event('spam_set', { actiontarget => $poster->{userid}, remote => $u });
+
+        LJ::User::UserlogRecord::SpamSet->create( $journal,
+            'spammerid' => $poster->userid, 'remote' => $u );
+
         LJ::run_hook('auto_suspender_for_spam', $poster->{userid});
     }
     
@@ -3107,11 +3110,14 @@
                 $entry->delete();
                 $res->{delayedid} = $delayedid;
 
-                $uowner->log_event('delete_entry', {
-                                            remote => $u,
-                                            actiontarget => $delayedid,
-                                            method => 'protocol', })
-                        unless $flags->{noauth};
+                unless ( $flags->{'noauth'} ) {
+                    LJ::User::UserlogRecord::DeleteDelayedEntry->create(
+                        $uowner,
+                        'remote'    => $u,
+                        'delayedid' => $delayedid,
+                        'method'    => 'protocol',
+                    );
+                }
 
                 return $res;
             }
@@ -3207,12 +3213,13 @@
         # rely on them to log why they're deleting the entry if they need to.  that way we don't have
         # double entries, and we have as much information available as possible at the location the
         # delete is initiated.
-        $uowner->log_event('delete_entry', {
-                remote => $u,
-                actiontarget => ($itemid * 256 + $oldevent->{anum}),
-                method => 'protocol',
-            })
-            unless $flags->{noauth};
+        unless ( $flags->{'noauth'} ) {
+            LJ::User::UserlogRecord::DeleteEntry->create( $uowner,
+                'remote'  => $u,
+                'ditemid' => $itemid * 256 + $oldevent->{'anum'},
+                'method'  => 'protocol',
+            );
+        }
 
         # We must use property 'dupsig_post' in author of entry to be deleted, not in
         # remote user or journal owner!

Modified: trunk/cgi-bin/weblib.pl
===================================================================
--- trunk/cgi-bin/weblib.pl	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/cgi-bin/weblib.pl	2012-08-07 15:03:40 UTC (rev 22589)
@@ -2407,16 +2407,20 @@
     return "<script>Site.StatusvisMessage=\"" . LJ::Lang::ml("statusvis_message.$statusvis_full") . "\";</script>";
 }
 
-sub needlogin_redirect {
+sub needlogin_redirect_url {
     my $uri = LJ::Request->uri;
     if (my $qs = LJ::Request->args) {
         $uri .= "?" . $qs;
     }
     $uri = LJ::eurl($uri);
 
-    return LJ::Request->redirect("$LJ::SITEROOT/?returnto=$uri");
+    return "$LJ::SITEROOT/?returnto=$uri";
 }
 
+sub needlogin_redirect {
+    return LJ::Request->redirect( LJ::needlogin_redirect_url() );
+}
+
 sub get_body_class_for_service_pages {
     my %opts = @_;
 

Modified: trunk/htdocs/admin/userlog.bml
===================================================================
--- trunk/htdocs/admin/userlog.bml	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/htdocs/admin/userlog.bml	2012-08-07 15:03:40 UTC (rev 22589)
@@ -1,213 +1 @@
-<?page
-title=>User Log Viewer
-head<=
-<style>
-<!--
-td.logrow {
-    border: solid 1px rgb(230,230,230);
-    padding: 2px;
-    margin: 0px;
-}
-th.logrow {
-    border: solid 1px rgb(180,180,180);
-    padding: 2px;
-    margin: 0px;
-    text-weight: bold;
-}
--->
-</style>
-<=head
-body<=
-<?_code
-{
-    use strict;
-    use LJ::TimeUtil;
-
-    use vars qw($GET $POST);
-
-    my $remote = LJ::get_remote();
-    return "<?needlogin?>" unless $remote;
-
-    my $err = sub {
-        return "<?h1 Error h1?><?p $_[0] p?>";
-    };
-    my $can_view =  LJ::check_priv($remote, 'canview', '*') || 
-                    LJ::check_priv($remote, 'canview', 'userlog');
-    my $can_view_uniq = LJ::check_priv($remote, 'canview', 'uniq');
-    return $err->("You do not have the necessary privilege to view this page.")
-        unless $can_view || 
-                LJ::check_priv($remote, 'canview', 'userloglight') ||
-                $LJ::IS_DEV_SERVER;
-
-    my $user = LJ::canonical_username($POST{user} || $GET{user});
-
-    my $ret = <<FORM;
-<form method='post' action='userlog.bml'>
-Username: <input type='text' name='user' value='$user' maxlength='15' size='15' /> <input type='submit' value='View' />
-</form>
-FORM
-    return $ret unless $user;
-
-    my $u = LJ::load_user($user);
-    return $err->("User does not exist.")
-        unless $u;
-
-    return $err->("User is deleted and purged.")
-        if $u->statusvis eq "X";
-
-    my $dbcr = LJ::get_cluster_reader($u);
-    return $err->("Unable to get user cluster reader.")
-        unless $dbcr;
-
-    my $sth = $dbcr->prepare('SELECT * FROM userlog WHERE userid = ? ORDER BY logtime DESC LIMIT 10000');
-    $sth->execute($u->{userid});
-    return $err->("Database error: " . $sth->errstr)
-        if $sth->err;
-
-    $ret .= "<?p Latest log entries for " . LJ::ljuser($u) . ". p?>";
-    $ret .= "<table style='border: solid 1px black; width: 95%;'>\n";
-    $ret .= "<tr>";
-    $ret .= join('', map { "<th class='logrow'>$_</th>" } ("Date and Time", "Action", "Initiator", "IP Address", "Uniq Cookie"));
-    $ret .= "</tr>\n";
-
-    my $format_email = sub {
-        my ($email) = @_;
-
-        my $cmd = LJ::eurl("finduser $email");
-        return qq{
-            <a href="$LJ::SITEROOT/admin/console/?prefill=$cmd">$email</a>
-        };
-    };
-
-    # Hack, to display account_create event on last log row.
-    # logtime field in userlog table has type int(10) unsigned and
-    # events occured in less than one second after account creation
-    # can occasionaly be displayed before it in user log.
-    my $account_creation;
-    while (my $row = $sth->fetchrow_hashref || $account_creation) {
-        my $extra = {};
-        LJ::decode_url_string($row->{extra}, $extra);
-
-        my $action = "Action undefined for: $row->{action}";
-        if ($row->{action} eq 'delete_entry') {
-            $action = "Deleted entry $row->{actiontarget} via $extra->{method}";
-        } elsif ($row->{action} eq 'delete_delayed_entry') {
-            $action = "Deleted delayed entry $row->{actiontarget} via $extra->{method}";
-        } elsif ($row->{action} eq 'account_create') {
-            $action = "Account created";
-            unless ( $account_creation ) {
-                $account_creation = $row;
-                next;
-            }
-        } elsif ($row->{action} eq 'ban_set') {
-            my $u = LJ::load_userid($row->{actiontarget});
-            $action = "Banned " . LJ::ljuser($u) if $u;
-        } elsif ($row->{action} eq 'ban_unset') {
-            my $u = LJ::load_userid($row->{actiontarget});
-            $action = "Unbanned " . LJ::ljuser($u) if $u;
-        } elsif ($row->{action} eq 'inbox_massdel') {
-             $action = "User delete lots of messages ($row->{actiontarget} messages deleted)" .
-                       " via '$extra->{via}' for '$extra->{view}' view";
-        } elsif ($row->{action} eq 'friend_invite_sent') {
-            $action = "Friend invite sent to $extra->{extra}";
-        } elsif ($row->{action} eq 'maintainer_add') {
-            my $u = LJ::load_userid($row->{actiontarget});
-            $action = "Added maintainer " . LJ::ljuser($u) if $u;
-        } elsif ($row->{action} eq 'maintainer_remove') {
-            my $u = LJ::load_userid($row->{actiontarget});
-            $action = "Removed maintainer " . LJ::ljuser($u) if $u;
-        } elsif ($row->{action} eq 'emailpost') {
-            $action = "User posted via email gateway";
-        } elsif ($row->{action} eq 'set_owner') {
-            my $userid = $row->{actiontarget};
-            my $u = LJ::load_userid ($userid);
-            $action = "User ".LJ::ljuser($u)." set as supermaintainer";
-        } elsif ($row->{action} eq 'accountstatus') {
-            my $path = "$extra->{old} -> $extra->{new}";
-            $action = {
-                    'V -> D' => "Account deleted",
-                    'D -> V' => "Account undeleted",
-                }->{$path} || "Account status changed ($extra->{old} to $extra->{new})";
-        } elsif ($row->{action} eq 'password_change') {
-            $action = "User changed password";
-        } elsif ($row->{action} eq 'password_reset') {
-            $action = "User reset password via lost password email";
-        } elsif ($row->{action} eq 'email_change') {
-            $action = "Email address changed to: ".$format_email->($extra->{'new'});
-        } elsif ($row->{action} eq 'mass_privacy_change') {
-            $action = "Entry privacy updated (from $extra->{s_security} to $extra->{e_security})";
-            # TODO: parse out e_unixtime and s_unixtime and display?
-        } elsif ($row->{action} eq 'delete_userpic') {
-            $action = "Deleted userpic #$extra->{picid}";
-        } elsif ($row->{action} eq 'pwd_reset_req') {
-            my $email = $extra->{email};
-            $email = $format_email->($email);
-            my $email_state = {
-                'A' => 'current, validated',
-                'T' => 'current, transitioning',
-                'N' => 'current, non-validated',
-                'P' => 'previously-validated'
-            }->{$extra->{email_state}};
-            my $time = scalar(localtime($extra->{time}));
-            $action = "Requested a password reset email to $email; $email_state; added on $time.";
-        } elsif ($row->{action} eq 'spam_set') {
-            my $u = LJ::load_userid($row->{actiontarget});
-            $action = "Marked as spammer " . LJ::ljuser($u) if $u;
-        } elsif ($row->{action} eq 'spam_unset') {
-            my $u = LJ::load_userid($row->{actiontarget});
-            $action = "Unmarked as spammer " . LJ::ljuser($u) if $u;
-        } elsif (my $info = LJ::run_hook('userlog_rows', $row, $extra)) {
-            $action = $info;
-        } elsif ($row->{action} eq 'custom_ratings_screen') {
-            my $u = LJ::load_userid($row->{actiontarget});
-            $action = "Screened in customized rating " . LJ::ljuser($u) if $u;
-        } elsif ($row->{action} eq 'custom_ratings_unscreen') {
-            my $u = LJ::load_userid($row->{actiontarget});
-            $action = "Uncreened in customized rating " . LJ::ljuser($u) if $u;
-        } elsif ( $row->{'action'} eq 'photo_delete' ) {
-            $action = 'Deleted photo ' . $extra->{'id'} .
-                ' from album ' . $extra->{'album'};
-        } elsif ( $row->{'action'} eq 'album_delete' ) {
-            $action = 'Deleted album ' . $extra->{'id'} . ' with ' .
-                $extra->{'photos_count'} . ' photo(s)';
-        } elsif ( $row->{'action'} eq 'photo_tag_delete' ) {
-            $action = 'Deleted tag "' . $extra->{'id'} .
-                '" in the photo hosting';
-        } else {
-            $action = "Unknown action ($row->{action})";
-        }
-
-        my $time = LJ::TimeUtil->mysql_time($row->{logtime});
-
-        my $actor;
-        if ($row->{remoteid}) {
-            my $u = LJ::load_userid($row->{remoteid});
-            $actor = LJ::ljuser($u);
-        } else {
-            $actor = "<em>not recorded</em>";
-        }
-        
-        my ($ip, $uniq);
-        if (!$can_view) {
-            $ip = '***';
-        } else {
-            $ip = $row->{ip} || "<em>not recorded</em>"; 
-        }			
-        if (!$can_view && !$can_view_uniq) {
-               $uniq = '***';
-        } else {
-            $uniq = ($row->{uniq}) 
-                ? qq{<a href='$LJ::SITEROOT/admin/uniq.bml?what=$row->{uniq}'> $row->{uniq} </a>} 
-                : "<em>not recorded</em>";
-        }
-
-        $ret .= "<tr>" . join('', map { "<td class='logrow'>$_</td>" } ($time, $action, $actor, $ip, $uniq)) . "</tr>\n";
-        last if $account_creation;
-    }
-
-    $ret .= "</table>";
-    return $ret;
-}
-_code?>
-<=body
-page?>
+This page is not used anymore; see LJ::Controller::Admin::Userlog.

Modified: trunk/htdocs/changeemail.bml
===================================================================
--- trunk/htdocs/changeemail.bml	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/htdocs/changeemail.bml	2012-08-07 15:03:40 UTC (rev 22589)
@@ -128,7 +128,8 @@
         LJ::User::InfoHistory->add( $u,
             'email', $old_email, $u->email_status );
 
-        $u->log_event('email_change', { remote => $remote, new => $POST{'email'} });
+        LJ::User::UserlogRecord::EmailChange->create( $u,
+            'new' => $POST{'email'}, 'remote' => $remote );
 
         LJ::run_hooks('post_email_change',
                      {

Modified: trunk/htdocs/changepassword.bml
===================================================================
--- trunk/htdocs/changepassword.bml	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/htdocs/changepassword.bml	2012-08-07 15:03:40 UTC (rev 22589)
@@ -181,7 +181,8 @@
      my $oldval = Digest::MD5::md5_hex($u->password . "change");
      LJ::User::InfoHistory->add( $u, 'password', $oldval );
 
-     $u->log_event('password_change', { remote => $remote });
+     LJ::User::UserlogRecord::PasswordChange->create( $u,
+        'remote' => $remote );
 
      LJ::update_user($u, { password => $POST{'newpass1'} });
 

Modified: trunk/htdocs/community/leave.bml
===================================================================
--- trunk/htdocs/community/leave.bml	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/htdocs/community/leave.bml	2012-08-07 15:03:40 UTC (rev 22589)
@@ -46,8 +46,8 @@
 
             return $error->($ML{'.label.lastmaintainer'}) unless $othermaints;
 
-            # log maint removal to userlog
-            $cu->log_event('maintainer_remove', { actiontarget => $remote->id, remote => $remote });
+            LJ::User::UserlogRecord::MaintainerRemove->create( $cu,
+                'maintid' => $remote->userid, 'remote' => $remote );
         }
 
         # remove user from community's friends list

Modified: trunk/htdocs/community/members.bml
===================================================================
--- trunk/htdocs/community/members.bml	2012-08-07 14:19:34 UTC (rev 22588)
+++ trunk/htdocs/community/members.bml	2012-08-07 15:03:40 UTC (rev 22589)
@@ -116,7 +116,8 @@
         if ($new_sm_u && $new_sm_u->is_visible && $new_sm_u->can_manage($c)) {
             LJ::clear_rel($c->{userid}, $remote->{userid}, 'S');
             LJ::set_rel($c->{userid}, $new_sm_u->{userid}, 'S');
-            $c->log_event('set_owner', { actiontarget => $new_sm_u->{userid}, remote => $remote });
+            LJ::User::UserlogRecord::SetOwner->create( $c,
+                'ownerid' => $new_sm_u->userid, 'remote' => $remote );
             LJ::statushistory_add($c, $remote, 'set_owner', $new_sm_u->{user} . " set as owner by " . $remote->{user});
         }
     }
@@ -384,7 +385,8 @@
 
         foreach my $uid (keys %{$delete{admin} || {}}) {
             # log maintainer deletions
-            $c->log_event('maintainer_remove', { actiontarget => $uid, remote => $remote });
+            LJ::User::UserlogRecord::MaintainerRemove->create( $c,
+                'maintid' => $uid, 'remote' => $remote );
 
             my $delmaintu = $changedmaintainers->{$uid};
             next unless $delmaintu;
@@ -461,7 +463,8 @@
 
         foreach my $uid (keys %{$add{admin} || {}}) {
             # log maintainer additions
-            $c->log_event('maintainer_add', { actiontarget => $uid, remote => $remote });
+            LJ::User::UserlogRecord::MaintainerAdd->create( $c,
+                'maintid' => $uid, 'remote' => $remote );
 
             my $newmaintu = $changedmaintainers->{$uid};
             next unless $newmaintu;

Modified: trunk/h...
 (truncated)
Tags: ailyin, andy, bml, livejournal, pl, pm
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