Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
# Named by path because no job in this matrix runs the tests/ root, only its
# subdirectories - a file added there runs nowhere unless it is listed here.
- { name: "PresentationMediaUploads", filter: "tests/PresentationMediaUploadsTest.php tests/PresentationMediaUploadsVisibilityTest.php tests/PresentationSerializerCacheKeyTest.php tests/PresentationReopenModelTest.php tests/PresentationReopenApiTest.php tests/PresentationReopenAuthzTest.php tests/PresentationSubmissionReopenedEmailTest.php" }
- { name: "SpeakerSubmitterPublishedFilter", filter: "tests/ProcessSpeakersEmailRequestJobTest.php tests/ProcessSubmittersEmailRequestJobTest.php tests/SpeakerRepositoryTest.php tests/SubmitterRepositoryTest.php tests/SpeakerServiceOriginalFilterTest.php tests/SubmitterServiceOriginalFilterTest.php" }
- { name: "SpeakerSubmitterPublishedFilter", filter: "tests/ProcessSpeakersEmailRequestJobTest.php tests/ProcessSubmittersEmailRequestJobTest.php tests/SpeakerRepositoryTest.php tests/SubmitterRepositoryTest.php tests/SpeakerServiceOriginalFilterTest.php tests/SubmitterServiceOriginalFilterTest.php tests/ActivitiesCountFilterMappingsTest.php" }
- { name: "Repositories", filter: "tests/Repositories/" }
- { name: "Services", filter: "tests/Unit/Services/" }
- { name: "Integration", filter: "tests/Integration/" }
Expand Down
90 changes: 90 additions & 0 deletions app/Http/Utils/Filters/SQL/SQLRawFilterMapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php namespace App\Http\Utils\Filters\SQL;
/*
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use utils\Filter;
use utils\FilterElement;
use utils\FilterMapping;

/**
* Class SQLRawFilterMapping
*
* Raw SQL counterpart of DoctrineFilterMapping: takes a condition carrying the
* :operator and :value placeholders and renders it for Filter::toRawSQL, binding
* each value as a named parameter instead of interpolating it.
*
* @package App\Http\Utils\Filters\SQL
*/
class SQLRawFilterMapping extends FilterMapping
{
/**
* @param string $condition
*/
public function __construct(string $condition)
{
parent::__construct('', $condition);
}

/**
* @param FilterElement $filter
* @param array $bindings bindings already collected by the caller
* @return string
*/
public function toRawSQL(FilterElement $filter, array $bindings = []): string
{
$this->bindings = [];
$param_idx = count($bindings) + 1;

$value = $filter->getValue();
$operator = $filter->getOperator();

if (!is_array($value)) {
return $this->renderCondition(
$value,
is_array($operator) ? $operator[0] : $operator,
$param_idx
);
}

$conditions = [];
foreach ($value as $idx => $v) {
$conditions[] = $this->renderCondition(
$v,
is_array($operator) ? $operator[$idx] : $operator,
$param_idx++
);
}

$same_field_op = $filter->getSameFieldOp() ?? Filter::MainOperatorOr;

return '( ' . implode(sprintf(' %s ', $same_field_op), $conditions) . ' )';
}

/**
* @param mixed $value
* @param string $operator
* @param int $param_idx
* @return string
*/
private function renderCondition($value, string $operator, int $param_idx): string
{
$param = sprintf(Filter::ParamPrefix, $param_idx);
$this->bindings[$param] = $value;

return str_replace(
[Filter::OperatorPlaceholder, Filter::ValuePlaceholder],
[$operator, ':' . $param],
$this->where
);
}
}
72 changes: 72 additions & 0 deletions app/Http/Utils/Filters/SQL/SQLSwitchFilterMapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php namespace App\Http\Utils\Filters\SQL;
/*
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use utils\FilterElement;
use utils\FilterMapping;

/**
* Class SQLSwitchFilterMapping
*
* Raw SQL counterpart of DoctrineSwitchFilterMapping: picks the condition by the
* filter value, OR-ing the conditions of every value the element carries. The
* conditions are literals, so nothing gets bound.
*
* @package App\Http\Utils\Filters\SQL
*/
class SQLSwitchFilterMapping extends FilterMapping
{
/**
* Condition for a value that must not restrict the result set. Spelled out rather
* than left absent so that a multi-value element such as `==true||false` still
* evaluates to true, the way the Doctrine switch mapping does.
*/
const NoRestriction = '1 = 1';

/**
* @var array value => SQL condition
*/
private $case_statements;

/**
* @param array $case_statements
*/
public function __construct(array $case_statements = [])
{
parent::__construct('', '');
$this->case_statements = $case_statements;
}

/**
* @param FilterElement $filter
* @param array $bindings
* @return string
*/
public function toRawSQL(FilterElement $filter, array $bindings = []): string
{
$this->bindings = [];

$value = $filter->getValue();
if (!is_array($value)) $value = [$value];

$conditions = [];
foreach ($value as $v) {
if (!isset($this->case_statements[$v])) continue;
$conditions[] = '( ' . $this->case_statements[$v] . ' )';
}

if (empty($conditions)) return '';

return implode(' OR ', $conditions);
}
}
12 changes: 10 additions & 2 deletions app/Repositories/Summit/DoctrineMemberRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use App\Http\Utils\Filters\DoctrineInFilterMapping;
use App\Http\Utils\Filters\DoctrineNotInFilterMapping;
use App\Repositories\Summit\Traits\ActivitiesCountFilterMappingsTrait;
use App\Http\Utils\Filters\SQL\SQLInFilterMapping;
use App\Http\Utils\Filters\SQL\SQLNotInFilterMapping;
use App\libs\Utils\PunnyCodeHelper;
Expand Down Expand Up @@ -43,6 +44,8 @@ final class DoctrineMemberRepository
extends SilverStripeDoctrineRepository
implements IMemberRepository
{
use ActivitiesCountFilterMappingsTrait;

/**
* @return string
*/
Expand Down Expand Up @@ -773,15 +776,20 @@ public function getUniqueActivitiesCountBySummit(Summit $summit, Filter $filter
} while (count($chunk) === $chunkSize);

// Phase 2: count distinct presentations whose creator is in the matched set.
// The presentation-level filters of the request scope phase 2 too: we count
// only the presentations that both belong to a matched submitter and satisfy
// the filter, so that "N Submitters | M Activities" describes one same set.
[$extra_filters, $bindings] = $this->buildActivitiesCountFilter($filter, $summit->getId());

$sql = <<<SQL
SELECT COUNT(DISTINCT E.ID)
FROM SummitEvent E
INNER JOIN Presentation P ON P.ID = E.ID
INNER JOIN `__tmp_mbr_ids` T ON T.id = E.CreatedByID
WHERE E.SummitID = ?
WHERE E.SummitID = :summit_id{$extra_filters}
SQL;

return (int) $conn->fetchOne($sql, [$summit->getId()]);
return (int) $conn->fetchOne($sql, $bindings);
} finally {
$conn->executeStatement('DROP TEMPORARY TABLE IF EXISTS `__tmp_mbr_ids`');
}
Expand Down
17 changes: 13 additions & 4 deletions app/Repositories/Summit/DoctrineSpeakerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use App\Http\Utils\Filters\DoctrineInFilterMapping;
use App\Http\Utils\Filters\DoctrineNotInFilterMapping;
use App\Repositories\Summit\Traits\ActivitiesCountFilterMappingsTrait;
use App\libs\Utils\PunnyCodeHelper;
use App\Repositories\SilverStripeDoctrineRepository;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
Expand Down Expand Up @@ -41,6 +42,8 @@ final class DoctrineSpeakerRepository
extends SilverStripeDoctrineRepository
implements ISpeakerRepository
{
use ActivitiesCountFilterMappingsTrait;

/**
* @return array
*/
Expand Down Expand Up @@ -862,14 +865,20 @@ public function getUniqueActivitiesCountBySummit(Summit $summit, Filter $filter
);
$conn->executeStatement('TRUNCATE TABLE `__tmp_pres_ids`');

// The presentation-level filters of the request scope phase 2 too: we count
// only the presentations that both belong to a matched speaker and satisfy
// the filter, so that "N Speakers | M Activities" describes one same set.
[$extra_filters, $bindings] = $this->buildActivitiesCountFilter($filter, $summit->getId());

$conn->executeStatement(
'INSERT IGNORE INTO `__tmp_pres_ids` (id)
SELECT DISTINCT E.ID
FROM SummitEvent E
INNER JOIN Presentation P ON P.ID = E.ID
INNER JOIN Presentation_Speakers PS ON PS.PresentationID = E.ID
INNER JOIN `__tmp_spk_ids` T ON T.id = PS.PresentationSpeakerID
WHERE E.SummitID = ?',
[$summit->getId()]
WHERE E.SummitID = :summit_id' . $extra_filters,
$bindings
);

$conn->executeStatement(
Expand All @@ -878,8 +887,8 @@ public function getUniqueActivitiesCountBySummit(Summit $summit, Filter $filter
FROM SummitEvent E
INNER JOIN Presentation P ON P.ID = E.ID
INNER JOIN `__tmp_spk_ids` T ON T.id = P.ModeratorID
WHERE E.SummitID = ?',
[$summit->getId()]
WHERE E.SummitID = :summit_id' . $extra_filters,
$bindings
);

return (int) $conn->fetchOne('SELECT COUNT(*) FROM `__tmp_pres_ids`');
Expand Down
Loading
Loading