mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
PHRAS-3277
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Model\Repositories;
|
||||
|
||||
use Alchemy\Phrasea\Cache\Exception;
|
||||
use Alchemy\Phrasea\Model\Entities\ValidationParticipant;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
@@ -27,6 +28,7 @@ class ValidationParticipantRepository extends EntityRepository
|
||||
* @param $today DateTime fake "today" to allow to get past/future events
|
||||
* (used by SendValidationRemindersCommand.php to debug with --dry)
|
||||
* @return ValidationParticipant[]
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function findNotConfirmedAndNotRemindedParticipantsByTimeLeftPercent($timeLeftPercent, DateTime $today=null)
|
||||
{
|
||||
@@ -34,6 +36,8 @@ class ValidationParticipantRepository extends EntityRepository
|
||||
$rsm->addRootEntityFromClassMetadata('Alchemy\Phrasea\Model\Entities\ValidationParticipant', 'p');
|
||||
$selectClause = $rsm->generateSelectClause();
|
||||
|
||||
switch($this->_em->getConnection()->getDriver()->getName()) {
|
||||
case 'pdo_mysql':
|
||||
$sql = '
|
||||
SELECT ' . $selectClause . '
|
||||
FROM ValidationParticipants p
|
||||
@@ -45,6 +49,25 @@ class ValidationParticipantRepository extends EntityRepository
|
||||
AND DATE_SUB(s.expires, INTERVAL FLOOR((TO_SECONDS(s.expires) - TO_SECONDS(s.created)) * :percent) SECOND) <= '. ($today===null ? 'CURRENT_TIMESTAMP()' : ':today')
|
||||
;
|
||||
|
||||
break;
|
||||
case 'pdo_sqlite':
|
||||
$sql = '
|
||||
SELECT ' . $selectClause . '
|
||||
FROM ValidationParticipants p
|
||||
INNER JOIN ValidationSessions s on p.validation_session_id = s.id
|
||||
INNER JOIN Baskets b on b.id = s.basket_id
|
||||
WHERE p.is_confirmed = 0
|
||||
AND p.reminded IS NULL
|
||||
AND s.expires > '. ($today===null ? 'strftime("%s","now")' : 'strftime("%s", :today)') . '
|
||||
AND (strftime("%s", s.expires) - ((strftime("%s", s.expires) - strftime("%s", s.created)) * :percent) )<= '. ($today===null ? 'strftime("%s","now")' : 'strftime("%s", :today)')
|
||||
;
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Unused PDO!, if necessary define the query for this PDO');
|
||||
|
||||
}
|
||||
|
||||
$q = $this->_em->createNativeQuery($sql, $rsm);
|
||||
$q->setParameter('percent', (float)($timeLeftPercent/100));
|
||||
|
||||
|
@@ -12,7 +12,7 @@ class ValidationParticipantRepositoryTest extends \PhraseanetTestCase
|
||||
$em = self::$DI['app']['orm.em'];
|
||||
$repo = $em->getRepository('Phraseanet:ValidationParticipant');
|
||||
/* @var $repo Alchemy\Phrasea\Model\Repositories\ValidationParticipantRepository */
|
||||
$participants = $repo->findNotConfirmedAndNotRemindedParticipantsByTimeLeftPercent(20, new \DateTime('+7 days'));
|
||||
$participants = $repo->findNotConfirmedAndNotRemindedParticipantsByTimeLeftPercent(20, new \DateTime());
|
||||
$this->assertEquals(3, count($participants));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user