Skip to content

Commit

Permalink
Merge branch 'hotfix-elastic'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvanbreda committed Jan 9, 2019
2 parents a3904de + 07bf124 commit 996f4bc
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 43 deletions.
2 changes: 0 additions & 2 deletions application/controllers/scheduled_tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,6 @@ private function loadOccurrencesDelta($plugin, $timestamp, $currentTime) {
when o.created_on>'$timestamp' then o.created_on
else greatest(o.updated_on, s.updated_on, sp.updated_on)
end as timestamp,
w.verification_checks_enabled,
lower(coalesce(onf.attr_stage, onf.attr_sex_stage)) as stage
into temporary occdelta
from occlist ol
Expand All @@ -806,7 +805,6 @@ private function loadOccurrencesDelta($plugin, $timestamp, $currentTime) {
join cache_occurrences_nonfunctional onf on onf.id=co.id
join samples s on s.id=o.sample_id and s.deleted=false
left join samples sp on sp.id=s.parent_id and sp.deleted=false
join websites w on w.id=o.website_id and w.deleted=false;
create index ix_occdelta_taxa_taxon_list_id on occdelta(taxa_taxon_list_id);
create index ix_occdelta_taxa_taxon_list_external_key on occdelta(taxa_taxon_list_external_key);
Expand Down
12 changes: 5 additions & 7 deletions modules/data_cleaner/controllers/services/data_cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
* 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.
*
* @package Services
* @author Indicia Team
* @author Indicia Team
* @license http://www.gnu.org/licenses/gpl.html GPL 3.0
* @link http://code.google.com/p/indicia/
*/
Expand Down Expand Up @@ -71,15 +70,14 @@ public function verify() {
LIMIT 0;
SQL
);
// Ensure the verify service always performs checks
$db->query("ALTER TABLE occdelta ADD COLUMN verification_checks_enabled boolean NOT NULL DEFAULT true;");
try {
$this->prepareOccdelta($db, $sample, $occurrences);
$r = $this->runRules($db);
$db->query('drop table occdelta');
$this->content_type = 'Content-Type: application/json';
$this->response = json_encode($r);
} catch (Exception $e) {
}
catch (Exception $e) {
$db->query('drop table occdelta');
$this->response = "Query failed";
error_logger::log_error('Error occurred calling verification rule service', $e);
Expand Down Expand Up @@ -118,8 +116,8 @@ private function prepareOccdelta($db, $sample, $occurrences) {
$date_start = $vd[0];
$date_end = $vd[1];
$date_type = $vd[2];
$db->query("insert into occdelta (website_id, survey_id, date_start, date_end, date_type, public_geom, taxa_taxon_list_id)
values ($website_id, $survey_id, '$date_start', '$date_end', '$date_type', st_geomfromtext('$geom', $srid), $taxa_taxon_list_id);");
$db->query("insert into occdelta (website_id, survey_id, date_start, date_end, date_type, public_geom, taxa_taxon_list_id, verification_checks_enabled)
values ($website_id, $survey_id, '$date_start', '$date_end', '$date_type', st_geomfromtext('$geom', $srid), $taxa_taxon_list_id, 't');");
}
// patch in some extra details about the taxon required for each cache entry
$db->query("update occdelta o set taxon_meaning_id=ttl.taxon_meaning_id, taxa_taxon_list_external_key=ttl.external_key ".
Expand Down
40 changes: 19 additions & 21 deletions modules/data_cleaner/tests/services/data_cleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
* 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.
*
* @package Services
* @subpackage Data
* @author Indicia Team
* @license http://www.gnu.org/licenses/gpl.html GPL
* @link http://code.google.com/p/indicia/
* @author Indicia Team
* @license http://www.gnu.org/licenses/gpl.html GPL
* @link https://github.com/indicia-team/warehouse/
*/

/**
Expand Down Expand Up @@ -174,25 +172,25 @@ public function testPeriodWithinYearFail() {
* data_cleaner_period_within_year module must be enabled.
*/
public function testPeriodWithinYearPass() {
$response = data_entry_helper::http_post($this->request, array(
'sample'=>json_encode(array(
'sample:survey_id'=>1,
'sample:date'=>'12/08/2012',
'sample:entered_sref'=>'SU1234',
'sample:entered_sref_system'=>'osgb'
)),
'occurrences'=>json_encode(array(
array(
'occurrence:taxa_taxon_list_id'=>1
))
),
'rule_types'=>json_encode(array('PeriodWithinYear'))
));
$errors = json_decode($response['output'], true);
$response = data_entry_helper::http_post($this->request, [
'sample' => json_encode([
'sample:survey_id' => 1,
'sample:date' => '12/08/2012',
'sample:entered_sref' => 'SU1234',
'sample:entered_sref_system' => 'osgb',
]),
'occurrences' => json_encode([
[
'occurrence:taxa_taxon_list_id' => 1,
],
]),
'rule_types' => json_encode(['PeriodWithinYear']),
]);
$errors = json_decode($response['output'], TRUE);

$this->assertTrue($response['result'], 'Invalid response');
$this->assertInternalType('array', $errors, 'Errors list not returned');
$this->assertCount(0, $errors, 'Errors contanied in list');
}

}
}
2 changes: 1 addition & 1 deletion modules/indicia_svc_data/controllers/services/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ protected function build_query_results($count=false)
// we have a filter on website_id to apply
if ($this->website_id) {
// check if a request for shared data is being made. Also check this is valid to prevent injection.
if (isset($_REQUEST['sharing']) && preg_match('/[reporting|peer_review|verification|data_flow|moderation|editing]/', $_REQUEST['sharing'])) {
if (isset($_REQUEST['sharing']) && preg_match('/(reporting|peer_review|verification|data_flow|moderation|editing)/', $_REQUEST['sharing'])) {
// request specifies the sharing mode (i.e. the task being performed, such as verification, moderation). So
// we can use this to work out access to other website data.
$this->db->join('index_websites_website_agreements as iwwa', array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function getDataSet() {
'updated_by_id' => 1,
'url' => 'http://www.indicia.org.uk',
'password' => 'password',
'verification_checks_enabled' => 'f',
),
),
'surveys' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
JOIN cache_occurrences_nonfunctional onf on onf.id=o.id
JOIN cache_samples_nonfunctional snf on snf.id=o.sample_id
JOIN cache_taxa_taxon_lists cttl on cttl.id=o.taxa_taxon_list_id
JOIN websites w on w.id=o.website_id and w.deleted=false
#agreements_join#
#joins#
WHERE #sharing_filter#
Expand All @@ -26,7 +25,7 @@
<column name='occurrence_id' display='ID' sql='o.id' datatype="integer"
template='&lt;span class="status-icon status-{record_status} release-{release_status} substatus-{record_substatus} query-{query} certainty-{certainty}" title="{status_hint}"&gt;&lt;/span&gt;&lt;span class="record-id"&gt;{occurrence_id}&lt;/span&gt;' />
<column name='source' display='Source' datatype="text"
sql="snf.website_title || ' | ' || case when substring(snf.survey_title from 1 for length(snf.website_title)) = w.title then trim(substring(snf.survey_title from length(snf.website_title)+1)) else snf.survey_title end" />
sql="snf.website_title || ' | ' || case when substring(snf.survey_title from 1 for length(snf.website_title)) = snf.website_title then trim(substring(snf.survey_title from length(snf.website_title)+1)) else snf.survey_title end" />
<column name='source_id' display='Source ID' datatype="text" visible="false"
sql="o.website_id::varchar || '|' || o.survey_id::varchar"
template="&lt;span title=&quot;{source}&quot;&gt;{source_id}&lt;/span&gt;" />
Expand Down Expand Up @@ -86,8 +85,8 @@
<column name='input_form' visible="false" sql="case when o.input_form is null then '#default_input_form#' else o.input_form end" datatype="text" />
<column name='pass' visible='false' sql="CASE
WHEN o.data_cleaner_result='t' THEN '&lt;div class=&quot;pass-icon&quot; title=&quot;Passes all auto-checks.&quot;&gt;&lt;/div&gt;'
WHEN true and w.verification_checks_enabled='f' THEN '&lt;div class=&quot;auto-check-disabled-icon&quot; title=&quot;Auto-check disabled.&quot;&gt;-&lt;/div&gt;'
WHEN w.verification_checks_enabled='t' AND o.data_cleaner_result IS NULL THEN '&lt;div class=&quot;pending-icon&quot; title=&quot;Pending auto-check.&quot;&gt;...&lt;/div&gt;'
WHEN true and o.verification_checks_enabled='f' THEN '&lt;div class=&quot;auto-check-disabled-icon&quot; title=&quot;Auto-check disabled.&quot;&gt;-&lt;/div&gt;'
WHEN o.verification_checks_enabled='t' AND o.data_cleaner_result IS NULL THEN '&lt;div class=&quot;pending-icon&quot; title=&quot;Pending auto-check.&quot;&gt;...&lt;/div&gt;'
END" />
<column name='fails' display='Auto check' template="{pass}{fails}"
sql="case when o.data_cleaner_result='f' then
Expand Down
3 changes: 3 additions & 0 deletions modules/phpUnit/config/core_fixture.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ websites:
updated_by_id: 1
url: "http://www.indicia.org.uk"
password: "password"
verification_checks_enabled: "true"


surveys:
Expand Down Expand Up @@ -606,6 +607,7 @@ cache_occurrences_functional:
map_sq_1km_id: 1
map_sq_2km_id: 1
map_sq_10km_id: 1
verification_checks_enabled: "true"
-
id: 2
sample_id: 1
Expand All @@ -629,6 +631,7 @@ cache_occurrences_functional:
map_sq_1km_id: 1
map_sq_2km_id: 1
map_sq_10km_id: 1
verification_checks_enabled: "true"

cache_occurrences_nonfunctional:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
JOIN cache_occurrences_nonfunctional onf on onf.id=o.id
JOIN cache_samples_nonfunctional snf on snf.id=o.sample_id
JOIN cache_taxa_taxon_lists cttl on cttl.id=o.taxa_taxon_list_id
JOIN websites w on w.id=o.website_id and w.deleted=false
LEFT JOIN index_websites_website_agreements canEdit on canEdit.from_website_id=o.website_id
and canEdit.to_website_id in (#website_ids#) and canEdit.provide_for_editing=true
#agreements_join#
Expand All @@ -35,7 +34,7 @@
<column name='occurrence_id' display='ID' sql='o.id' datatype="integer"
template='&lt;span class="status-icon status-{record_status} release-{release_status} substatus-{record_substatus} query-{query} certainty-{certainty}" title="{status_hint}"&gt;&lt;/span&gt;&lt;span class="record-id"&gt;{occurrence_id}&lt;/span&gt;' />
<column name='source' display='Source' datatype="text"
sql="snf.website_title || ' | ' || case when substring(snf.survey_title from 1 for length(snf.website_title)) = w.title then trim(substring(snf.survey_title from length(snf.website_title)+1)) else snf.survey_title end" />
sql="snf.website_title || ' | ' || case when substring(snf.survey_title from 1 for length(snf.website_title)) = snf.website_title then trim(substring(snf.survey_title from length(snf.website_title)+1)) else snf.survey_title end" />
<column name='source_id' display='Source ID' datatype="text" visible="false"
sql="o.website_id::varchar || '|' || o.survey_id::varchar"
template="&lt;span title=&quot;{source}&quot;&gt;{source_id}&lt;/span&gt;" />
Expand Down Expand Up @@ -74,8 +73,8 @@
end" datatype="text" />
<column name='pass' visible='false' sql="CASE
WHEN o.data_cleaner_result='t' THEN '&lt;div class=&quot;pass-icon&quot; title=&quot;Passes all auto-checks.&quot;&gt;&lt;/div&gt;'
WHEN true and w.verification_checks_enabled='f' THEN '&lt;div class=&quot;auto-check-disabled-icon&quot; title=&quot;Auto-check disabled.&quot;&gt;-&lt;/div&gt;'
WHEN w.verification_checks_enabled='t' AND o.data_cleaner_result IS NULL THEN '&lt;div class=&quot;pending-icon&quot; title=&quot;Pending auto-check.&quot;&gt;...&lt;/div&gt;'
WHEN true and o.verification_checks_enabled='f' THEN '&lt;div class=&quot;auto-check-disabled-icon&quot; title=&quot;Auto-check disabled.&quot;&gt;-&lt;/div&gt;'
WHEN o.verification_checks_enabled='t' AND o.data_cleaner_result IS NULL THEN '&lt;div class=&quot;pending-icon&quot; title=&quot;Pending auto-check.&quot;&gt;...&lt;/div&gt;'
END" />
<column name='fails' display='Auto check' template="{pass}{fails}"
sql="case when o.data_cleaner_result='f' then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
JOIN cache_samples_nonfunctional snf on snf.id=o.sample_id
JOIN samples s on s.id=o.sample_id and s.deleted=false
JOIN cache_taxa_taxon_lists cttl on cttl.id=o.taxa_taxon_list_id
JOIN websites w on w.id=o.website_id and w.deleted=false
LEFT JOIN index_websites_website_agreements canEdit on canEdit.from_website_id=o.website_id
and canEdit.to_website_id in (#website_ids#) and canEdit.provide_for_editing=true
JOIN workflow_metadata wm ON wm.key='taxa_taxon_list_external_key'
Expand Down Expand Up @@ -62,7 +61,7 @@
&lt;input type='hidden' class='external_key' value='{external_key}' /&gt;" />
<column name="external_key" display="External key" sql="cttl.external_key" datatype="text" visible="false" />
<column name="source" display="Source" datatype="text"
sql="snf.website_title || ' | ' || case when substring(snf.survey_title from 1 for length(snf.website_title)) = w.title then trim(substring(snf.survey_title from length(snf.website_title)+1)) else snf.survey_title end" />
sql="snf.website_title || ' | ' || case when substring(snf.survey_title from 1 for length(snf.website_title)) = snf.website_title then trim(substring(snf.survey_title from length(snf.website_title)+1)) else snf.survey_title end" />
<column name="source_id" display="Source ID" datatype="text" visible="false"
sql="o.website_id::varchar || '|' || o.survey_id::varchar"
template="&lt;span title=&quot;{source}&quot;&gt;{source_id}&lt;/span&gt;" />
Expand Down Expand Up @@ -100,8 +99,8 @@
end" datatype="text" />
<column name='pass' visible='false' sql="CASE
WHEN o.data_cleaner_result='t' THEN '&lt;div class=&quot;pass-icon&quot; title=&quot;Passes all auto-checks.&quot;&gt;&lt;/div&gt;'
WHEN true and w.verification_checks_enabled='f' THEN '&lt;div class=&quot;auto-check-disabled-icon&quot; title=&quot;Auto-check disabled.&quot;&gt;-&lt;/div&gt;'
WHEN w.verification_checks_enabled='t' AND o.data_cleaner_result IS NULL THEN '&lt;div class=&quot;pending-icon&quot; title=&quot;Pending auto-check.&quot;&gt;...&lt;/div&gt;'
WHEN true and o.verification_checks_enabled='f' THEN '&lt;div class=&quot;auto-check-disabled-icon&quot; title=&quot;Auto-check disabled.&quot;&gt;-&lt;/div&gt;'
WHEN o.verification_checks_enabled='t' AND o.data_cleaner_result IS NULL THEN '&lt;div class=&quot;pending-icon&quot; title=&quot;Pending auto-check.&quot;&gt;...&lt;/div&gt;'
END" />
<column name="fails" display="Auto check" template="{pass}{fails}"
sql="case when o.data_cleaner_result='f' then
Expand Down

0 comments on commit 996f4bc

Please sign in to comment.