OSDN Git Service

Model::Moderation: fix to run
authorhylom <hylom@users.sourceforge.jp>
Fri, 28 Oct 2016 19:03:34 +0000 (04:03 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 28 Oct 2016 19:03:34 +0000 (04:03 +0900)
src/newslash_web/lib/Newslash/Model/Moderations.pm

index 0b7a4ea..ed57cf9 100644 (file)
@@ -1,6 +1,8 @@
 package Newslash::Model::Moderations;
 use Newslash::Model::Base -base;
 
+use Data::Dumper;
+
 # parameters
 
 my $karma_posting_penalty_style = 0;
@@ -47,18 +49,17 @@ sub score_for_comment_post {
     my ($self, $user) = @_;
 
     my $users = $self->new_instance_of("Newslash::Model::Users");
-    my $user_comment = $users->select(uid => $user->{uid}, 'comments');
-    my $user_info = $users->select(uid => $user->{uid}, 'info');
+    my $user_comment = $users->select(uid => $user->{uid}, target => 'comments');
+    my $user_info = $users->select(uid => $user->{uid}, target => 'info');
 
     my $pts = $user_comment->{defaultpoints};
     my $karma_bonus = 'no';
     my $tweak = 0;
 
-
     if ($user->{login}) {
         my $karma = $user_info->{karma};
         if ($karma_posting_penalty_style == 0) {
-            $pts-- if $karam < 0;
+            $pts-- if $karma < 0;
             $pts-- if $karma < $badkarma;
         }
         else {
@@ -117,18 +118,33 @@ target user's uid
 sub undo_moderation {
     my ($self, $type, $id, $uid) = @_;
     # type = sid or stoid or discussion_id
+    my $sid; # sid is discussion_id!
+
+    if ($type eq 'sid'
+        || $type eq 'stoid') {
+        my $stories = $self->new_instance_of("Newslash::Model::Stories");
+        my $story = $stories->select($type => $id);
+        $sid = $story->{discussion};
+    }
+    elsif ($type eq 'discussion_id') {
+        $sid = $id;
+    }
+    else {
+        return;
+    }
 
     my $dbh = $self->connect_db({AutoCommit => 0,});
     my $sql = <<"EOSQL";
 SELECT id, cid, val, active, cuid, reason FROM moderatorlog
-  WHERE sid = ? AND uid = ?
+  WHERE ? = ? AND uid = ?
 EOSQL
     my $sth = $dbh->prepare($sql);
-    $sth->execute($sid, $uid);
+    $sth->execute($type, $id, $uid);
     my $target = $sth->fetchall_arrayref({});
 
     for my $mod (@$target) {
         next if !$mod->{active};
+        my $cid = $mod->{cid};
 
         $self->removeModTags($uid, $cid);
 
@@ -217,7 +233,7 @@ target id
 
 sub removeModTags {
     my($self, $uid, $cid) = @_;
-    my $globjid = $self->new_instance_of("Newslash::Model::Globjids");
+    my $globjids = $self->new_instance_of("Newslash::Model::Globjids");
 
     my $comment_globjid = $globjids->getGlobjidFromTargetIfExists('comments', $cid);
     if ($comment_globjid) {
@@ -235,7 +251,7 @@ sub getReasons {
     my $rs = $sth->fetchall_hashref('id');
     $dbh->disconnect;
 
-    if (!%rs) {
+    if (!%$rs) {
         return;
     }
     #my $table_cache = "_reasons_cache";