Gossamer Forum
Quote Reply
which hooks to use??
When adding/modifying/validating links from the editor browser, which hooks are need to add functions?

Specificially, I need to something when:

-a link is validated for the first time by the administrator
-a pending change is validated by the administrator

I'm guessing I use a POST hook on modify_link, but how do I make sure that my function is only called when the admin validates the initial addition or subsequent changes? According to the hook documentation, there is "failure", and "success" branch to deal with.

That said, it seems that site_html_modify_success would do what I want except it seems it only runs when modify_link is invoked from modify.cgi.

Advice here would be greatly appreciated!

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] which hooks to use?? In reply to
Looking at the code, it looks like there's a validate_link hook you can use (take a look at Links::Tools). To tell whether it's a first time change or not, there should be an entry in the Changes table if it's a change validation.

Adrian
Quote Reply
Re: [brewt] which hooks to use?? In reply to
Thanks for the reply, brewt. But I believe I nailed down that I actually need to use POST hooks on add_link and modify_link (hooks called whenever $DB->table('Links')->add or ->modify is used).

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [brewt] which hooks to use?? In reply to
oops, meant PRE hooks... add_link needs to be a pre, since I want to have the ID number of the just-added link. modify_link could be either, I guess.

Is this safe to do:

Code:
sub pre_add {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'add_link' is run. You
# should call $PLG->action(STOP) if you don't want the regular
# 'add_link' code to run, otherwise the code will continue as normal.
#
my (@args) = @_;

# Do something useful here
$PLG->action(STOP);
my $id = $DB->table("Links")->_plg_add(@args);

if ($id) {
#do something
}

return $id;
}

sub pre_modify {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'modify_link' is run. You
# should call $PLG->action(STOP) if you don't want the regular
# 'modify_link' code to run, otherwise the code will continue as normal.
#
my (@args) = @_;

# Do something useful here
$PLG->action(STOP);
my $ret = $DB->table("Links")->_plg_modify(@args);

if ($ret) {
my $id = $args[0]->{ID};
#do something
}

return $ret;
}

Philip
------------------
Limecat is not pleased.

Last edited by:

fuzzy logic: Jun 22, 2006, 4:35 PM
Quote Reply
Re: [fuzzy logic] which hooks to use?? In reply to
Why not just a post hook on user_add_link (I'm assuming you meant that and not just add_link). You should get a hash of all the link information (including the ID of the link).

Adrian
Quote Reply
Re: [brewt] which hooks to use?? In reply to
hm... I thought user_add_link was used only for add.cgi? Browser.pm doesn't appear to use a user_add_link hook, and instead uses the hook that runs when $obj->add() is called.

from Links::Browser
Code:
$links->add ($IN->get_hash)
or return $self->javascript_error ( message => Links::language('BROWSER_LINKCANTADD', _format_js($GT::SQL::error)), hist_go => -1 );

from Links::Table::Links
Code:
sub add {
# -------------------------------------------------------------------
# Adds a link, but passes through Plugins::Dispatch.
#
my $self = shift;
my $p = (ref $_[0] eq 'HASH') ? shift : {@_};

$PLG->dispatch('add_link', sub { $self->_plg_add(@_) }, $p);
}

silly me, though, as I could have just used a POST on add_link. I was pretty sure that when I tested it all I got was '1', and not the link ID. Must have just got confused after messng with browser_link_add which only gives a 1 or 0 result.

Philip
------------------
Limecat is not pleased.