Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

help debugging a subroutine

Quote Reply
help debugging a subroutine
Hi,

I'm hoping someone can shed some light on this. I've got a special FACustom.pm file with a subroutine that's supposed to calculate the number of posts in an Announcements forum since the last time the user was seen at that forum. This count is also supposed to max out at the last 30 days, so nothing older than that should be counted.

Right now something is seriously messed up, since when I call it in the template I'm getting the following error message:

Error: Unable to load module: GForum::FACustom. Reason:
Error: No subroutine 'GForum::FACustom::getUserNewAnnouncements' in 'GForum/FACustom.pm',
Error: No subroutine 'GForum::FACustom::getUserNewAnnouncements' in 'GForum.pm'

Code:
use strict;
use vars qw/@EXPORT_OK/;
use GForum qw/$DB $USER $CFG/;

sub getUserNewAnnouncements {
if ($USER) {

my $cutoff = shift;
if(!$cutoff) {
$cutoff = time() - (3600*24*30);
}

my $user_id = $USER->{user_id};
my $forum_id = 11; #this is the id of the announcements forum
my $last_in_forum = $DB->table('UserNew')->select('usernew_last' => { user_id_fk => $user_id, forum_id_fk => $forum_id})->fetchrow_hashref->{usernew_last};

if(!$last_in_forum || $last_in_forum < $cutoff) {
my $cond = GT::SQL::Condition->new(
forum_id_fk => '=' => $forum_id,
post_root_id => '=' => 0,
post_time => '>' => $cutoff
);

return $DB->table('Post')->count($cond);

} else {
my $cond = GT::SQL::Condition->new(
forum_id_fk => '=' => $forum_id,
post_root_id => '=' => 0,
post_time => '>' => $last_in_forum
);

return $DB->table('Post')->count($cond);
}

} else {

return 0;
}
}

1;

Thanks in advance for any suggestions.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] help debugging a subroutine In reply to
Hi,

Not sure if this is a valid line?

my $last_in_forum = $DB->table('UserNew')->select('usernew_last' => { user_id_fk => $user_id, forum_id_fk => $forum_id})->fetchrow_hashref->{usernew_last};


Probably better written;

my $last_in_forum = $DB->table('UserNew')->select( ['usernew_last'], { user_id_fk => $user_id, forum_id_fk => $forum_id})->fetchrow;

Not sure about any other coding problems.

What happens if you run it in the plugin editor? i.e make a test plugin, copy the code into the .pm file, and then do a "Perl Check". This normally shows up any major errors :)

Hope that helps.

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] help debugging a subroutine In reply to
Thanks, Andy.

After making that change and running it through the "perl check" in the plugin manager, I got a "syntax OK" response.

The really weird thing is that I've even commented out every single line of code except for the subroutine name and brackets, and it STILL says that same error message. So I think I must have screwed up on an even more fundamental level... I've never used a custom pm file in GForum before, but it works fine for me in DBManSQL. Is this something that should work in principal with GForum as well??

Thanks again for your help.

PS Like the new avatar. Smile

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] help debugging a subroutine In reply to
Hi,

Have you tried using this tag syntax?

<%GForum::FACustom->getUserNewAnnouncements()%>

I know the later versions of LSQL and GForum have some weird issues in calling through custom .pm files (I had some real fun trying to get Custom.pm recognising custom routines, which was a bit of a PITA :(

Quote:
PS Like the new avatar. Smile

heheh.. thanks =)

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] help debugging a subroutine In reply to
I made that change in the template, but now it's coming up with a "Unknown Tag: 'GForum::FACustom->getUserNewAnnouncements()'" error. Unsure

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] help debugging a subroutine In reply to
Mmm.. maybe someone at GT could shed some light? Normally <%Plugins::Plugin_Name::function()%> works fine :/

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: [hennagaijin] help debugging a subroutine In reply to
Mmm.. thinking about it, did you try this?

<%Plugins::GForum::FACustom::getUserNewAnnouncements%>

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] help debugging a subroutine In reply to
I tried everything I could think of, but was unable to get it to work from the outside pm file. I did get it working as a global, though:

Code:
sub {
use GForum qw/$DB $USER $CFG/;

if ($USER) {

my $cutoff = time - (3600*24*30);

my $user_id = $USER->{user_id};
my $forum_id = 11; # announcements forum id
my $last_check = $DB->table('UserNew')->select('usernew_last' => { user_id_fk => $user_id, forum_id_fk => $forum_id})->fetchrow;
my $last_in_forum = $last_check->{usernew_last} unless !$last_check;

if(!$last_in_forum || $last_in_forum < $cutoff) {
my $cond = GT::SQL::Condition->new(
forum_id_fk => '=' => 11,
post_root_id => '=' => 0,
post_time => '>' => $cutoff
);

return $DB->table('Post')->count($cond);

} else {
my $cond = GT::SQL::Condition->new(
forum_id_fk => '=' => 11,
post_root_id => '=' => 0,
post_time => '>' => $last_in_forum
);

return $DB->table('Post')->count($cond);

}

} else {

return 0;
}
}

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund