liquid_feedback_core

changeset 582:225a0c047691

Bugfix in function "write_event_initiative_revoked_trigger" (wrong use of SELECT, needs to be PERFORM)
author jbe
date Tue Sep 04 14:30:41 2018 +0200 (19 months ago)
parents 1cb6710fc429
children f5095a9696eb
files core.sql update/core-update.v4.0.0-v4.0.1.sql
line diff
     1.1 --- a/core.sql	Sun Mar 04 18:10:07 2018 +0100
     1.2 +++ b/core.sql	Tue Sep 04 14:30:41 2018 +0200
     1.3 @@ -1999,13 +1999,13 @@
     1.4      BEGIN
     1.5        IF OLD."revoked" ISNULL AND NEW."revoked" NOTNULL THEN
     1.6          -- NOTE: lock for primary key update to avoid new drafts
     1.7 -        SELECT NULL FROM "initiative" WHERE "id" = NEW."id" FOR UPDATE;
     1.8 +        PERFORM NULL FROM "initiative" WHERE "id" = NEW."id" FOR UPDATE;
     1.9          SELECT * INTO "issue_row" FROM "issue"
    1.10            WHERE "id" = NEW."issue_id" FOR SHARE;
    1.11          SELECT * INTO "area_row" FROM "area"
    1.12            WHERE "id" = "issue_row"."area_id" FOR SHARE;
    1.13          -- NOTE: FOR SHARE cannot be used with DISTINCT in view "current_draft"
    1.14 -        SELECT NULL FROM "draft" WHERE "initiative_id" = NEW."id" FOR SHARE;
    1.15 +        PERFORM NULL FROM "draft" WHERE "initiative_id" = NEW."id" FOR SHARE;
    1.16          SELECT "id" INTO "draft_id_v" FROM "current_draft"
    1.17            WHERE "initiative_id" = NEW."id";
    1.18          INSERT INTO "event" (
     2.1 --- a/update/core-update.v4.0.0-v4.0.1.sql	Sun Mar 04 18:10:07 2018 +0100
     2.2 +++ b/update/core-update.v4.0.0-v4.0.1.sql	Tue Sep 04 14:30:41 2018 +0200
     2.3 @@ -66,4 +66,39 @@
     2.4  COMMENT ON COLUMN "system_application"."base_url"     IS 'Base URL for users';
     2.5  COMMENT ON COLUMN "system_application"."manifest_url" IS 'URL referring to a manifest that can be used for application (type/version) discovery';
     2.6  
     2.7 +CREATE OR REPLACE FUNCTION "write_event_initiative_revoked_trigger"()
     2.8 +  RETURNS TRIGGER
     2.9 +  LANGUAGE 'plpgsql' VOLATILE AS $$
    2.10 +    DECLARE
    2.11 +      "issue_row"  "issue"%ROWTYPE;
    2.12 +      "area_row"   "area"%ROWTYPE;
    2.13 +      "draft_id_v" "draft"."id"%TYPE;
    2.14 +    BEGIN
    2.15 +      IF OLD."revoked" ISNULL AND NEW."revoked" NOTNULL THEN
    2.16 +        -- NOTE: lock for primary key update to avoid new drafts
    2.17 +        PERFORM NULL FROM "initiative" WHERE "id" = NEW."id" FOR UPDATE;
    2.18 +        SELECT * INTO "issue_row" FROM "issue"
    2.19 +          WHERE "id" = NEW."issue_id" FOR SHARE;
    2.20 +        SELECT * INTO "area_row" FROM "area"
    2.21 +          WHERE "id" = "issue_row"."area_id" FOR SHARE;
    2.22 +        -- NOTE: FOR SHARE cannot be used with DISTINCT in view "current_draft"
    2.23 +        PERFORM NULL FROM "draft" WHERE "initiative_id" = NEW."id" FOR SHARE;
    2.24 +        SELECT "id" INTO "draft_id_v" FROM "current_draft"
    2.25 +          WHERE "initiative_id" = NEW."id";
    2.26 +        INSERT INTO "event" (
    2.27 +            "event", "member_id",
    2.28 +            "unit_id", "area_id", "policy_id", "issue_id", "state",
    2.29 +            "initiative_id", "draft_id"
    2.30 +          ) VALUES (
    2.31 +            'initiative_revoked', NEW."revoked_by_member_id",
    2.32 +            "area_row"."unit_id", "issue_row"."area_id",
    2.33 +            "issue_row"."policy_id",
    2.34 +            NEW."issue_id", "issue_row"."state",
    2.35 +            NEW."id", "draft_id_v"
    2.36 +          );
    2.37 +      END IF;
    2.38 +      RETURN NULL;
    2.39 +    END;
    2.40 +  $$;
    2.41 +
    2.42  COMMIT;

Impressum / About Us