/
hitparade_commentcount_fix.pl
executable file
·86 lines (67 loc) · 2.37 KB
/
hitparade_commentcount_fix.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2005 by Open Source Technology Group. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id$
use strict;
use vars qw( %task );
use File::Basename;
use Slash;
use Slash::DB;
use Slash::Display;
use Slash::Utility;
use Getopt::Std;
(my $VERSION) = ' $Revision$ ' =~ /\$Revision:\s+([^\s]+)/;
#my $PROGNAME = basename($0);
my $PROGNAME = 'hitparade_commentcount_fix.pl';
$task{$PROGNAME}{timespec} = '0,5,10,15,20,25,30,35,40,45,50,55 * * * *';
# Handles mail and administrivia necessary for RECENTLY expired users.
$task{$PROGNAME}{code} = sub {
my($virtual_user, $constants, $slashdb, $user) = @_;
my $counts = $slashdb->sqlSelectAll('sid,commentcount', 'discussions', " sid != ''");
for(@$counts) {
$slashdb->sqlDo(" UPDATE stories SET commentcount='$_->[1]' WHERE sid='$_->[0]'");
}
my $hits = $slashdb->sqlSelectAll('discussions.id,threshold,count,sid', 'discussion_hitparade, discussions', " discussions.id=discussion_hitparade.discussion AND sid != '' AND type ='open' ");
my $hitparade;
my $sid2discussion;
for(@$hits){
$hitparade->{$_->[0]}{$_->[1]} = $_->[2];
$sid2discussion->{$_->[0]} = $_->[3]
if $_->[3];
}
for (keys %$hitparade) {
my $discussion = $hitparade->{$_};
my $sid = $sid2discussion->{$_};
# Ok, it's a hack, move along, this is not the code you are looking for -Brian
my $string = join (",",
map { $discussion->{$_} || 0 }
($constants->{comment_minscore} .. $constants->{comment_maxscore})
);
$slashdb->sqlDo(" UPDATE discussions SET hitparade ='$string' WHERE sid='$_'");
$slashdb->sqlDo(" UPDATE stories SET hitparade ='$string' WHERE sid='$sid'")
if $sid;
}
};
# Standalone code.
if ($0 =~ /$PROGNAME$/) {
my(%opts);
getopts('hu:v', \%opts);
if (exists $opts{h} || !exists $opts{u}) {
print <<EOT;
Usage: $PROGNAME -u [virtual user]
This program rebuilds the story and discussion tables data for
hitparade and commentcount. This is normally taken care of
by slashd so odds are you will never need this program.
EOT
exit 1;
} elsif (exists $opts{v}) {
print "(slashd task) $PROGNAME $VERSION.\n\n";
}
createEnvironment($opts{u});
my $constants = getCurrentStatic();
my $slashdb = getCurrentDB();
# Calls the code defined above.
$task{$PROGNAME}{code}->($opts{u}, $constants, $slashdb);
}
1;