liquid_feedback_core
changeset 24:85ee75f90ecd
Close issues when verification time elapsed after revoking last initiative
and more comments in check_issue(...) function
and more comments in check_issue(...) function
author | jbe |
---|---|
date | Sat Feb 06 03:34:09 2010 +0100 (2010-02-06) |
parents | 137c98fa0b4f |
children | f0460e206bc6 |
files | core.sql |
line diff
1.1 --- a/core.sql Sat Feb 06 03:32:04 2010 +0100 1.2 +++ b/core.sql Sat Feb 06 03:34:09 2010 +0100 1.3 @@ -2984,13 +2984,16 @@ 1.4 BEGIN 1.5 PERFORM "global_lock"(); 1.6 SELECT * INTO "issue_row" FROM "issue" WHERE "id" = "issue_id_p"; 1.7 + -- only process open issues: 1.8 IF "issue_row"."closed" ISNULL THEN 1.9 SELECT * INTO "policy_row" FROM "policy" 1.10 WHERE "id" = "issue_row"."policy_id"; 1.11 + -- create a snapshot, unless issue is already fully frozen: 1.12 IF "issue_row"."fully_frozen" ISNULL THEN 1.13 PERFORM "create_snapshot"("issue_id_p"); 1.14 SELECT * INTO "issue_row" FROM "issue" WHERE "id" = "issue_id_p"; 1.15 END IF; 1.16 + -- eventually close or accept issues, which have not been accepted: 1.17 IF "issue_row"."accepted" ISNULL THEN 1.18 IF EXISTS ( 1.19 SELECT NULL FROM "initiative" 1.20 @@ -2999,6 +3002,7 @@ 1.21 AND "supporter_count" * "policy_row"."issue_quorum_den" 1.22 >= "issue_row"."population" * "policy_row"."issue_quorum_num" 1.23 ) THEN 1.24 + -- accept issues, if supporter count is high enough 1.25 PERFORM "set_snapshot_event"("issue_id_p", 'end_of_admission'); 1.26 "issue_row"."accepted" = now(); -- NOTE: "issue_row" used later 1.27 UPDATE "issue" SET "accepted" = "issue_row"."accepted" 1.28 @@ -3006,12 +3010,15 @@ 1.29 ELSIF 1.30 now() >= "issue_row"."created" + "issue_row"."admission_time" 1.31 THEN 1.32 + -- close issues, if admission time has expired 1.33 PERFORM "set_snapshot_event"("issue_id_p", 'end_of_admission'); 1.34 UPDATE "issue" SET "closed" = now() 1.35 WHERE "id" = "issue_row"."id"; 1.36 END IF; 1.37 END IF; 1.38 + -- eventually half freeze issues: 1.39 IF 1.40 + -- NOTE: issue can't be closed at this point, if it has been accepted 1.41 "issue_row"."accepted" NOTNULL AND 1.42 "issue_row"."half_frozen" ISNULL 1.43 THEN 1.44 @@ -3037,15 +3044,43 @@ 1.45 WHERE "id" = "issue_row"."id"; 1.46 END IF; 1.47 END IF; 1.48 + -- close issues after some time, if all initiatives have been revoked: 1.49 + IF 1.50 + "issue_row"."closed" ISNULL AND 1.51 + NOT EXISTS ( 1.52 + -- all initiatives are revoked 1.53 + SELECT NULL FROM "initiative" 1.54 + WHERE "issue_id" = "issue_id_p" AND "revoked" ISNULL 1.55 + ) AND ( 1.56 + NOT EXISTS ( 1.57 + -- and no initiatives have been revoked lately 1.58 + SELECT NULL FROM "initiative" 1.59 + WHERE "issue_id" = "issue_id_p" 1.60 + AND now() < "revoked" + "issue_row"."verification_time" 1.61 + ) OR ( 1.62 + -- or verification time has elapsed 1.63 + "issue_row"."half_frozen" NOTNULL AND 1.64 + "issue_row"."fully_frozen" ISNULL AND 1.65 + now() >= "issue_row"."half_frozen" + "issue_row"."verification_time" 1.66 + ) 1.67 + ) 1.68 + THEN 1.69 + "issue_row"."closed" = now(); -- NOTE: "issue_row" used later 1.70 + UPDATE "issue" SET "closed" = "issue_row"."closed" 1.71 + WHERE "id" = "issue_row"."id"; 1.72 + END IF; 1.73 + -- fully freeze issue after verification time: 1.74 IF 1.75 "issue_row"."half_frozen" NOTNULL AND 1.76 "issue_row"."fully_frozen" ISNULL AND 1.77 + "issue_row"."closed" ISNULL AND 1.78 now() >= "issue_row"."half_frozen" + "issue_row"."verification_time" 1.79 THEN 1.80 PERFORM "freeze_after_snapshot"("issue_id_p"); 1.81 - -- "issue" might change, thus "issue_row" has to be updated below 1.82 + -- NOTE: "issue" might change, thus "issue_row" has to be updated below 1.83 END IF; 1.84 SELECT * INTO "issue_row" FROM "issue" WHERE "id" = "issue_id_p"; 1.85 + -- close issue by calling close_voting(...) after voting time: 1.86 IF 1.87 "issue_row"."closed" ISNULL AND 1.88 "issue_row"."fully_frozen" NOTNULL AND