php - MySQL Trigger create multiple records based on fields changed in SQL query? -
i have mysql trigger creates "task event log" record in db table when task record modified.
the event record trigger creates can specific "task edited" , need more advanced.
i need create separate event log records each task field modified.
if task title, description, , due date changed, need make 3 event records, 1 each field modified. "task due date modified"
is there way create separate event table records each task field "modified" using triggers?
the main reason using triggers have mass update task page allows mass update task records , there field values. allows drag , drop change there sort order , when sot order changes on records, not make taks modified date change unless real task fields changed well.
begin if not (new.date_modified <=> old.date_modified) insert apoll_web_projects_events (event_type, project_id, task_id, created_by_user_id, description, date_created) values ('7', new.project_id, new.task_id, new.modified_user_id, new.name, utc_timestamp()); end if; end
here mysql query mass updates task records making sure update modified date field when changed field criteria met.
then trigger fires on records did meet criteria , updated date_modified field.
insert $this->tasksdbtablename(task_id, project_id, created_by_user_id, modified_user_id, name, description, status, priority, type, date_entered, date_modified, date_started, date_completed, date_due, milestone_id, assigned_user_id, sort_order, heading) values ($db->quote($taskid), '$projectid', '$created_by_user_id', '$modified_user_id', '$name', '$description', '$status', '$priority', '$type', utc_timestamp(), utc_timestamp(), '$date_started', '$date_completed', '$date_due', '$milestone_id', '$assigned_user_id', '$sort_order', '$heading') on duplicate key update date_modified = (case when name <> values(name) or description <> values(description) or status <> values(status) or type <> values(type) or priority <> values(priority) utc_timestamp() else date_modified end), modified_user_id='$modified_user_id', name='$name', description='$description', status='$status', priority='$priority', type='$type', date_started='$date_started', date_completed='$date_completed', date_due='$date_due', milestone_id='$milestone_id', assigned_user_id='$assigned_user_id', sort_order='$sort_order', heading='$heading'
in sql above, when criteria met make go ahead , update task record, there way have fire off sort of event create event record each field is updating?
Comments
Post a Comment