Skip to content

Commit

Permalink
Merge pull request Silvanite#64 from SGS-Optimisation/main
Browse files Browse the repository at this point in the history
fix rule filter too permissive
  • Loading branch information
yayann authored Jul 14, 2021
2 parents d6f9386 + e1287c7 commit dcebf29
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/Services/Rule/RuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ function ($job, $mapping) {
$mysgsValue = [$mysgsValue];
}

$matchedAtLeastOnce = false;
foreach ($mysgsValue as $index => $mysgsValue_single) {
if (empty($mysgsValue_single)) {
continue;
}
/*logger(sprintf('checking taxo %s for term "%s" against mysgs value: %s',
logger(sprintf('checking taxo %s for term "%s" against mysgs value: %s',
$term->taxonomy->name, $termValue, print_r($mysgsValue_single, true))
);*/
);
if (!(Str::is($termValue, Str::lower($mysgsValue_single))
|| (
isset($term->config['aliases'])
Expand All @@ -116,37 +117,40 @@ function ($job, $mapping) {
)
)
)) {
/*logger(sprintf('rule %s dropped, term %s did not match with %s',
logger(sprintf('rule %s dropped, term %s did not match with %s',
$rule->id, $termValue, $mysgsValue_single)
);*/
);
$matched = false;
} else {
$matchedTaxonomies[$term->taxonomy->name] = true;
$matchedAtLeastOnce = true;

/*logger(sprintf('rule %s added, term %s matched with %s',
logger(sprintf('rule %s added, term %s matched with %s',
$rule->id, $termValue, $mysgsValue_single)
);*/
);

if (!in_array($term->name, $job_taxonomy_terms_matches[$term->taxonomy->name])) {
$job_taxonomy_terms_matches[$term->taxonomy->name][] = $term->name;
}
}
}

$matched = ($matched || $matchedAtLeastOnce);
}
}
}

$taxonomyMatch = false;
$taxonomyMatch = true;
foreach ($matchedTaxonomies as $taxonomy => $state) {
$taxonomyMatch |= $state;
$taxonomyMatch &= $state;
}

if ($matched || $taxonomyMatch) {
$clientRules[] = $rule;
} else {
/*logger(sprintf('rule %s dropped, matched=%b taxoMatch=%b ',
logger(sprintf('rule %s dropped, matched=%b taxoMatch=%b ',
$rule->id, $matched, $taxonomyMatch)
);*/
);
}
}

Expand Down

0 comments on commit dcebf29

Please sign in to comment.