###
### Spam detection configuration preparation
###

# Allow Admin to edit the spam configuration 
touch /usr/lib/gforge/www/include/spam_rules_config.php
chown apache:apache /usr/lib/gforge/www/include/spam_rules_config.php

###
### [#4712] Remove duplicate project associations
###

# Execute the following to see if some associations need to be removed by hand

select * from group_subproject
 where exists (select 'x'
               from group_subproject i, subproject_type sta, subproject_type stb
               where (i.source_group = group_subproject.source_group
                      and i.destination_group = group_subproject.destination_group
                      and i.subproject_type_id = group_subproject.subproject_type_id
                      and i.id < group_subproject.id)
                     OR 
                     (i.source_group = group_subproject.destination_group
                      and i.destination_group = group_subproject.source_group
                      and sta.subproject_type_id = group_subproject.subproject_type_id
                      and stb.destination_name = sta.source_name
                      and i.subproject_type_id = stb.subproject_type_id
                      and i.id < group_subproject.id));

# If you can automatically remove them, use

delete from group_subproject
 where exists (select 'x'
               from group_subproject i, subproject_type sta, subproject_type stb
               where (i.source_group = group_subproject.source_group
                      and i.destination_group = group_subproject.destination_group
                      and i.subproject_type_id = group_subproject.subproject_type_id
                      and i.id < group_subproject.id)
                     OR 
                     (i.source_group = group_subproject.destination_group
                      and i.destination_group = group_subproject.source_group
                      and sta.subproject_type_id = group_subproject.subproject_type_id
                      and stb.destination_name = sta.source_name
                      and i.subproject_type_id = stb.subproject_type_id
                      and i.id < group_subproject.id));
