|
| 1 | +-- © 2025 and later: Unicode, Inc. and others. |
| 2 | +-- SPDX-License-Identifier: Unicode-3.0 |
| 3 | + |
| 4 | +-- USAGE: |
| 5 | +-- CALL update_org_cla('airbnb','48','2023-08-28'); |
| 6 | +-- pass in the org, the version, and the signed date |
| 7 | +-- will update all users in the ENTIRE org. |
| 8 | + |
| 9 | +DROP PROCEDURE IF EXISTS update_org_cla; |
| 10 | +DELIMITER ;; |
| 11 | +CREATE PROCEDURE update_org_cla (IN my_org VARCHAR(256), IN my_version VARCHAR(122), IN signed_date VARCHAR(20)) |
| 12 | +BEGIN |
| 13 | + -- the set_id for CLA requests |
| 14 | + DECLARE set_cla INT; |
| 15 | + DECLARE usr_id INT; |
| 16 | + DECLARE usr_email VARCHAR(256); |
| 17 | + DECLARE usr_name VARCHAR(256); |
| 18 | + -- cursor for users in the org |
| 19 | + DECLARE done INT DEFAULT FALSE; |
| 20 | + DECLARE usr CURSOR FOR select id, email, name FROM cldr_users WHERE org = my_org; |
| 21 | + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; |
| 22 | + -- get the set_id for set_cla |
| 23 | + SELECT set_id FROM set_kinds WHERE set_name = 'SignedCla' INTO set_cla; |
| 24 | + OPEN usr; |
| 25 | + usr_loop: LOOP |
| 26 | + FETCH usr INTO usr_id, usr_email, usr_name; |
| 27 | + IF done THEN |
| 28 | + LEAVE usr_loop; |
| 29 | + END IF; |
| 30 | + SET @v = CONCAT( |
| 31 | + '{"email":"', usr_email, |
| 32 | + '","name":"', usr_name, |
| 33 | + '","employer":"', my_org, |
| 34 | + '","corporate":"true","version":"', my_version, |
| 35 | + '","signed":"', signed_date, |
| 36 | + '","readonly":"true"}'); |
| 37 | + select usr_id, set_cla, @v; |
| 38 | + REPLACE INTO set_values (usr_id, set_id, set_value) |
| 39 | + values (usr_id, set_cla, @v); |
| 40 | + END LOOP; |
| 41 | +END;; |
| 42 | +DELIMITER ; |
0 commit comments