Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. -- FUNCTION: "www-data".modlogfunc()
  2.  
  3. -- DROP FUNCTION "www-data".modlogfunc();
  4.  
  5. CREATE FUNCTION "www-data".modlogfunc()
  6. RETURNS trigger
  7. LANGUAGE 'plpgsql'
  8. COST 100
  9. VOLATILE NOT LEAKPROOF
  10. ROWS 0
  11. AS $BODY$
  12. DECLARE
  13. changes character varying(100);
  14. BEGIN
  15. changes = '';
  16. IF new.password != old.password OR XOR(old.password IS NULL, new.password IS NULL) THEN
  17. changes = changes || 'password,';
  18. END IF;
  19. IF new.is_superuser != old.is_superuser THEN
  20. changes = changes || 'is_superuser,';
  21. END IF;
  22. IF new.first_name != old.first_name OR XOR(old.first_name IS NULL, new.first_name IS NULL) THEN
  23. changes = changes || 'first_name,';
  24. END IF;
  25. IF new.last_name != old.last_name OR XOR(old.last_name IS NULL, new.last_name IS NULL) THEN
  26. changes = changes || 'last_name,';
  27. END IF;
  28. IF new.email != old.email THEN
  29. changes = changes || 'email,';
  30. END IF;
  31. IF new.phone != old.phone OR XOR(old.phone IS NULL, new.phone IS NULL) THEN
  32. changes = changes || 'phone,';
  33. END IF;
  34. IF new.address_id != old.address_id OR XOR(old.address_id IS NULL, new.address_id IS NULL) THEN
  35. changes = changes || 'address_id,';
  36. END IF;
  37. IF new.company_id != old.company_id OR XOR(old.company_id IS NULL, new.company_id IS NULL) THEN
  38. changes = changes || 'company_id,';
  39. END IF;
  40. IF new.service_access != old.service_access THEN
  41. changes = changes || 'service_access,';
  42. END IF;
  43. IF new.personal_data_access != old.personal_data_access THEN
  44. changes = changes || 'personal_data_access,';
  45. END IF;
  46. IF new.rules_accept_date != old.rules_accept_date OR XOR(old.rules_accept_date IS NULL, new.rules_accept_date IS NULL) THEN
  47. changes = changes || 'rules_accept_date,';
  48. END IF;
  49. IF new.personal_data_measurement != old.personal_data_measurement THEN
  50. changes = changes || 'personal_data_measurement,';
  51. END IF;
  52. IF new.personal_data_producent != old.personal_data_producent THEN
  53. changes = changes || 'personal_data_producent,';
  54. END IF;
  55. IF new.personal_data_marketing != old.personal_data_marketing THEN
  56. changes = changes || 'personal_data_marketing,';
  57. END IF;
  58. IF new.personal_data_other != old.personal_data_other THEN
  59. changes = changes || 'personal_data_other,';
  60. END IF;
  61. IF new.personal_data_direct_marketing != old.personal_data_direct_marketing THEN
  62. changes = changes || 'personal_data_direct_marketing,';
  63. END IF;
  64. IF new.personal_data_communication != old.personal_data_communication THEN
  65. changes = changes || 'personal_data_communication,';
  66. END IF;
  67. IF changes != '' THEN
  68. INSERT INTO "www-data".accounts_modifications_history(user_id, d, changes) VALUES (new.ID, current_timestamp, changes);
  69. END IF;
  70. RETURN NEW;
  71. END;
  72.  
  73. $BODY$;
  74.  
  75. ALTER FUNCTION "www-data".modlogfunc()
  76. OWNER TO "www-data";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement