-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for un-intentional report cache busting when copying a collection
- Loading branch information
1 parent
4148b3b
commit 55ce468
Showing
4 changed files
with
143 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
--! Previous: sha1:b8cbc01e7d5166e77a68f5e3072082b77ff40769 | ||
--! Hash: sha1:34bba5d9e6dcba7e4de57df697d33c04c760aa76 | ||
|
||
-- Enter migration here | ||
CREATE OR REPLACE FUNCTION public.copy_sketch_toc_item_recursive(parent_id integer, type public.sketch_child_type, append_copy_to_name boolean) RETURNS integer | ||
LANGUAGE plpgsql | ||
security definer | ||
AS $$ | ||
declare | ||
copy_id int; | ||
child_copy_id int; | ||
is_collection boolean; | ||
child record; | ||
begin | ||
if type = 'sketch' then | ||
if it_me((select user_id from sketches where id = parent_id)) = false then | ||
raise exception 'Permission denied'; | ||
end if; | ||
else | ||
if it_me((select user_id from sketch_folders where id = parent_id)) = false then | ||
raise exception 'Permission denied'; | ||
end if; | ||
end if; | ||
SET session_replication_role = replica; | ||
if type = 'sketch' then | ||
-- copy it and get the copy id | ||
select id, is_collection(sketch_class_id) from copy_sketch(parent_id) into copy_id, is_collection; | ||
-- When copying a sketch from the forum, make sure its folder_id and collection_id are cleared | ||
if ((select shared_in_forum from sketches where id = parent_id)) then | ||
update sketches set collection_id = null, folder_id = null where id = copy_id; | ||
end if; | ||
if append_copy_to_name = true then | ||
update sketches set name = name || ' (copy)' where id = copy_id; | ||
end if; | ||
if is_collection then | ||
-- copy subfolders and sub-sketches | ||
FOR child IN SELECT * FROM get_children_of_collection(parent_id) | ||
LOOP | ||
raise notice 'copying %', child.type; | ||
select copy_sketch_toc_item_recursive(child.id, child.type, false) into child_copy_id; | ||
raise notice 'assigning collection_id=%', copy_id; | ||
if child.type = 'sketch_folder' then | ||
update sketch_folders set collection_id = copy_id, folder_id = null where id = child_copy_id; | ||
else | ||
update sketches set collection_id = copy_id, folder_id = null where id = child_copy_id; | ||
end if; | ||
END LOOP; | ||
end if; | ||
elsif type = 'sketch_folder' then | ||
-- copy it and get the copy id | ||
select id from copy_sketch_folder(parent_id) into copy_id; | ||
-- When copying a sketch from the forum, make sure its folder_id and collection_id are cleared | ||
if ((select shared_in_forum from sketch_folders where id = parent_id)) then | ||
update sketch_folders set collection_id = null, folder_id = null where id = copy_id; | ||
end if; | ||
if append_copy_to_name = true then | ||
update sketch_folders set name = name || ' (copy)' where id = copy_id; | ||
end if; | ||
-- copy subfolders and sub-sketches | ||
FOR child IN SELECT * FROM get_children_of_folder(parent_id) | ||
LOOP | ||
raise notice 'copying %', child.type; | ||
select copy_sketch_toc_item_recursive(child.id, child.type, false) into child_copy_id; | ||
raise notice 'assigning folder_id=%', copy_id; | ||
if child.type = 'sketch_folder' then | ||
update sketch_folders set folder_id = copy_id, collection_id = null where id = child_copy_id; | ||
else | ||
update sketches set folder_id = copy_id, collection_id = null where id = child_copy_id; | ||
end if; | ||
END LOOP; | ||
end if; | ||
SET session_replication_role = default; | ||
return copy_id; | ||
end; | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
-- Enter migration here | ||
-- Enter migration here |
Oops, something went wrong.