Index: openacs-4/packages/acs-kernel/acs-kernel.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/acs-kernel.info,v diff -u -N -r1.150.2.8 -r1.150.2.9 --- openacs-4/packages/acs-kernel/acs-kernel.info 21 Mar 2019 15:04:18 -0000 1.150.2.8 +++ openacs-4/packages/acs-kernel/acs-kernel.info 4 Apr 2019 11:01:52 -0000 1.150.2.9 @@ -9,15 +9,15 @@ f t - + OpenACS Core Team Routines and data models providing the foundation for OpenACS-based Web services. 2017-08-06 OpenACS The OpenACS kernel contains the core datamodel create and drop scripts for such things as objects, groups, parties and the supporting PL/SQL and PL/pgSQL procedures. 3 - + Index: openacs-4/packages/acs-kernel/sql/postgresql/community-core-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/community-core-create.sql,v diff -u -N -r1.29.6.2 -r1.29.6.3 --- openacs-4/packages/acs-kernel/sql/postgresql/community-core-create.sql 23 Feb 2019 13:03:40 -0000 1.29.6.2 +++ openacs-4/packages/acs-kernel/sql/postgresql/community-core-create.sql 4 Apr 2019 11:01:53 -0000 1.29.6.3 @@ -806,14 +806,13 @@ DECLARE v_user_id users.user_id%TYPE; v_authority_id auth_authorities.authority_id%TYPE; - v_person_exists varchar; + v_person_exists integer; BEGIN v_user_id := p_user_id; - select case when count(*) = 0 then 'f' else 't' end into v_person_exists - from persons where person_id = v_user_id; + select 1 from persons into v_person_exists where person_id = v_user_id; - if v_person_exists = 'f' then + if NOT FOUND then v_user_id := person__new( v_user_id, p_object_type, @@ -905,15 +904,15 @@ receives_alerts_p__user_id integer ) RETURNS boolean AS $$ DECLARE - counter boolean; + found_p boolean; BEGIN - select case when count(*) = 0 then 'f' else 't' end into counter - from users - where no_alerts_until >= now() - and user_id = receives_alerts_p__user_id; + select exists into found_p ( + select 1 from users + where no_alerts_until >= now() + and user_id = receives_alerts_p__user_id + ); - return counter; - + return found_p; END; $$ LANGUAGE plpgsql stable; Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.0d14-5.10.0d15.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/Attic/upgrade-5.10.0d14-5.10.0d15.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.10.0d14-5.10.0d15.sql 4 Apr 2019 11:01:53 -0000 1.1.2.1 @@ -0,0 +1,92 @@ +-- Modernize SQL existence test: make these more readable and faster + +-- +-- procedure acs_user__new/16 +-- +CREATE OR REPLACE FUNCTION acs_user__new( + p_user_id integer, -- default null + p_object_type varchar, -- default 'user' + p_creation_date timestamptz, -- default now() + p_creation_user integer, -- default null + p_creation_ip varchar, -- default null + p_authority_id integer, -- defaults to local authority + p_username varchar, + p_email varchar, + p_url varchar, -- default null + p_first_names varchar, + p_last_name varchar, + p_password char, + p_salt char, + p_screen_name varchar, -- default null + p_email_verified_p boolean, -- default 't' + p_context_id integer -- default null + +) RETURNS integer AS $$ +DECLARE + v_user_id users.user_id%TYPE; + v_authority_id auth_authorities.authority_id%TYPE; + v_person_exists integer; +BEGIN + v_user_id := p_user_id; + + select 1 from persons into v_person_exists where person_id = v_user_id; + + if NOT FOUND then + v_user_id := person__new( + v_user_id, + p_object_type, + p_creation_date, + p_creation_user, + p_creation_ip, + p_email, + p_url, + p_first_names, + p_last_name, + p_context_id + ); + else + update acs_objects set object_type = 'user' where object_id = v_user_id; + end if; + + -- default to local authority + if p_authority_id is null then + select authority_id + into v_authority_id + from auth_authorities + where short_name = 'local'; + else + v_authority_id := p_authority_id; + end if; + + insert into users + (user_id, authority_id, username, password, salt, screen_name, email_verified_p) + values + (v_user_id, v_authority_id, p_username, p_password, p_salt, p_screen_name, p_email_verified_p); + + insert into user_preferences + (user_id) + values + (v_user_id); + + return v_user_id; + +END; +$$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION acs_user__receives_alerts_p( + receives_alerts_p__user_id integer +) RETURNS boolean AS $$ +DECLARE + found_p boolean; +BEGIN + select EXISTS into found_p ( + select 1 from users + where no_alerts_until >= now() + and user_id = receives_alerts_p__user_id + ); + + return found_p; +END; +$$ LANGUAGE plpgsql stable; +