Skip to content

Commit

Permalink
Restrict added and modified separately.
Browse files Browse the repository at this point in the history
The previous implementation could return results as long as the added
and modified dates just "straddled" the from and until params.

Ref #8.
  • Loading branch information
zerocrates committed Oct 14, 2014
1 parent b1a0a62 commit 2e51659
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions libraries/OaiPmhRepository/ResponseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,33 @@ private function resumeListResponse($token)
private function listResponse($verb, $metadataPrefix, $cursor, $set, $from, $until) {
$listLimit = $this->_listLimit;

$itemTable = get_db()->getTable('Item');
$db = get_db();
$itemTable = $db->getTable('Item');
$select = $itemTable->getSelect();
$alias = $itemTable->getTableAlias();
$itemTable->filterByPublic($select, true);
if($set)
$itemTable->filterByCollection($select, $set);

$modifiedClause = $addedClause = '';
if($from) {
$select->where("$alias.modified >= ? OR $alias.added >= ?", $from);
$select->group("$alias.id");
$quotedFromDate = $db->quote($from);
$modifiedClause = "$alias.modified >= $quotedFromDate";
$addedClause = "$alias.added >= $quotedFromDate";
}
if($until) {
$select->where("$alias.modified < ? OR $alias.added < ?", $until);
$select->group("$alias.id");
if ($from) {
$modifiedClause .= ' AND ';
$addedClause .= ' AND ';
}
$quotedUntilDate = $db->quote($until);
$modifiedClause .= "$alias.modified < $quotedUntilDate";
$addedClause .= "$alias.added < $quotedUntilDate";
}


if ($from || $until) {
$select->where("($modifiedClause) OR ($addedClause)");
}

// Total number of rows that would be returned
Expand Down

0 comments on commit 2e51659

Please sign in to comment.