diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm
index 7cc6a416d..508093f73 100644
--- a/lib/WebGUI.pm
+++ b/lib/WebGUI.pm
@@ -57,21 +57,25 @@ sub page {
tie %hash, 'Tie::CPHash';
%hash = (%{$wobject},%{$extra});
$wobject = \%hash;
- if (${$wobject}{pageId} != $session{page}{pageId} && ${$wobject}{pageId} != 2) {
- $wobjectOutput = WebGUI::International::get(417);
- WebGUI::ErrorHandler::warn($session{user}{username}." [".$session{user}{userId}."] attempted to access wobject [".$session{form}{wid}."] on page '".$session{page}{title}."' [".$session{page}{pageId}."].");
- } else {
- $cmd = "WebGUI::Wobject::".${$wobject}{namespace};
- $w = $cmd->new($wobject);
- $cmd = "www_".$session{form}{func};
- $wobjectOutput = $w->$cmd;
- }
- # $wobjectOutput = WebGUI::International::get(381); # bad error
} else {
- WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or corrupt, but was requested by $session{user}{username} [$session{user}{userId}].");
+ WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or corrupt, but was requested "
+ ."by $session{user}{username} [$session{user}{userId}].");
$wobject = ();
}
}
+ if ($wobject) {
+ if (${$wobject}{pageId} != $session{page}{pageId} && ${$wobject}{pageId} != 2) {
+ $wobjectOutput = WebGUI::International::get(417);
+ WebGUI::ErrorHandler::warn($session{user}{username}." [".$session{user}{userId}."] attempted to access wobject ["
+ .$session{form}{wid}."] on page '".$session{page}{title}."' [".$session{page}{pageId}."].");
+ } else {
+ $cmd = "WebGUI::Wobject::".${$wobject}{namespace};
+ $w = $cmd->new($wobject);
+ $cmd = "www_".$session{form}{func};
+ $wobjectOutput = $w->$cmd;
+ }
+ # $wobjectOutput = WebGUI::International::get(381); # bad error
+ }
}
if ($operationOutput ne "") {
$contentHash{0} = $operationOutput;
diff --git a/sbin/Hourly/ExpireSessions.pm b/sbin/Hourly/ExpireSessions.pm
new file mode 100644
index 000000000..d3e4d7212
--- /dev/null
+++ b/sbin/Hourly/ExpireSessions.pm
@@ -0,0 +1,22 @@
+package Hourly::ExpireSessions;
+
+#-------------------------------------------------------------------
+# WebGUI is Copyright 2001-2002 Plain Black Software.
+#-------------------------------------------------------------------
+# Please read the legal notices (docs/legal.txt) and the license
+# (docs/license.txt) that came with this distribution before using
+# this software.
+#-------------------------------------------------------------------
+# http://www.plainblack.com info@plainblack.com
+#-------------------------------------------------------------------
+
+use strict;
+use WebGUI::SQL;
+
+#-------------------------------------------------------------------
+sub process {
+ WebGUI::SQL->write("delete from userSession where expires<".time(),$_[0]);
+}
+
+1;
+
diff --git a/sbin/Hourly/SyndicatedContent.pm b/sbin/Hourly/SyndicatedContent.pm
new file mode 100644
index 000000000..e4888c087
--- /dev/null
+++ b/sbin/Hourly/SyndicatedContent.pm
@@ -0,0 +1,73 @@
+package Hourly::SyndicatedContent;
+
+#-------------------------------------------------------------------
+# WebGUI is Copyright 2001-2002 Plain Black Software.
+#-------------------------------------------------------------------
+# Please read the legal notices (docs/legal.txt) and the license
+# (docs/license.txt) that came with this distribution before using
+# this software.
+#-------------------------------------------------------------------
+# http://www.plainblack.com info@plainblack.com
+#-------------------------------------------------------------------
+
+use HTTP::Request;
+use LWP::UserAgent;
+use strict;
+use WebGUI::SQL;
+use RSSLite;
+
+#-------------------------------------------------------------------
+sub getRSS {
+ my ($userAgent, $request, $response, $content, %result);
+ $userAgent = new LWP::UserAgent;
+ $request = new HTTP::Request (GET => $_[0]);
+ $response = $userAgent->request($request);
+ $content = $response->content;
+ parseXML(\%result, \$content);
+ return %result;
+}
+
+#-------------------------------------------------------------------
+sub generateHTML {
+ my (%rss, $html, $item);
+ %rss = @_;
+ $html = $rss{title};
+ $html = ''.$html.'' if ($rss{link});
+ $html = '
'.$html.'
';
+ $html .= $rss{description}.'' if ($rss{description});
+ foreach $item (@{$rss{items}}) {
+ $html .= '
';
+ if ($item->{link}) {
+ $html .= ''.$item->{title}.'';
+ } else {
+ $html .= $item->{title};
+ }
+ $html .= ' - '.$item->{description} if ($item->{description});
+ $html .= '
';
+ }
+ return ($html);
+}
+
+#-------------------------------------------------------------------
+sub process {
+ my ($sth, @data, %rss, $html);
+ $sth = WebGUI::SQL->read("select wobject.wobjectId, SyndicatedContent.rssURL, SyndicatedContent.content
+ from wobject,SyndicatedContent where wobject.wobjectId=SyndicatedContent.wobjectId and wobject.pageId<>3",$_[0]);
+ while (@data = $sth->array) {
+ %rss = getRSS($data[1]);
+ $html = generateHTML(%rss);
+ if ($html ne "") {
+ WebGUI::SQL->write("update SyndicatedContent set content=".$_[0]->quote($html).", lastFetched=".time()."
+ where wobjectId=$data[0]",$_[0]);
+ } elsif (substr($data[2],6) ne "Unable" && substr($data[2],7) ne "Not yet") {
+ # then just leave the existing content in place
+ } else {
+ WebGUI::SQL->write("update SyndicatedContent set content='Unable to fetch content. Perhaps the RSS is improperly formated.',
+ lastFetched=".time()." where wobjectId=$data[0]",$_[0]);
+ }
+ }
+ $sth->finish;
+}
+
+1;
+
diff --git a/sbin/runHourly.pl b/sbin/runHourly.pl
index 6e29bb112..76c580a26 100644
--- a/sbin/runHourly.pl
+++ b/sbin/runHourly.pl
@@ -8,78 +8,71 @@
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
+
+our $webguiRoot;
+
BEGIN {
- unshift (@INC, "../lib");
+ $webguiRoot = $ARGV[0] || "..";
+ unshift (@INC, $webguiRoot."/lib");
}
use DBI;
-use HTTP::Request;
-use LWP::UserAgent;
-use strict;
+use strict qw(subs vars);
use Data::Config;
-use WebGUI::SQL;
-use RSSLite;
-my $config = new Data::Config '../etc/WebGUI.conf';
-our $dbh = DBI->connect($config->param('dsn'), $config->param('dbuser'), $config->param('dbpass'));
-deleteExpiredSessions();
-updateSyndicatedContent();
-
-$dbh->disconnect();
-
-#-------------------------------------------------------------------
-sub deleteExpiredSessions {
- WebGUI::SQL->write("delete from userSession where expires<".time(),$dbh);
+my (@files, $cmd, $namespace, $i, $file, $confdir, @plugins, $plugin, $plugdir);
+if ($^O =~ /Win/i) {
+ $confdir = $webguiRoot."\\etc\\";
+ $plugdir = $webguiRoot."\\sbin\\Hourly\\";
+} else {
+ $confdir = $webguiRoot."/etc/";
+ $plugdir = $webguiRoot."/sbin/Hourly/";
}
-#-------------------------------------------------------------------
-sub getRSS {
- my ($userAgent, $request, $response, $content, %result);
- $userAgent = new LWP::UserAgent;
- $request = new HTTP::Request (GET => $_[0]);
- $response = $userAgent->request($request);
- $content = $response->content;
- parseXML(\%result, \$content);
- return %result;
+if (opendir (PLUGDIR,$plugdir)) {
+ @files = readdir(PLUGDIR);
+ foreach $file (@files) {
+ if ($file =~ /(.*?)\.pm$/) {
+ $namespace = $1;
+ $cmd = "use Hourly::".$namespace;
+ eval($cmd);
+ $plugins[$i] = "Hourly::".$namespace."::process";
+ $i++;
+ }
+ }
+ closedir(PLUGDIR);
+} else {
+ print "Can't open $plugdir.\n";
+ exit;
}
-#-------------------------------------------------------------------
-sub generateHTML {
- my (%rss, $html, $item);
- %rss = @_;
- $html = $rss{title};
- $html = ''.$html.'' if ($rss{link});
- $html = ''.$html.'
';
- $html .= $rss{description}.'' if ($rss{description});
- foreach $item (@{$rss{items}}) {
- $html .= '
';
- if ($item->{link}) {
- $html .= ''.$item->{title}.'';
- } else {
- $html .= $item->{title};
- }
- $html .= ' - '.$item->{description} if ($item->{description});
- $html .= '
';
- }
- return ($html);
-}
-
-#-------------------------------------------------------------------
-sub updateSyndicatedContent {
- my ($sth, @data, %rss, $html);
- $sth = WebGUI::SQL->read("select wobject.wobjectId, SyndicatedContent.rssURL, SyndicatedContent.content from wobject,SyndicatedContent where wobject.wobjectId=SyndicatedContent.wobjectId and wobject.pageId<>3",$dbh);
- while (@data = $sth->array) {
- %rss = getRSS($data[1]);
- $html = generateHTML(%rss);
- if ($html ne "") {
- WebGUI::SQL->write("update SyndicatedContent set content=".$dbh->quote($html).", lastFetched=".time()." where wobjectId=$data[0]",$dbh);
- } elsif (substr($data[2],6) ne "Unable" && substr($data[2],7) ne "Not yet") {
- # then just leave the existing content in place
- } else {
- WebGUI::SQL->write("update SyndicatedContent set content='Unable to fetch content. Perhaps the RSS is improperly formated.', lastFetched=".time()." where wobjectId=$data[0]",$dbh);
+if (opendir (CONFDIR,$confdir)) {
+ @files = readdir(CONFDIR);
+ foreach $file (@files) {
+ if ($file =~ /(.*?)\.conf$/ && $file ne "some_other_site.conf") {
+ my ($config);
+ $config = new Data::Config $confdir.$file;
+ unless ($config->param('dsn') eq "") {
+ my $dbh;
+ unless (eval {$dbh = DBI->connect($config->param('dsn'),$config->param('dbuser'),$config->param('dbpass'))}) {
+ print "Can't connect to ".$config->param('dsn')." with info provided. Skipping.\n";
+ } else {
+ foreach $plugin (@plugins) {
+ &$plugin($dbh);
+ }
+ $dbh->disconnect();
+ }
+ } else {
+ print "$file has some problems. Skipping\n";
+ }
}
}
- $sth->finish;
+ closedir(CONFDIR);
+} else {
+ print "Can't open $confdir.\n";
+ exit;
}
+
+
diff --git a/sbin/testEnvironment.pl b/sbin/testEnvironment.pl
index b0b0aa7a3..b96946e08 100644
--- a/sbin/testEnvironment.pl
+++ b/sbin/testEnvironment.pl
@@ -17,7 +17,7 @@
our $webguiRoot;
BEGIN {
- $webguiRoot = $ARGV[0] || "/data/WebGUI";
+ $webguiRoot = $ARGV[0] || "..";
unshift (@INC, $webguiRoot."/lib");
}