Skip to content

Commit

Permalink
Merge branch 'hotfix-485_redundant_names'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvanbreda committed Aug 2, 2023
2 parents 48d8c80 + 8a18fa5 commit 94d1dd9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
4 changes: 2 additions & 2 deletions application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
*
* @var string
*/
$config['version'] = '8.21.8';
$config['version'] = '8.21.9';

/**
* Version release date.
*
* @var string
*/
$config['release_date'] = '2023-07-31';
$config['release_date'] = '2023-08-01';

/**
* Link to the code repository downloads page.
Expand Down
76 changes: 49 additions & 27 deletions modules/cache_builder/config/cache_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
select distinct on (tlt.id) tlt.id, tl.deleted or tlt.deleted or tltpref.deleted or t.deleted or l.deleted or tpref.deleted or lpref.deleted as deleted
from termlists tl
join termlists_terms tlt on tlt.termlist_id=tl.id
join termlists_terms tltpref on tltpref.meaning_id=tlt.meaning_id and tltpref.preferred='t'
join termlists_terms tltpref on tltpref.meaning_id=tlt.meaning_id and tltpref.preferred=true
join terms t on t.id=tlt.term_id
join languages l on l.id=t.language_id
join terms tpref on tpref.id=tltpref.term_id
Expand All @@ -40,7 +40,7 @@
select distinct on (tlt.id) tlt.id, tl.deleted or tlt.deleted or tltpref.deleted or t.deleted or l.deleted or tpref.deleted or lpref.deleted as deleted
from termlists tl
join termlists_terms tlt on tlt.termlist_id=tl.id
join termlists_terms tltpref on tltpref.meaning_id=tlt.meaning_id and tltpref.preferred='t'
join termlists_terms tltpref on tltpref.meaning_id=tlt.meaning_id and tltpref.preferred=true
join terms t on t.id=tlt.term_id
join languages l on l.id=t.language_id
join terms tpref on tpref.id=tltpref.term_id
Expand Down Expand Up @@ -74,7 +74,7 @@
from termlists tl
join termlists_terms tlt on tlt.termlist_id=tl.id
#join_needs_update#
join termlists_terms tltpref on tltpref.meaning_id=tlt.meaning_id and tltpref.preferred='t'
join termlists_terms tltpref on tltpref.meaning_id=tlt.meaning_id and tltpref.preferred=true
join terms t on t.id=tlt.term_id
join languages l on l.id=t.language_id
join terms tpref on tpref.id=tltpref.term_id
Expand All @@ -99,7 +99,7 @@
join termlists_terms tlt on tlt.termlist_id=tl.id
#join_needs_update#
left join cache_termlists_terms ctlt on ctlt.id=tlt.id
join termlists_terms tltpref on tltpref.meaning_id=tlt.meaning_id and tltpref.preferred='t'
join termlists_terms tltpref on tltpref.meaning_id=tlt.meaning_id and tltpref.preferred=true
join terms t on t.id=tlt.term_id and t.deleted=false
join languages l on l.id=t.language_id and l.deleted=false
join terms tpref on tpref.id=tltpref.term_id
Expand All @@ -116,7 +116,7 @@
or l.deleted or tpref.deleted or tg.deleted or lpref.deleted as deleted
from taxon_lists tl
join taxa_taxon_lists ttl on ttl.taxon_list_id=tl.id
join taxa_taxon_lists ttlpref on ttlpref.taxon_meaning_id=ttl.taxon_meaning_id and ttlpref.preferred='t' and ttlpref.taxon_list_id=ttl.taxon_list_id
join taxa_taxon_lists ttlpref on ttlpref.taxon_meaning_id=ttl.taxon_meaning_id and ttlpref.preferred=true and ttlpref.taxon_list_id=ttl.taxon_list_id
join taxa t on t.id=ttl.taxon_id
join languages l on l.id=t.language_id
join taxa tpref on tpref.id=ttlpref.taxon_id
Expand Down Expand Up @@ -216,9 +216,9 @@
taxon_list_id=tl.id,
taxon_list_title=tl.title,
website_id=tl.website_id,
preferred_taxa_taxon_list_id=ttlpref.id,
parent_id=ttlpref.parent_id,
taxonomic_sort_order=ttlpref.taxonomic_sort_order,
preferred_taxa_taxon_list_id=coalesce(ttlpref.id, ttlprefredundant.id),
parent_id=coalesce(ttlpref.parent_id, ttlprefredundant.parent_id),
taxonomic_sort_order=coalesce(ttlpref.taxonomic_sort_order, ttlprefredundant.taxonomic_sort_order),
taxon=t.taxon || coalesce(' ' || t.attribute, ''),
authority=t.authority,
language_iso=l.iso,
Expand All @@ -231,7 +231,7 @@
search_name=regexp_replace(regexp_replace(regexp_replace(lower(t.taxon), E'\\\\(.+\\\\)', '', 'g'), 'ae', 'e', 'g'), E'[^a-z0-9\\\\?\\\\+]', '', 'g'),
external_key=tpref.external_key,
organism_key=tpref.organism_key,
taxon_meaning_id=ttlpref.taxon_meaning_id,
taxon_meaning_id=coalesce(ttlpref.taxon_meaning_id, ttlprefredundant.taxon_meaning_id),
taxon_group_id = tpref.taxon_group_id,
taxon_group = tg.title,
taxon_rank_id = tr.id,
Expand All @@ -248,19 +248,27 @@
from taxon_lists tl
join taxa_taxon_lists ttl on ttl.taxon_list_id=tl.id
#join_needs_update#
join taxa_taxon_lists ttlpref
-- Select the preferred name which isn't redundant (allow_data_entry=true)
left join taxa_taxon_lists ttlpref
on ttlpref.taxon_meaning_id=ttl.taxon_meaning_id
and ttlpref.preferred=true
and ttlpref.taxon_list_id=ttl.taxon_list_id
and ttlpref.deleted=false
and (ttlpref.allow_data_entry=ttl.allow_data_entry or ttlpref.allow_data_entry=true)
and ttlpref.allow_data_entry=true
-- A fallback preferred name which is redundant (allow_data_entry=false)
left join taxa_taxon_lists ttlprefredundant
on ttlprefredundant.taxon_meaning_id=ttl.taxon_meaning_id
and ttlprefredundant.preferred=true
and ttlprefredundant.taxon_list_id=ttl.taxon_list_id
and ttlprefredundant.deleted=false
and ttlprefredundant.allow_data_entry=false
join taxa t on t.id=ttl.taxon_id and t.deleted=false
join languages l on l.id=t.language_id and l.deleted=false
join taxa tpref on tpref.id=ttlpref.taxon_id and tpref.deleted=false
join taxa tpref on tpref.id=coalesce(ttlpref.taxon_id, ttlprefredundant.taxon_id) and tpref.deleted=false
join taxon_groups tg on tg.id=tpref.taxon_group_id and tg.deleted=false
left join taxon_ranks tr on tr.id=t.taxon_rank_id and tr.deleted=false
join languages lpref on lpref.id=tpref.language_id and lpref.deleted=false
left join taxa tcommon on tcommon.id=ttlpref.common_taxon_id and tcommon.deleted=false
left join taxa tcommon on tcommon.id=coalesce(ttlpref.common_taxon_id, ttlprefredundant.common_taxon_id) and tcommon.deleted=false
where cttl.id=ttl.id";

$config['taxa_taxon_lists']['insert'] = "insert into cache_taxa_taxon_lists (
Expand All @@ -276,14 +284,18 @@
)
select distinct on (ttl.id) ttl.id, ttl.preferred,
tl.id as taxon_list_id, tl.title as taxon_list_title, tl.website_id,
ttlpref.id as preferred_taxa_taxon_list_id, ttlpref.parent_id, ttlpref.taxonomic_sort_order,
coalesce(ttlpref.id, ttlprefredundant.id) as preferred_taxa_taxon_list_id,
coalesce(ttlpref.parent_id, ttlprefredundant.parent_id) as parent_id,
coalesce(ttlpref.taxonomic_sort_order, ttlprefredundant.taxonomic_sort_order) as taxonomic_sort_order,
t.taxon || coalesce(' ' || t.attribute, ''), t.authority,
l.iso as language_iso, l.language,
tpref.taxon || coalesce(' ' || tpref.attribute, '') as preferred_taxon, tpref.authority as preferred_authority,
lpref.iso as preferred_language_iso, lpref.language as preferred_language,
tcommon.taxon as default_common_name,
regexp_replace(regexp_replace(regexp_replace(lower(t.taxon), E'\\\\(.+\\\\)', '', 'g'), 'ae', 'e', 'g'), E'[^a-z0-9\\\\?\\\\+]', '', 'g'),
tpref.external_key, tpref.organism_key, ttlpref.taxon_meaning_id, tpref.taxon_group_id, tg.title,
tpref.external_key, tpref.organism_key,
coalesce(ttlpref.taxon_meaning_id, ttlprefredundant.taxon_meaning_id) as taxon_meaning_id,
tpref.taxon_group_id, tg.title,
tr.id, tr.rank, tr.sort_order,
now(), now(), ttl.allow_data_entry,
t.marine_flag, t.freshwater_flag, t.terrestrial_flag, t.non_native_flag,
Expand All @@ -292,20 +304,30 @@
join taxa_taxon_lists ttl on ttl.taxon_list_id=tl.id and ttl.deleted=false
#join_needs_update#
left join cache_taxa_taxon_lists cttl on cttl.id=ttl.id
join taxa_taxon_lists ttlpref
-- Select the preferred name which isn't redundant (allow_data_entry=true)
left join taxa_taxon_lists ttlpref
on ttlpref.taxon_meaning_id=ttl.taxon_meaning_id
and ttlpref.preferred='t'
and ttlpref.preferred=true
and ttlpref.taxon_list_id=ttl.taxon_list_id
and ttlpref.deleted=false
and ttlpref.allow_data_entry=ttl.allow_data_entry
and ttlpref.allow_data_entry=true
-- A fallback preferred name which is redundant (allow_data_entry=false)
left join taxa_taxon_lists ttlprefredundant
on ttlprefredundant.taxon_meaning_id=ttl.taxon_meaning_id
and ttlprefredundant.preferred=true
and ttlprefredundant.taxon_list_id=ttl.taxon_list_id
and ttlprefredundant.deleted=false
and ttlprefredundant.allow_data_entry=false
join taxa t on t.id=ttl.taxon_id and t.deleted=false and t.deleted=false
join languages l on l.id=t.language_id and l.deleted=false and l.deleted=false
join taxa tpref on tpref.id=ttlpref.taxon_id and tpref.deleted=false
join taxa tpref on tpref.id=coalesce(ttlpref.taxon_id, ttlprefredundant.taxon_id) and tpref.deleted=false
join taxon_groups tg on tg.id=tpref.taxon_group_id and tg.deleted=false
left join taxon_ranks tr on tr.id=t.taxon_rank_id and tr.deleted=false
join languages lpref on lpref.id=tpref.language_id and lpref.deleted=false
left join taxa tcommon on tcommon.id=ttlpref.common_taxon_id and tcommon.deleted=false
where cttl.id is null and tl.deleted=false";
left join taxa tcommon on tcommon.id=coalesce(ttlpref.common_taxon_id, ttlprefredundant.common_taxon_id) and tcommon.deleted=false
where cttl.id is null and tl.deleted=false
-- Must have one or other preferred name available.
and (ttlpref.id is not null or ttlprefredundant.id is not null)";

$config['taxa_taxon_lists']['join_needs_update'] = 'join needs_update_taxa_taxon_lists nu on nu.id=ttl.id and nu.deleted=false';
$config['taxa_taxon_lists']['key_field'] = 'ttl.id';
Expand Down Expand Up @@ -436,7 +458,7 @@
from taxon_lists tl
join taxa_taxon_lists ttl on ttl.taxon_list_id=tl.id
join taxa_taxon_lists ttlpref on ttlpref.taxon_meaning_id=ttl.taxon_meaning_id
and ttlpref.preferred='t'
and ttlpref.preferred=true
and ttlpref.taxon_list_id=ttl.taxon_list_id
join taxa t on t.id=ttl.taxon_id
join languages l on l.id=t.language_id
Expand Down Expand Up @@ -723,7 +745,7 @@
cttl.external_key, cttl.organism_key, cttl.authority, cttl.search_code, cttl.taxonomic_sort_order, cttl.taxon_rank
from cache_taxa_taxon_lists cttl
#join_needs_update#
left join cache_taxon_searchterms cts on cts.taxa_taxon_list_id=cttl.id and cts.name_type in ('L','S','V') and cts.simplified='f'
left join cache_taxon_searchterms cts on cts.taxa_taxon_list_id=cttl.id and cts.name_type in ('L','S','V') and cts.simplified=false
where cts.taxa_taxon_list_id is null and cttl.allow_data_entry=true";

$config['taxon_searchterms']['insert']['abbreviations'] = "insert into cache_taxon_searchterms (
Expand Down Expand Up @@ -1629,8 +1651,8 @@
LEFT JOIN cache_taxon_paths ctp ON ctp.external_key=cttl.external_key AND ctp.taxon_list_id=COALESCE(#master_list_id#, cttl.taxon_list_id)
LEFT JOIN (occurrence_attribute_values oav
JOIN termlists_terms certainty ON certainty.id=oav.int_value
JOIN occurrence_attributes oa ON oa.id=oav.occurrence_attribute_id and oa.deleted='f' and oa.system_function='certainty'
) ON oav.occurrence_id=o.id AND oav.deleted='f'
JOIN occurrence_attributes oa ON oa.id=oav.occurrence_attribute_id and oa.deleted=false and oa.system_function='certainty'
) ON oav.occurrence_id=o.id AND oav.deleted=false
LEFT JOIN occurrence_comments oc1 ON oc1.occurrence_id=o.id AND oc1.deleted=false AND oc1.auto_generated=false
AND oc1.query=true AND (o.verified_on IS NULL OR oc1.created_on>o.verified_on)
LEFT JOIN occurrence_comments oc2 ON oc2.occurrence_id=o.id AND oc2.deleted=false AND oc2.auto_generated=false
Expand Down Expand Up @@ -1877,8 +1899,8 @@
LEFT JOIN cache_taxon_paths ctp ON ctp.external_key=cttl.external_key AND ctp.taxon_list_id=#master_list_id#
LEFT JOIN (occurrence_attribute_values oav
JOIN termlists_terms certainty ON certainty.id=oav.int_value
JOIN occurrence_attributes oa ON oa.id=oav.occurrence_attribute_id and oa.deleted='f' and oa.system_function='certainty'
) ON oav.occurrence_id=o.id AND oav.deleted='f'
JOIN occurrence_attributes oa ON oa.id=oav.occurrence_attribute_id and oa.deleted=false and oa.system_function='certainty'
) ON oav.occurrence_id=o.id AND oav.deleted=false
WHERE o.deleted=false
AND co.id IS NULL
";
Expand Down

0 comments on commit 94d1dd9

Please sign in to comment.