From 66e84bcbfbd8d333d282ae5ec3418cb33a582700 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 11 Jul 2012 16:54:09 +0200 Subject: [PATCH 1/6] refactor send_reminded function --- .../Phrasea/Controller/Setup/Installer.php | 2 - .../ValidationParticipantRepository.php | 22 ++++++++ lib/classes/Session/Handler.class.php | 52 ++++++++----------- .../notify/validationreminder.class.php | 18 ++++--- .../ValidationParticipantRepositoryTest.php | 21 ++++++++ tests/PhraseanetPHPUnitAbstract.class.inc | 7 ++- 6 files changed, 81 insertions(+), 41 deletions(-) create mode 100644 tests/Doctrine/Repositories/ValidationParticipantRepositoryTest.php diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index d8eea5740a..a2b5fcec64 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -180,8 +180,6 @@ class Installer implements ControllerProviderInterface \setup::rollback($conn, $connbas); try { - $setupRegistry = new \Setup_Registry(); - $setupRegistry->set('GV_ServerName', $servername, \registry::TYPE_STRING); $appbox = \appbox::create($app['Core'], $setupRegistry, $conn, $appbox_name, true); diff --git a/lib/Doctrine/Repositories/ValidationParticipantRepository.php b/lib/Doctrine/Repositories/ValidationParticipantRepository.php index 53a222762a..1f210d5b23 100644 --- a/lib/Doctrine/Repositories/ValidationParticipantRepository.php +++ b/lib/Doctrine/Repositories/ValidationParticipantRepository.php @@ -12,6 +12,7 @@ namespace Repositories; use Doctrine\ORM\EntityRepository; +use Doctrine\DBAL\Types\Type; /** * @@ -21,5 +22,26 @@ use Doctrine\ORM\EntityRepository; class ValidationParticipantRepository extends EntityRepository { + /** + * Retrieve all not reminded participants where the validation has not expired + * + * @param $expireDate The expiration Date + * @return array + */ + public function findNotConfirmedAndNotRemindedParticipantsByExpireDate(\DateTime $expireDate) + { + $dql = ' + SELECT p, s + FROM Entities\ValidationParticipant p + JOIN p.session s + JOIN s.basket b + WHERE p.is_confirmed = 0 + AND p.reminded IS NULL + AND s.expires < :date'; + + return $this->_em->createQuery($dql) + ->setParameter('date', $expireDate, Type::DATETIME) + ->getResult(); + } } diff --git a/lib/classes/Session/Handler.class.php b/lib/classes/Session/Handler.class.php index 2b5d7680fb..5381eb76bc 100644 --- a/lib/classes/Session/Handler.class.php +++ b/lib/classes/Session/Handler.class.php @@ -367,16 +367,13 @@ class Session_Handler throw new Exception_ServiceUnavailable(); } - $registry = $this->appbox->get_registry(); - $conn = $this->appbox->get_connection(); $browser = Browser::getInstance(); - $sbases = array(); - $this->send_reminders(); $auth->prelog(); + if ($this->is_authenticated() && $this->get_usr_id() == $auth->get_user()->get_id()) { return $this; } @@ -533,38 +530,31 @@ class Session_Handler return $this; } - $Core = bootstrap::getCore(); + $core = bootstrap::getCore(); - $registry = $Core->getRegistry(); - $date_two_day = new DateTime('+' . (int) $registry->get('GV_validation_reminder') . ' days'); + $registry = $core->getRegistry(); - $events_mngr = eventsmanager_broker::getInstance($this->appbox, $Core); + $date = new DateTime('+' . (int) $registry->get('GV_validation_reminder') . ' days'); - $sql = 'SELECT v.id as validate_id, v.usr_id, v.ssel_id - , s.usr_id as owner, t.value - FROM (validate v, ssel s) - INNER JOIN tokens t - ON (t.datas = s.ssel_id - AND v.usr_id=t.usr_id AND t.type="validate") - WHERE expires_on < :expires_on - AND ISNULL(last_reminder) AND confirmed="0" AND s.ssel_id = v.ssel_id '; + $eventsMngr = eventsmanager_broker::getInstance($this->appbox, $core); - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':expires_on' => phraseadate::format_mysql($date_two_day))); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); + $em = $core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $participantRepo = $em->getRepository('\Entities\ValidationParticipant'); + /* @var $participantRepo \Repositories\ValidationParticipantRepository */ + $participants = $participantRepo->findNotConfirmedAndNotRemindedParticipantsByExpireDate($date); - foreach ($rs as $row) { - $params = array( - 'to' => $row['usr_id'], - 'ssel_id' => $row['ssel_id'], - 'from' => $row['owner'], - 'validate_id' => $row['validate_id'], - 'url' => $registry->get('GV_ServerName') - . 'lightbox/validate/' . $row['ssel_id'] . '/?LOG=' . $row['value'] - ); - - $events_mngr->trigger('__VALIDATION_REMINDER__', $params); + foreach ($participants as $participant) { + /* @var $participant \Entities\ValidationParticipant */ + $validationSession = $participant->getSession(); + $basketId = $validationSession->getBasket()->getId(); + $eventsMngr->trigger('__VALIDATION_REMINDER__', array( + 'to' => $participant->getUsrId(), + 'ssel_id' => $basketId, + 'from' => $validationSession->getInitiatorId(), + 'validate_id' => $validationSession->getId(), + 'url' => $registry->get('GV_ServerName') . 'lightbox/validate/' . $basketId . '/'//?LOG=' . $row['value'] + )); } return $this; diff --git a/lib/classes/eventsmanager/notify/validationreminder.class.php b/lib/classes/eventsmanager/notify/validationreminder.class.php index 58732e80fc..0bb44ab774 100644 --- a/lib/classes/eventsmanager/notify/validationreminder.class.php +++ b/lib/classes/eventsmanager/notify/validationreminder.class.php @@ -110,13 +110,19 @@ class eventsmanager_notify_validationreminder extends eventsmanager_notifyAbstra $mailed = true; } - try { - $sql = 'UPDATE validate SET last_reminder=NOW() WHERE id = :validate_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':validate_id' => $params['validate_id'])); - $stmt->closeCursor(); - } catch (Exception $e) { + $core = \bootstrap::getCore(); + $em = $core->getEntityManager(); + + $validationParticipant = $em->getRepository('\Entities\ValidationParticipant')->find($params['to']); + /* @var $validationParticipant \Entities\ValidationParticipant */ + + if (null !== $validationParticipant) { + $validationParticipant->setReminded(new \DateTime('now')); + + $em->persist($validationParticipant); + + $em->flush(); } return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed); diff --git a/tests/Doctrine/Repositories/ValidationParticipantRepositoryTest.php b/tests/Doctrine/Repositories/ValidationParticipantRepositoryTest.php new file mode 100644 index 0000000000..77bfe9b5f7 --- /dev/null +++ b/tests/Doctrine/Repositories/ValidationParticipantRepositoryTest.php @@ -0,0 +1,21 @@ +insertOneValidationBasket(array( + 'expires' => new \DateTime('+1 days') + )); + + $em = self::$core->getEntityManager(); + $repo = $em->getRepository('\Entities\ValidationParticipant'); + /* @var $repo \Repositories\ValidationParticipantRepository */ + $expireDate = new \DateTime('+2 days'); + $participants = $repo->findNotConfirmedAndNotRemindedParticipantsByExpireDate($expireDate); + $this->assertEquals(1, count($participants)); + } +} diff --git a/tests/PhraseanetPHPUnitAbstract.class.inc b/tests/PhraseanetPHPUnitAbstract.class.inc index bae585c3d4..704d22365f 100644 --- a/tests/PhraseanetPHPUnitAbstract.class.inc +++ b/tests/PhraseanetPHPUnitAbstract.class.inc @@ -373,7 +373,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase * * @return \Entities\Basket */ - protected function insertOneValidationBasket() + protected function insertOneValidationBasket(array $parameters = array()) { $em = self::$core->getEntityManager(); @@ -384,8 +384,11 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $Validation->setBasket($basket); $Validation->setInitiator(self::$user); + if (isset($parameters['expires']) && $parameters['expires'] instanceof \DateTime) { + $Validation->setExpires($parameters['expires']); + } + $basket->setValidation($Validation); - $em->persist($Validation); $em->merge($basket); From 6159ba2d006f406ec25186d717cc77a1b8a6a15b Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 11 Jul 2012 17:22:43 +0200 Subject: [PATCH 2/6] add getValidationToken method --- lib/classes/Session/Handler.class.php | 12 ++++++++-- lib/classes/random.class.php | 34 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/classes/Session/Handler.class.php b/lib/classes/Session/Handler.class.php index 5381eb76bc..6eebf2480d 100644 --- a/lib/classes/Session/Handler.class.php +++ b/lib/classes/Session/Handler.class.php @@ -547,13 +547,21 @@ class Session_Handler foreach ($participants as $participant) { /* @var $participant \Entities\ValidationParticipant */ $validationSession = $participant->getSession(); + $participantId = $participant->getUsrId(); $basketId = $validationSession->getBasket()->getId(); + + try { + $token = \random::getValidationToken($participantId, $basketId); + } catch (\Exception_NotFound $e) { + continue; + } + $eventsMngr->trigger('__VALIDATION_REMINDER__', array( - 'to' => $participant->getUsrId(), + 'to' => $participantId, 'ssel_id' => $basketId, 'from' => $validationSession->getInitiatorId(), 'validate_id' => $validationSession->getId(), - 'url' => $registry->get('GV_ServerName') . 'lightbox/validate/' . $basketId . '/'//?LOG=' . $row['value'] + 'url' => $registry->get('GV_ServerName') . 'lightbox/validate/' . $basketId . '/?LOG=' . $token )); } diff --git a/lib/classes/random.class.php b/lib/classes/random.class.php index 6dcd58a5c6..d117c0e411 100644 --- a/lib/classes/random.class.php +++ b/lib/classes/random.class.php @@ -221,4 +221,38 @@ class random return $row; } + + /** + * Get the validation token for one user and one validation basket + * + * @param integer $userId + * @param integer $basketId + * @return string The desired token + * @throws \Exception_NotFound + */ + public static function getValidationToken($userId, $basketId) + { + $conn = \connection::getPDOConnection(); + $sql = ' + SELECT value FROM tokens + WHERE type = :type + AND usr_id = :usr_id + AND datas = :basket_id + AND (expire_on > NOW() OR expire_on IS NULL)'; + + $stmt = $conn->prepare($sql); + $stmt->execute(array( + ':type' => self::TYPE_VALIDATE, + ':usr_id' => (int) $userId, + ':basket_id' => (int) $basketId, + )); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + if ( ! $row) { + throw new \Exception_NotFound('Token not found'); + } + + return $row['value']; + } } From 9e7975f91e214a2c6d05a4d627bd8102048d665c Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Thu, 12 Jul 2012 12:24:31 +0200 Subject: [PATCH 3/6] Fix #799 Thesaurus scrollbar issue on webkit browser --- www/thesaurus2/thesaurus.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/www/thesaurus2/thesaurus.php b/www/thesaurus2/thesaurus.php index ae88887eae..678a5f98b4 100644 --- a/www/thesaurus2/thesaurus.php +++ b/www/thesaurus2/thesaurus.php @@ -198,7 +198,7 @@ User_Adapter::updateClientInfos(5); - + -
+
+
From 315c630764b4f64a1fe9d852f6b3ed9c3d0012ef Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Thu, 12 Jul 2012 12:25:53 +0200 Subject: [PATCH 4/6] Display fallback message when no preview available for HTML5 player --- templates/web/prod/actions/Tools/index.html.twig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/web/prod/actions/Tools/index.html.twig b/templates/web/prod/actions/Tools/index.html.twig index eb880e9b7d..3079f3aab8 100644 --- a/templates/web/prod/actions/Tools/index.html.twig +++ b/templates/web/prod/actions/Tools/index.html.twig @@ -124,6 +124,7 @@ {% for subdef in previewHtml5 %} {% endfor %} + {% trans 'No preview available' %} @@ -374,7 +375,7 @@