Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FUNCTION: "www-data".modlogfunc()
- -- DROP FUNCTION "www-data".modlogfunc();
- CREATE FUNCTION "www-data".modlogfunc()
- RETURNS trigger
- LANGUAGE 'plpgsql'
- COST 100
- VOLATILE NOT LEAKPROOF
- ROWS 0
- AS $BODY$
- DECLARE
- changes character varying(100);
- BEGIN
- changes = '';
- IF new.password != old.password OR XOR(old.password IS NULL, new.password IS NULL) THEN
- changes = changes || 'password,';
- END IF;
- IF new.is_superuser != old.is_superuser THEN
- changes = changes || 'is_superuser,';
- END IF;
- IF new.first_name != old.first_name OR XOR(old.first_name IS NULL, new.first_name IS NULL) THEN
- changes = changes || 'first_name,';
- END IF;
- IF new.last_name != old.last_name OR XOR(old.last_name IS NULL, new.last_name IS NULL) THEN
- changes = changes || 'last_name,';
- END IF;
- IF new.email != old.email THEN
- changes = changes || 'email,';
- END IF;
- IF new.phone != old.phone OR XOR(old.phone IS NULL, new.phone IS NULL) THEN
- changes = changes || 'phone,';
- END IF;
- IF new.address_id != old.address_id OR XOR(old.address_id IS NULL, new.address_id IS NULL) THEN
- changes = changes || 'address_id,';
- END IF;
- IF new.company_id != old.company_id OR XOR(old.company_id IS NULL, new.company_id IS NULL) THEN
- changes = changes || 'company_id,';
- END IF;
- IF new.service_access != old.service_access THEN
- changes = changes || 'service_access,';
- END IF;
- IF new.personal_data_access != old.personal_data_access THEN
- changes = changes || 'personal_data_access,';
- END IF;
- IF new.rules_accept_date != old.rules_accept_date OR XOR(old.rules_accept_date IS NULL, new.rules_accept_date IS NULL) THEN
- changes = changes || 'rules_accept_date,';
- END IF;
- IF new.personal_data_measurement != old.personal_data_measurement THEN
- changes = changes || 'personal_data_measurement,';
- END IF;
- IF new.personal_data_producent != old.personal_data_producent THEN
- changes = changes || 'personal_data_producent,';
- END IF;
- IF new.personal_data_marketing != old.personal_data_marketing THEN
- changes = changes || 'personal_data_marketing,';
- END IF;
- IF new.personal_data_other != old.personal_data_other THEN
- changes = changes || 'personal_data_other,';
- END IF;
- IF new.personal_data_direct_marketing != old.personal_data_direct_marketing THEN
- changes = changes || 'personal_data_direct_marketing,';
- END IF;
- IF new.personal_data_communication != old.personal_data_communication THEN
- changes = changes || 'personal_data_communication,';
- END IF;
- IF changes != '' THEN
- INSERT INTO "www-data".accounts_modifications_history(user_id, d, changes) VALUES (new.ID, current_timestamp, changes);
- END IF;
- RETURN NEW;
- END;
- $BODY$;
- ALTER FUNCTION "www-data".modlogfunc()
- OWNER TO "www-data";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement