Forum OpenACS Development: changing acs_objects_last_mod_update_tr

Currently this trigger on acs_objects is:
create function acs_objects_last_mod_update_tr () returns opaque as '
begin
  new.last_modified := now();

  return new;

end;' language 'plpgsql';
Which is annoying since if you want to change last_modified you have to drop and recreate this trigger.

I would like to change it so that it reads

create function acs_objects_last_mod_update_tr () returns opaque as '
begin
  if new.last_modified is null then
     new.last_modified := old.last_modified;
  else if new.last_modified = old.last_modified then
     new.last_modified := now();

  return new;
end;' language 'plpgsql';
what this would mean is that for changes which should preserve last_modified you could update and set last_modified = null to preserve the timestamp, the current behavior where updates don't touch last_modified would be the same, and for places where you are setting last_modified explicitly you could do so without dropping the trigger.

The only significant disadvantage is that if a script that did something like update last_modified to match an external timestamp (for a bulk load for example) got run twice you might end up with last_modified set to now for all updated rows (and you might also get the occasional update where the original and new ones just happen to match and the timestamp is set to now anyway).

The motivation is that I want to be able to load mailing list archives into forums and set the creation and last modified dates to the right values. or have last_modified in static pages reflect the timestamp on the file.

Anyone have any objection? Should this be a TIP?

Collapse
Posted by Barry Books on
I've run into this problem also. It seems to me the funtionality should be
if last_modified is set in the update that's what it should be
if last_modified in not set then it should be now()
if last_modified is null then leave it alone