Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Problems with modify_link hook

Quote Reply
Problems with modify_link hook
Hi
My aim was do Links table changes after editor or admin have submitted link modify
This updates are based on computations with entered data

I tried two ways to save this computations:
made PRE modify_link hook and change $IN->
values to be saved in table during update

But table update happens before PRE modify_link hook
why!!!???

another way:
I triyed use POST modify_link hook
after my table update was executed
I see the foloowing error message popup
'The record you are attempting to modify has changed since you last accessed it'

Please help me reach my aim or explain modify_link hook architechture

Thank you
and table changes are not saved
Quote Reply
Re: [twssser] Problems with modify_link hook In reply to
Hi,

I sent Alex a potential bug report on this one. I hit this by accident, trying to follow program flow.

I don't think the pre_add/modify hoods are being triggered properly, but I may not be understanding them correctly.

As for the post hook, that is a safety feature of Links to prevent multiple modifications to a record. There *is* a way around it, since I allow people to edit/re-edit their links, but I can't remember exactly what it is I'm not doing to trigger that warning. You may have to re-select the record before you can do anything to it (my edits occour much later than immediately after modify). There may be a flag set that needs to be cleared before you can do that.

Try just re-requesting the modified record (get->ID) and see if that allows you to modify the record.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Problems with modify_link hook In reply to
Thanks for suggestion but this didn't helps
I tried get record from table

the same error message about record access

maybe there is another way to update record later or before modify_link?
Quote Reply
Re: [twssser] Problems with modify_link hook In reply to
There is another issue going on here, as well. If you are modifying fields that are stored in the modifications database, then you'd want to edit *that* hash directly. Retrieve it, modify it, then save it back.

Look in User::Modify.pm for the dumper code, to see how that works.

If what you are trying to do can be done pre_ code wise, you might want to edit your Modify.pm file to "use mymodule.pm", then make a call to run the code in your module. This is not portable, and you'd have to do it for each new install of links, but you can do that. It's two lines of code, and you can put both the "use" and call to the module in the subroutine (its' not good form, but it works, and keeps it together). Then, if you modify the external pm file, you are not actually editing the Modify.pm any longer, but your own module. You could also use "require", rather than "use", to add the code to the file. That would be one line of code in Modify.pm, or more safely:

eval{require "mycode.pl"};
#if($@) {
# print "Failed to load mycode.pl\n";
#}

The plugin system was to make sure large changes in behaviour did not have to be carried through each new generation. But, small, site specific changes to the code are almost inevitable. Sometimes a plugin is like using a sledge hammer to put a tack into a cork board.

Just keep a little file of "code edits" in the main links directory, and refer to it any time you update links.

Hopefully, alex will look at that pre- code thing, and see what the problem is :)


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Problems with modify_link hook In reply to
Thank for suggestion
It helps
but I've found another problem - the same message appears
and I've digged into code and found that Timestmp field check get 0 value so Timestmp check cause this error

I fix this by manually setting Timestmp to now time
Code:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
$year=1900+$year;
$mon++;
if (length($mon)==1) {$mon="0$mon"}
if (length($mday)==1) {$mday="0$mday"}
if (length($hour)==1) {$hour="0$hour"}
if (length($min)==1) {$min="0$min"}
if (length($sec)==1) {$sec="0$sec"}
$save->{Timestmp} = "$year$mon$mday$hour$min$sec";

Tomorrow I'll try do ->update in hook with manually setting Timestmp
but I think this will not work coz update delete all Timestmp fields...

Let's see
Quote Reply
Re: [twssser] Problems with modify_link hook In reply to
Let me know what you find :)

Alex partially answered the point of executing, with this:

add_link and modify_link execute when the link is added/modified from the admin or scripts.

user_add_link and user_modify_link execute before Add.pm or Modify.pm is run.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Problems with modify_link hook In reply to
Hi
As I tell before change timestmp to now in table::update don't helps
I think it is coz update delete all Timestamp from query...


Thank you pugdog and Alex
update link from user side will my next step...

now I'm going use modify hash way...