Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Confusing problem with cronjob and subscriptions

Quote Reply
Confusing problem with cronjob and subscriptions
To send the daily subscription notifications a daily cronjob is configured:

00 6 * * * /%PATH_TO_BOARD%/admin/cron/subscribe.pl --send

But it dies with
GT::SQL::Relation (822): Unknown method 'fetchrow_arrayref' called at /%PATH_TO_BOARD%/admin/GForum/Subscribe.pm line 34

After a little debugging i found out, that in Subscribe.pm after

my $sth = $DB->table('ForumSubscriber', 'User', 'Forum', 'Category')->select;

$sth is still not defined. But $DB->table('ForumSubscriber', 'User', 'Forum', 'Category') is defined.

And to complete my confusion: When i start "subscribe.pl --send" manually, everything work fine.

Do anybody have some help for me?

PS: Sorry for my maybe not so good english.

Last edited by:

schubiman: Dec 28, 2004, 4:12 AM
Quote Reply
Re: [schubiman] Confusing problem with cronjob and subscriptions In reply to
I'm guessing the instances of %PATH_TO_BOARD% actually show as your path? If not, you need to change them to it <G>

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Confusing problem with cronjob and subscriptions In reply to
Of course it does Smile

Otherwise the manually start of subscribe.pl wouldn't work.
Quote Reply
Re: [schubiman] Confusing problem with cronjob and subscriptions In reply to
Mmm.. what do the first few lines of admin/GForum/Subscribe.pm, and subscribe.pl look like? Are there any lines that look like;

use lib '....';

?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Confusing problem with cronjob and subscriptions In reply to
subscribe.pl:

Code:

use lib '/forum/admin';
use GForum qw/$CFG/;
use GForum::Subscribe;
use Getopt::Long;
GForum::init('/forum/admin');
my %opt;
if ($ENV{REQUEST_METHOD}) {
print "Content-type: text/html\n\n";
print "This script can only be run from shell/command prompt.";
}
else {
GetOptions(
'help' => \$opt{help},
'send' => \$opt{send},
'debug' => \$opt{debug},
'file-debug=s' => \$opt{debug_file}
);
if ($opt{send}) {
GForum::Subscribe::send_all(@opt{'debug', 'debug_file'});
}
else {
usage();
}
}
...


Subscribe.pm:
Code:

package GForum::Subscribe;
use strict;
use vars qw/%TPL_CACHE $DEBUG $DEBUG_FILE $DEBUG_FH/;
use GForum qw/:user $CFG $DB/;
use GForum::Authenticate;
use GForum::Convert;
use GForum::Post;
use GForum::Forum;
use GForum::Template;
use GT::Mail;
use GT::Mail::Editor;
sub send_all {
%TPL_CACHE = ();
($DEBUG, $DEBUG_FILE) = @_;
my $sth = $DB->table('ForumSubscriber', 'User', 'Forum', 'Category')->select;
my $PostUser = $DB->table('Post' => 'User');
while (my $row = $sth->fetchrow_hashref) { # Loops through each forum for each forum subscriber
debug("Checking forum $row->{forum_id} ($row->{forum_name}) for user $row->{user_id} ($row->{user_username})") if $DEBUG;
unless (GForum::Authenticate::auth(enabled_user => $row)) {
debug("Skipping: User not enabled/validated") if $DEBUG;
next;
}
GForum::Forum::normalize($row);
$GForum::TEMPLATE_SET = $row->{user_template} || $CFG->{default_template_set} || 'default'; # GForum::Template needs this
my $pc = GT::SQL::Condition->new(
forum_id_fk => '=' => $row->{forum_id},
post_moved => IS => undef,
post_time => '>' => ($row->{subsc_last} || $row->{subsc_time})
);
my $num_posts = $DB->table('Post')->count($pc);
debug("Found $num_posts posts in this forum") if $DEBUG;
$num_posts or next;
$PostUser->select_options("ORDER BY post_time DESC");
$PostUser->select_options("LIMIT $CFG->{subscribe_email_max_posts}") if $CFG->{subscribe_email_max_posts};
my $psth = $PostUser->select(left_join => $pc);
my %info = %$row;
$info{more_posts} = $num_posts > $CFG->{subscribe_email_max_posts} if $CFG->{subscribe_email_max_posts};
$info{subscribe_email_max_posts} = $CFG->{subscribe_email_max_posts};
my $posts_shown = 0;
while (my $prow = $psth->fetchrow_hashref) {
$prow->{post_message_text} = $prow->{post_message};
GForum::Post::plain_text(\$prow->{post_message_text}, $prow);
push @{$info{post_loop}}, $prow;
last if $CFG->{subscribe_email_max_posts} and ++$posts_shown >= $CFG->{subscribe_email_max_posts};
}
GForum::Post::normalize($info{post_loop});
debug("Displaying $posts_shown" . (($num_posts > $posts_shown and $CFG->{subscribe_email_max_posts}) ? " (subscribe_email_max_posts set to $CFG->{subscribe_email_max_posts})" : "")) if $DEBUG;
my $email = _get_tpl($GForum::TEMPLATE_SET);
my $headers = $email->headers;
my %head;
while (my ($k, $v) = each %$headers) {
my $val = $v; # Copy it
$val = GForum::Template->parse("string", \%info, { string => $val });
$head{$k} = $val;
}
my $body = $email->body;
$body = GForum::Template->parse("string", \%info, { string => $body });
$CFG->{smtp_server} or $CFG->{mail_path} or die 'No mail path or SMTP server set!';
$head{To} ||= $row->{user_email};
$head{From} ||= $CFG->{admin_email};
my $mailer = GT::Mail->new(
%head,
msg => $body,
($CFG->{smtp_server} ? (smtp => $CFG->{smtp_server}) : (sendmail => $CFG->{mail_path}))
);
debug("Sending to $row->{user_email}") if $DEBUG;
local $@;

if($row->{user_username} eq "schubert"){
if (eval { $mailer->send }) {
debug("Archive of $row->{cat_name}: $row->{forum_name} successfully sent to $row->{user_username}") if $DEBUG;
$DB->table('ForumSubscriber')->update({ subsc_last => time }, { user_id_fk => $info{user_id}, forum_id_fk => $info{forum_id} });
}
else {
debug("Unable to send to $row->{user_email}: " . ($@ || $mailer->error)); # No 'if $DEBUG' - always show this
}
}
}
}
...
Quote Reply
Re: [schubiman] Confusing problem with cronjob and subscriptions In reply to
Mmm.. what if you change;

use lib '/forum/admin';

...to something like;

use lib '/full/path/to/forum/admin';

Does that make a difference?

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Confusing problem with cronjob and subscriptions In reply to
All paths are full paths. But i exchanged them to /forum/... because it's much, much shorter Smile.
Quote Reply
Re: [schubiman] Confusing problem with cronjob and subscriptions In reply to
Hi,

Could be a MySQL table corruption problem. Turn on debug and look for $GT::SQL::error. If you don't see it, add:

$sth or die "Error: $GT::SQL::error";

immediately after line 34. That should contain a more meaningful error message.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Confusing problem with cronjob and subscriptions In reply to
That helped, thanks!
We found the error. The cron job runs under root and didn't load the .profile before starting the subscribe.pl. Therefor the ORACLE_HOME wasn't set. We changed the cron job, so it will now load the .profile before starting the subscribe.pl.
Now everything works fine!