]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/Factoids.pl
- half-assed attempt to move over to new sql functions
[infobot.git] / src / Modules / Factoids.pl
index f00bdaabc2de9216a50eb29050ca2dea626151d5..5da983d4357c6e5fafca4e1d002526f5e1e46645 100644 (file)
@@ -5,7 +5,10 @@
 #     Splitted: SQLExtras.pl
 #
 
-if (&IsParam("useStrict")) { use strict; }
+use strict;
+
+use vars qw($dbh $who);
+use vars qw(%param);
 
 ###
 # Usage: &CmdFactInfo($faqtoid, $query);
@@ -19,7 +22,9 @@ sub CmdFactInfo {
        return;
     }
 
-    my %factinfo = &dbGetColNiceHash("factoids", "*", "factoid_key=".&dbQuote($faqtoid));
+    my %factinfo = &sqlSelectRowHash("factoids", "*",
+       { factoid_key => $faqtoid }
+    );
 
     # factoid does not exist.
     if (scalar (keys %factinfo) <= 1) {
@@ -49,7 +54,7 @@ sub CmdFactInfo {
        if ($time) {
            if (time() - $time > 60*60*24*7) {
                my $days = int( (time() - $time)/60/60/24 );
-               $string .= " at \037". scalar(localtime $time). "\037" .
+               $string .= " at \037". scalar(gmtime $time). "\037" .
                                " ($days days)";
            } else {
                $string .= " ".&Time2String(time() - $time)." ago";
@@ -60,28 +65,23 @@ sub CmdFactInfo {
     }
 
     # modified:
-#    if ($factinfo{'modified_by'}) {
-#      $string = "last modified";
-#
-#      my $time = $factinfo{'modified_time'};
-#      if ($time) {
-#          if (time() - $time > 60*60*24*7) {
-#              $string .= " at \037". scalar(localtime $time). "\037";
-#          } else {
-#              $string .= " ".&Time2String(time() - $time)." ago";
-#          }
-#      }
-#
-#      my @x;
-#      foreach (split ",", $factinfo{'modified_by'}) {
-#          /\!/;
-#          push(@x, $`);
-#      }
-#      $string .= "by ".&IJoin(@x);
-#
-#      $i++;
-#      push(@array,$string);
-#    }
+    # disabled for the time being... it's misleading/useless info.
+    if (0 && $factinfo{'modified_by'}) {
+       $string = "last modified";
+
+       my $time = $factinfo{'modified_time'};
+       if ($time) {
+           if (time() - $time > 60*60*24*7) {
+               $string .= " at \037". scalar(gmtime $time). "\037";
+           } else {
+               $string .= " ".&Time2String(time() - $time)." ago ";
+           }
+       }
+
+       $string .= " by ".(split ",", $factinfo{'modified_by'})[0];
+
+       push(@array,$string);
+    }
 
     # requested:
     if ($factinfo{'requested_by'}) {
@@ -95,24 +95,24 @@ sub CmdFactInfo {
                $string .= "\002". $requested_count. "\002 ".
                        &fixPlural("time", $requested_count);
            }
-       }
 
-       $string .= ", " if ($string ne "");
+           my $requested_by = $factinfo{'requested_by'};
+           $requested_by =~ /\!/;
+           $string .= "last by $`";
 
-       my $requested_by = $factinfo{'requested_by'};
-       $requested_by =~ /\!/;
-       $string .= "last by $`";
-
-       my $requested_time = $factinfo{'requested_time'};
-       if ($requested_time) {
-           if (time() - $requested_time > 60*60*24*7) {
-               $string .= " at \037". scalar(localtime $requested_time). "\037";
-           } else {
-               $string .= ", ".&Time2String(time() - $requested_time)." ago";
+           my $requested_time = $factinfo{'requested_time'};
+           if ($requested_time) {
+               if (time() - $requested_time > 60*60*24*7) {
+                   $string .= " at \037". scalar(localtime $requested_time). "\037";
+               } else {
+                   $string .= ", ".&Time2String(time() - $requested_time)." ago";
+               }
            }
+       } else {
+           $string  = "has not been requested yet";
        }
 
-       push(@array,$string);
+       push(@array, $string);
     }
 
     # locked:
@@ -671,6 +671,7 @@ sub CmdFactStats {
 
     } elsif ($type =~ /^(2|too)long$/i) {
        my @list;
+       my $query;
 
        # factoid_key.
        $query = "SELECT factoid_key FROM factoids WHERE length(factoid_key) >= $param{'maxKeySize'}";
@@ -679,14 +680,16 @@ sub CmdFactStats {
        while (my @row = $sth->fetchrow_array) {
            push(@list,$row[0]);
        }
+       $sth->finish;
 
        # factoid_value.
-       my $query = "SELECT factoid_key,factoid_value FROM factoids WHERE length(factoid_value) >= $param{'maxDataSize'}";
+       $query = "SELECT factoid_key,factoid_value FROM factoids WHERE length(factoid_value) >= $param{'maxDataSize'}";
        $sth = $dbh->prepare($query);
        $sth->execute;
        while (my @row = $sth->fetchrow_array) {
            push(@list,sprintf("\002%s\002 - %s", length($row[1]), $row[0]));
        }
+       $sth->finish;
 
        if (scalar @list == 0) {
            return "good. no factoids exceed length.";