A new trigger allowing calendar_alarm.component to be edited.

The trigger will then cause the caldav_data record to be
updated with the new alarm component, and the etag is changed.
This commit is contained in:
Andrew McMillan 2010-04-03 17:28:01 +13:00
parent a364cbf5c8
commit b806fa8305

View File

@ -1222,3 +1222,24 @@ BEGIN
END END
$$ LANGUAGE 'PlPgSQL' STRICT; $$ LANGUAGE 'PlPgSQL' STRICT;
DROP TRIGGER alarm_changed ON calendar_alarm CASCADE;
CREATE or REPLACE FUNCTION alarm_changed() RETURNS TRIGGER AS $$
DECLARE
oldcomponent TEXT;
newcomponent TEXT;
BEGIN
-- in case we trigger on other events in future
IF TG_OP = 'UPDATE' THEN
IF NEW.component != OLD.component THEN
UPDATE caldav_data
SET caldav_data = replace( caldav_data, OLD.component, NEW.component ),
dav_etag = md5(replace( caldav_data, OLD.component, NEW.component ))
WHERE caldav_data.dav_id = NEW.dav_id;
END IF;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER alarm_changed AFTER UPDATE ON calendar_alarm
FOR EACH ROW EXECUTE PROCEDURE alarm_changed();