I've just found the post where you discussed this with sangiro and Laura :
http://www.gossamer-threads.com/...i?post=273819#273819
date_get (time, '%ddd% %mmm% %dd% %yyyy%');
but if you want to use date_set_format you really need to set the format back at the end of the sub using
GT::Date::date_set_format($CFG->{'date_db_format'});
setting the date back needs to be done before this :
Anyway I'll give it a wirl, but this explains why it isn't in the release version since it can potentially create issues with a mod_perl installation. I have not got mod_perl turned on at the moment but will be aiming to.
Thanks for the help
I'm not that much of a wiz like you with perl but I see that it picks up the IP with $ENV{REMOTE_ADDR} and follow most of it but I can't figure out which field it will be updating as compared to presently where it updates the Detailed_Hits field. Do I need to create a new field for unique hits or does this mod mean that it will now just log unique hits and not all hits ?
This 'should' be the correct version with get_date to avoid the issues discussed by Laura :
my $click_db = $DB->table ('ClickTrack');
my $DETAILED_CFG = Links::Plugins::get_plugin_user_cfg ('Detailed_Page');
my $column_name = $DETAILED_CFG->{'column_name'};
my $delete_by = $DETAILED_CFG->{'delete_by'};
Links::init_date();
GT::Date::date_get (time, '%ddd% %mmm% %dd% %yyyy%');
$delete_by = GT::Date::date_get ( time() - 18000 ); # 5 HOURS
## do some house keeping on old click-track records.
## these never seem to be deleted.
$click_db->delete(GT::SQL::Condition->new('Created', '<', $delete_by));
my $click_sth = $click_db->select ( { LinkID => $id,
IP => $ip,
ClickType => 'Hits'
} ) or return { error => $GT::SQL::error, LinkID => $id };
if ($click_db->hits) {
my $record = $click_sth->fetchrow_hashref;
my $created = $record->{'Created'};
if ($created < $delete_by) { ## if the record is older than delete_by
$click_db->update (
{ ## refresh the date
Created => \"NOW()"
},
{
LinkID => $id,
IP => $ip,
ClickType => 'Hits'
},
{
GT_SQL_SKIP_INDEX => 1
}
) or return { error => $GT::SQL::error, LinkID => $id };
$LINKDB->update (
{
"$column_name" => \"$column_name + 1"
}, ## set
{
ID => $id ## where
},
{
GT_SQL_SKIP_INDEX => 1 ## cut overhead
}
) or return { error => $GT::SQL::error, LinkID => $id };
}
} else {
## print "No record was found, I'm going to try to update links, and insert click_db<BR>";
$LINKDB->update ( {
"$column_name" => \"$column_name + 1"
},
{
ID => $id
},
{
GT_SQL_SKIP_INDEX => 1
} ) or return { error => $GT::SQL::error, LinkID => $id };
$click_db->insert ( {
LinkID => $id,
IP => $ip,
ClickType => 'Hits',
Created => \"NOW()"
} ) or return { error => $GT::SQL::error, LinkID => $id };
}
I'll try it out with and without mod_perl and let you know how it goes.
John
Significant Media
http://www.gossamer-threads.com/...i?post=273819#273819
Quote:
Personally I would use date_get (time, '%ddd% %mmm% %dd% %yyyy%');
but if you want to use date_set_format you really need to set the format back at the end of the sub using
GT::Date::date_set_format($CFG->{'date_db_format'});
setting the date back needs to be done before this :
Quote:
return ($link;Anyway I'll give it a wirl, but this explains why it isn't in the release version since it can potentially create issues with a mod_perl installation. I have not got mod_perl turned on at the moment but will be aiming to.
Thanks for the help
I'm not that much of a wiz like you with perl but I see that it picks up the IP with $ENV{REMOTE_ADDR} and follow most of it but I can't figure out which field it will be updating as compared to presently where it updates the Detailed_Hits field. Do I need to create a new field for unique hits or does this mod mean that it will now just log unique hits and not all hits ?
This 'should' be the correct version with get_date to avoid the issues discussed by Laura :
Code:
my $ip = $ENV{REMOTE_ADDR} || 'None'; my $click_db = $DB->table ('ClickTrack');
my $DETAILED_CFG = Links::Plugins::get_plugin_user_cfg ('Detailed_Page');
my $column_name = $DETAILED_CFG->{'column_name'};
my $delete_by = $DETAILED_CFG->{'delete_by'};
Links::init_date();
GT::Date::date_get (time, '%ddd% %mmm% %dd% %yyyy%');
$delete_by = GT::Date::date_get ( time() - 18000 ); # 5 HOURS
## do some house keeping on old click-track records.
## these never seem to be deleted.
$click_db->delete(GT::SQL::Condition->new('Created', '<', $delete_by));
my $click_sth = $click_db->select ( { LinkID => $id,
IP => $ip,
ClickType => 'Hits'
} ) or return { error => $GT::SQL::error, LinkID => $id };
if ($click_db->hits) {
my $record = $click_sth->fetchrow_hashref;
my $created = $record->{'Created'};
if ($created < $delete_by) { ## if the record is older than delete_by
$click_db->update (
{ ## refresh the date
Created => \"NOW()"
},
{
LinkID => $id,
IP => $ip,
ClickType => 'Hits'
},
{
GT_SQL_SKIP_INDEX => 1
}
) or return { error => $GT::SQL::error, LinkID => $id };
$LINKDB->update (
{
"$column_name" => \"$column_name + 1"
}, ## set
{
ID => $id ## where
},
{
GT_SQL_SKIP_INDEX => 1 ## cut overhead
}
) or return { error => $GT::SQL::error, LinkID => $id };
}
} else {
## print "No record was found, I'm going to try to update links, and insert click_db<BR>";
$LINKDB->update ( {
"$column_name" => \"$column_name + 1"
},
{
ID => $id
},
{
GT_SQL_SKIP_INDEX => 1
} ) or return { error => $GT::SQL::error, LinkID => $id };
$click_db->insert ( {
LinkID => $id,
IP => $ip,
ClickType => 'Hits',
Created => \"NOW()"
} ) or return { error => $GT::SQL::error, LinkID => $id };
}
I'll try it out with and without mod_perl and let you know how it goes.
John
Significant Media