Guest User

Untitled

a guest
Apr 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. CREATE OR REPLACE FUNCTION younity_gallery_spot_items_trig () RETURNS TRIGGER AS $$
  2.  
  3. # get important data out of the TD dict
  4. event = TD["event"]
  5. record = TD["new"]
  6.  
  7. if event == "UPDATE":
  8.  
  9. if record["stat_active"] or record["stat_in_auction"]:
  10.  
  11. # item is active or in auction, so make sure the zone is active
  12. plan = plpy.prepare("""
  13. UPDATE
  14. adult.zones
  15. SET
  16. stat_active = true
  17. WHERE
  18. zone_id = $1
  19. """,
  20. ["int8"])
  21.  
  22. plpy.execute(plan, [record["zone_id"]])
  23.  
  24. else:
  25.  
  26. # item isn't active and isn't in an auction, so if the rest of the zone
  27. # items aren't active and aren't in an auction, we can set the zone to inactive
  28. plan = plpy.prepare("""
  29. SELECT
  30. 1
  31. FROM
  32. adult.gallery_spot_items
  33. WHERE
  34. zone_id = $1
  35. AND
  36. (stat_active OR stat_in_auction)
  37. """,
  38. ["int8"])
  39.  
  40. items = plpy.execute(plan, [record["zone_id"]])
  41.  
  42. if len(items) == 0:
  43.  
  44. # no other active or auctioned items, let's inactivate the zone
  45. plan = plpy.prepare("""
  46. UPDATE
  47. adult.zones
  48. SET
  49. stat_active = false
  50. WHERE
  51. zone_id = $1
  52. """,
  53. ["int8"])
  54.  
  55. plpy.execute(plan, [record["zone_id"]])
  56.  
  57. return None
  58.  
  59. $$ LANGUAGE plpythonu;
Add Comment
Please, Sign In to add comment