Bug #7964

OAI date range query's method will overwrite first date range value with second

Added by Dan Gillean over 7 years ago. Updated about 7 years ago.

Status:VerifiedStart date:02/11/2015
Priority:MediumDue date:
Assignee:Dan Gillean% Done:

0%

Category:OAI-PMH
Target version:Release 2.2.0
Google Code Legacy ID: Tested version:2.1, 2.1.1, 2.2
Sponsored:No Requires documentation:

Description

Reported by Edgar Rodríguez Silva in the User forum: https://groups.google.com/d/msg/ica-atom-users/hJQF2Ldjkgc/Zs_VUSUMdPkJ

The problem is in the method QubitInformationObject::getUpdatedRecords($from, $until, $offset, $limit, $set) in lines 397-405:

This method uses $criteria->add to add both the $from and the $until values. However, the ->add method used will not accept multiple values - so the second value ($until) overwrites the first. Or, as Edgar more eloquently puts it, "If a criterion for one requested column already exists, criteria->add replaces it."

Edgar's suggested solution is to use $criteria->addAnd for the second value:

 if ($from != '')
    {
      $criteria->add(QubitObject::UPDATED_AT, $from, Criteria::GREATER_EQUAL);
    }

    if ($until != '')
    {
      $criteria->addAnd(QubitObject::UPDATED_AT, $until, Criteria::LESS_EQUAL);
    }

One question remains: will this method succeed if a $from criteria is NOT included by the user in the query? If this won't cause catatrophic failure (e.g. if an addAnd without a preceding add wouldn't break the query), then we should implement this 1-line fix for 2.2.

History

#1 Updated by Edgar Rodríguez Silva over 7 years ago

In propel API documentation (version 1.6) about says:

If a criterion for the requested column already exists, the condition is "AND"ed to the existing criterion (necessary for Propel 1.4 compatibility).
If no criterion for the requested column already exists, the condition is "AND"ed to the latest criterion.
If no criterion exist, the condition is added a new criterion

Considering that AtoM works with Propel 1.4.2, I have made some tests. These are the results:

FROM present
UNTIL present
CRITERIA output with toString() method:
SQL (may not be complete): SELECT FROM `status`, `object`, `information_object` WHERE status.STATUS_ID=:p1 AND (object.UPDATED_AT>=:p2 AND object.UPDATED_AT<=:p3) AND information_object.PARENT_ID IS NOT NULL AND information_object.ID=status.OBJECT_ID AND information_object.ID=object.ID ORDER BY object.UPDATED_AT ASC LIMIT 100
Params: status.STATUS_ID => 160, object.UPDATED_AT => '2015-02-05T11:49:32Z', object.UPDATED_AT => '2015-02-06T10:49:32Z'

FROM not present
UNTIL present
CRITERIA output with toString() method:
SQL (may not be complete): SELECT FROM `status`, `object`, `information_object` WHERE status.STATUS_ID=:p1 AND object.UPDATED_AT<=:p2 AND information_object.PARENT_ID IS NOT NULL AND information_object.ID=status.OBJECT_ID AND information_object.ID=object.ID ORDER BY object.UPDATED_AT ASC LIMIT 100
Params: status.STATUS_ID => 160, object.UPDATED_AT => '2015-02-06T10:49:32Z'

FROM present
UNTIL not present
CRITERIA output with toString() method:
SQL (may not be complete): SELECT FROM `status`, `object`, `information_object` WHERE status.STATUS_ID=:p1 AND object.UPDATED_AT>=:p2 AND information_object.PARENT_ID IS NOT NULL AND information_object.ID=status.OBJECT_ID AND information_object.ID=object.ID ORDER BY object.UPDATED_AT ASC LIMIT 100
Params: status.STATUS_ID => 160, object.UPDATED_AT => '2015-02-05T11:49:32Z'

#2 Updated by José Raddaoui Marín about 7 years ago

  • Status changed from New to QA/Review
  • Assignee changed from Mike Cantelon to Dan Gillean

Thanks Edgar! I've added your fix to qa/2.2.x.

#3 Updated by Dan Gillean about 7 years ago

  • Status changed from QA/Review to Verified
  • Tested version 2.2 added

Works great! Tested some queries with both from and until parameters, as well as just from, and just until, including the use of the resumption token (but manually URL encoded, which is a separate issue).

Thanks again, Edgar and Radda!

Also available in: Atom PDF