-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,574 additions
and
145 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
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
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
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
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
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
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
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
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
File renamed without changes.
86 changes: 86 additions & 0 deletions
86
modules/cache_builder/helpers/task_cache_builder_taxonomy_occurrence.php
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,86 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Queue worker to update cache_occurrences_functional.taxon_path. | ||
* | ||
* Indicia, the OPAL Online Recording Toolkit. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/gpl.html. | ||
* | ||
* @author Indicia Team | ||
* @license http://www.gnu.org/licenses/gpl.html GPL | ||
* @link https://github.com/indicia-team/warehouse | ||
*/ | ||
|
||
defined('SYSPATH') or die('No direct script access.'); | ||
|
||
/** | ||
* Queue worker to update cache_occurrences_functional taxonomy related fields. | ||
* | ||
* E.g. for a rename taxon UKSI operation, occurrences get a new external key, | ||
* so need to update cache_occurrences_functional. | ||
*/ | ||
class task_cache_builder_taxonomy_occurrence { | ||
|
||
/** | ||
* Not a fast operation. | ||
*/ | ||
const BATCH_SIZE = 10; | ||
|
||
/** | ||
* Perform the processing for a task batch found in the queue. | ||
* | ||
* Note that this task updates occurrences, but the stored record in the | ||
* work_queue task should be a taxa_taxon_list. Otherwise huge numbers of | ||
* work queue tasks are required. | ||
* | ||
* @param object $db | ||
* Database connection object. | ||
* @param object $taskType | ||
* Object read from the database for the task batch. Contains the task | ||
* name, entity, priority, created_on of the first record in the batch | ||
* count (total number of queued tasks of this type). | ||
* @param string $procId | ||
* Unique identifier of this work queue processing run. Allows filtering | ||
* against the work_queue table's claimed_by field to determine which | ||
* tasks to perform. | ||
*/ | ||
public static function process($db, $taskType, $procId) { | ||
$masterListId = warehouse::getMasterTaxonListId(); | ||
$sql = <<<SQL | ||
UPDATE cache_occurrences_functional o | ||
SET taxon_path=ctp.path, | ||
preferred_taxa_taxon_list_id=cttl.preferred_taxa_taxon_list_id, | ||
taxa_taxon_list_external_key=cttl.external_key, | ||
taxon_meaning_id=cttl.taxon_meaning_id, | ||
family_taxa_taxon_list_id=cttl.family_taxa_taxon_list_id, | ||
taxon_group_id=cttl.taxon_group_id, | ||
taxon_rank_sort_order=cttl.taxon_rank_sort_order, | ||
marine_flag=cttl.marine_flag, | ||
freshwater_flag=cttl.freshwater_flag, | ||
terrestrial_flag=cttl.terrestrial_flag, | ||
non_native_flag=cttl.non_native_flag | ||
FROM work_queue q, cache_taxa_taxon_lists cttl | ||
LEFT JOIN cache_taxon_paths ctp | ||
ON ctp.taxon_meaning_id=cttl.taxon_meaning_id | ||
AND ctp.taxon_list_id=$masterListId | ||
WHERE cttl.id=o.taxa_taxon_list_id | ||
AND cttl.taxon_list_id=$masterListId | ||
AND o.taxa_taxon_list_id=q.record_id | ||
AND q.entity='taxa_taxon_list' | ||
AND q.task='task_cache_builder_taxonomy_occurrence' | ||
AND q.claimed_by='$procId'; | ||
SQL; | ||
$db->query($sql); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
modules/indicia_setup/db/version_4_10_0/202011091217_base36_fn.sql
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,24 @@ | ||
CREATE OR REPLACE FUNCTION base36_encode(IN digits bigint, IN min_width int = 0) RETURNS varchar AS $$ | ||
DECLARE | ||
chars char[]; | ||
ret varchar; | ||
val bigint; | ||
BEGIN | ||
chars := ARRAY['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']; | ||
val := digits; | ||
ret := ''; | ||
IF val < 0 THEN | ||
val := val * -1; | ||
END IF; | ||
WHILE val != 0 LOOP | ||
ret := chars[(val % 36)+1] || ret; | ||
val := val / 36; | ||
END LOOP; | ||
|
||
IF min_width > 0 AND char_length(ret) < min_width THEN | ||
ret := lpad(ret, min_width, '0'); | ||
END IF; | ||
|
||
RETURN ret; | ||
END; | ||
$$ LANGUAGE plpgsql IMMUTABLE; |
51 changes: 51 additions & 0 deletions
51
modules/indicia_setup/db/version_4_10_0/202011101004_reduce_precision.sql
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,51 @@ | ||
CREATE OR REPLACE FUNCTION reduce_precision( | ||
geom_in geometry, | ||
confidential boolean, | ||
reduce_to_precision integer) | ||
RETURNS geometry AS | ||
$BODY$ | ||
DECLARE geom geometry; | ||
DECLARE geomltln geometry; | ||
DECLARE r geometry; | ||
DECLARE precisionM integer; | ||
DECLARE x float; | ||
DECLARE y float; | ||
DECLARE srid integer; | ||
DECLARE sref_metadata record; | ||
BEGIN | ||
IF confidential = true OR COALESCE(reduce_to_precision, 0)>1 THEN | ||
precisionM = CASE | ||
WHEN COALESCE(reduce_to_precision, 0)>1 THEN reduce_to_precision | ||
ELSE 1000 | ||
END; | ||
srid = get_output_srid(geom_in); | ||
IF srid<>900913 THEN | ||
geom = st_transform(geom_in, srid); | ||
ELSE | ||
geom = geom_in; | ||
END IF; | ||
-- If lower precision than requested, then can return as it is. | ||
-- If same precision allowing for rounding errors, then re-calculate to ensure | ||
-- all square geoms are consistent for aggregation purposes. | ||
IF floor(sqrt(st_area(geom))) > precisionM THEN | ||
r = geom_in; | ||
ELSE | ||
geom = st_centroid(geom); | ||
-- need to reduce this to a square on the grid | ||
x = floor(st_xmin(geom)::NUMERIC / precisionM) * precisionM; | ||
y = floor(st_ymin(geom)::NUMERIC / precisionM) * precisionM; | ||
r = st_geomfromtext('polygon((' || x::varchar || ' ' || y::varchar || ',' || (x + precisionM)::varchar || ' ' || y::varchar || ',' | ||
|| (x + precisionM)::varchar || ' ' || (y + precisionM)::varchar || ',' || x::varchar || ' ' || (y + precisionM)::varchar || ',' | ||
|| x::varchar || ' ' || y::varchar || '))', srid); | ||
IF srid<>900913 THEN | ||
r = st_transform(r, 900913); | ||
END IF; | ||
END IF; | ||
ELSE | ||
r = geom_in; | ||
END IF; | ||
RETURN r; | ||
END; | ||
$BODY$ | ||
LANGUAGE plpgsql IMMUTABLE | ||
COST 100; |
3 changes: 3 additions & 0 deletions
3
modules/indicia_setup/db/version_4_10_0/202012041304_unique_email_idx.sql
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,3 @@ | ||
DROP INDEX ix_unique_email_address; | ||
|
||
CREATE UNIQUE INDEX ix_unique_email_address ON people (email_address) WHERE deleted='f' AND email_address !='' AND email_address is not null; |
5 changes: 5 additions & 0 deletions
5
modules/indicia_setup/db/version_4_10_0/202012070927_organism_key.sql
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,5 @@ | ||
ALTER TABLE taxa | ||
ADD COLUMN organism_key varchar; | ||
|
||
COMMENT ON COLUMN taxa.organism_key | ||
IS 'Identifier for the organism concept, e.g. when linking to UKSI.'; |
Oops, something went wrong.