Skip to content

Instantly share code, notes, and snippets.

@lisachenko
Created January 29, 2019 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lisachenko/6079e77d8d50377033687a85105be0ac to your computer and use it in GitHub Desktop.
Save lisachenko/6079e77d8d50377033687a85105be0ac to your computer and use it in GitHub Desktop.
Symfony ACL reorder ACE
DELIMITER ;;
DROP PROCEDURE IF EXISTS fix_ace_order;
CREATE PROCEDURE fix_ace_order()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE acl_id INT;
DECLARE acl_cursor CURSOR FOR SELECT o.id
FROM acl_object_identities o
LEFT JOIN acl_entries e ON (
e.class_id = o.class_id AND
e.object_identity_id = o.id)
group by concat(o.id, ';', e.ace_order)
having count(concat(o.id, ';', e.ace_order)) > 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN acl_cursor;
read_loop:
LOOP
FETCH acl_cursor INTO acl_id;
IF done THEN
LEAVE read_loop;
END IF;
SET @n := -1;
UPDATE acl_entries e
SET ace_order = (@n := @n + 1)
WHERE object_identity_id = acl_id;
END LOOP;
CLOSE acl_cursor;
END;
;;
CALL fix_ace_order()
;;
@lisachenko
Copy link
Author

This small SQL procedure allows to reorder broken ordering of ACE records in Symfony ACL database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment