Menu : fix problem when cloning
This commit is contained in:
parent
f938c9073e
commit
840b674782
2 changed files with 59 additions and 3 deletions
|
|
@ -154,10 +154,17 @@ if (isset($_POST['clone']))
|
||||||
select 'copie de '||p_name,p_desc,with_calc,
|
select 'copie de '||p_name,p_desc,with_calc,
|
||||||
with_direct_form from profile where p_id=$1 returning p_id", array($p_id));
|
with_direct_form from profile where p_id=$1 returning p_id", array($p_id));
|
||||||
$cn->exec_sql("
|
$cn->exec_sql("
|
||||||
insert into profile_menu (p_id,me_code,me_code_dep,p_order,p_type_display,pm_default)
|
insert into profile_menu (p_id,me_code,me_code_dep,p_order,p_type_display,pm_default)
|
||||||
select $1,me_code,me_code_dep,p_order,p_type_display,pm_default from profile_menu
|
select $1,me_code,me_code_dep,p_order,p_type_display,pm_default from profile_menu
|
||||||
where p_id=$2
|
where p_id=$2
|
||||||
", array($new_id, $p_id));
|
", array($new_id, $p_id));
|
||||||
|
$cn->exec_sql("select menu_complete_dependency($1)",array($new_id));
|
||||||
|
$cn->exec_sql("update profile_menu
|
||||||
|
set pm_id_dep=(select distinct higher_dep
|
||||||
|
from v_menu_dependency as a
|
||||||
|
where
|
||||||
|
a.pm_id= profile_menu.pm_id)
|
||||||
|
where pm_id_dep is null and p_id=$1",array($new_id));
|
||||||
$cn->commit();
|
$cn->commit();
|
||||||
$p_id=$new_id;
|
$p_id=$new_id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -253,3 +253,52 @@ end;
|
||||||
LANGUAGE plpgsql ;
|
LANGUAGE plpgsql ;
|
||||||
|
|
||||||
update attr_def set ad_extra=4 where ad_id in (6,7);
|
update attr_def set ad_extra=4 where ad_id in (6,7);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION comptaproc.menu_complete_dependency(n_profile numeric)
|
||||||
|
RETURNS void AS
|
||||||
|
$BODY$
|
||||||
|
declare
|
||||||
|
n_count integer;
|
||||||
|
csr_root_menu cursor (p_profile numeric) is select pm_id,
|
||||||
|
me_code,
|
||||||
|
me_code_dep
|
||||||
|
|
||||||
|
from profile_menu
|
||||||
|
where
|
||||||
|
me_code in
|
||||||
|
(select a.me_code_dep
|
||||||
|
from profile_menu as a
|
||||||
|
join profile_menu as b on (a.me_code=b.me_code and a.me_code_dep=b.me_code_dep and a.pm_id <> b.pm_id and a.p_id=b.p_id)
|
||||||
|
where a.p_id=n_profile)
|
||||||
|
and p_id=p_profile;
|
||||||
|
|
||||||
|
begin
|
||||||
|
for duplicate in csr_root_menu(n_profile)
|
||||||
|
loop
|
||||||
|
raise notice 'found %',duplicate;
|
||||||
|
update profile_menu set pm_id_dep = duplicate.pm_id
|
||||||
|
where pm_id in (select a.pm_id
|
||||||
|
from profile_menu as a
|
||||||
|
left join profile_menu as b on (a.me_code=b.me_code and a.me_code_dep=b.me_code_dep)
|
||||||
|
where
|
||||||
|
a.p_id=n_profile
|
||||||
|
and b.p_id=n_profile
|
||||||
|
and a.pm_id_dep is null
|
||||||
|
and a.me_code_dep = duplicate.me_code
|
||||||
|
and a.pm_id < b.pm_id);
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
for duplicate in csr_root_menu(n_profile)
|
||||||
|
loop
|
||||||
|
select count(*) into n_count from profile_menu where p_id=n_profile and pm_id_dep = duplicate.pm_id;
|
||||||
|
raise notice '% use % times',duplicate,n_count;
|
||||||
|
if n_count = 0 then
|
||||||
|
raise notice ' Update with %',duplicate;
|
||||||
|
update profile_menu set pm_id_dep = duplicate.pm_id where p_id = n_profile and me_code_dep = duplicate.me_code and pm_id_dep is null;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
end loop;
|
||||||
|
|
||||||
|
end;
|
||||||
|
$BODY$
|
||||||
|
LANGUAGE plpgsql ;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue