Merge pull request #160 from nlegoff/bugs

Bugs
This commit is contained in:
Romain Neutron
2012-07-17 06:21:35 -07:00
13 changed files with 132 additions and 49 deletions

View File

@@ -57,7 +57,7 @@ return call_user_func(
} }
$response = \set_export::stream_file($pathOut, $file->get_file(), $file->get_mime(), 'attachment'); $response = \set_export::stream_file($pathOut, $file->get_file(), $file->get_mime(), 'inline');
$response->setPrivate(); $response->setPrivate();
/* @var $response \Symfony\Component\HttpFoundation\Response */ /* @var $response \Symfony\Component\HttpFoundation\Response */

View File

@@ -180,8 +180,6 @@ class Installer implements ControllerProviderInterface
\setup::rollback($conn, $connbas); \setup::rollback($conn, $connbas);
try { try {
$setupRegistry = new \Setup_Registry();
$setupRegistry->set('GV_ServerName', $servername, \registry::TYPE_STRING);
$appbox = \appbox::create($app['Core'], $setupRegistry, $conn, $appbox_name, true); $appbox = \appbox::create($app['Core'], $setupRegistry, $conn, $appbox_name, true);

View File

@@ -12,6 +12,7 @@
namespace Repositories; namespace Repositories;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\DBAL\Types\Type;
/** /**
* *
@@ -21,5 +22,26 @@ use Doctrine\ORM\EntityRepository;
class ValidationParticipantRepository extends 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();
}
} }

View File

@@ -367,16 +367,13 @@ class Session_Handler
throw new Exception_ServiceUnavailable(); throw new Exception_ServiceUnavailable();
} }
$registry = $this->appbox->get_registry();
$conn = $this->appbox->get_connection(); $conn = $this->appbox->get_connection();
$browser = Browser::getInstance(); $browser = Browser::getInstance();
$sbases = array();
$this->send_reminders(); $this->send_reminders();
$auth->prelog(); $auth->prelog();
if ($this->is_authenticated() && $this->get_usr_id() == $auth->get_user()->get_id()) { if ($this->is_authenticated() && $this->get_usr_id() == $auth->get_user()->get_id()) {
return $this; return $this;
} }
@@ -533,38 +530,39 @@ class Session_Handler
return $this; return $this;
} }
$Core = bootstrap::getCore(); $core = bootstrap::getCore();
$registry = $Core->getRegistry(); $registry = $core->getRegistry();
$date_two_day = new DateTime('+' . (int) $registry->get('GV_validation_reminder') . ' days');
$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 $eventsMngr = eventsmanager_broker::getInstance($this->appbox, $core);
, 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 ';
$stmt = $this->appbox->get_connection()->prepare($sql); $em = $core->getEntityManager();
$stmt->execute(array(':expires_on' => phraseadate::format_mysql($date_two_day))); /* @var $em \Doctrine\ORM\EntityManager */
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $participantRepo = $em->getRepository('\Entities\ValidationParticipant');
$stmt->closeCursor(); /* @var $participantRepo \Repositories\ValidationParticipantRepository */
$participants = $participantRepo->findNotConfirmedAndNotRemindedParticipantsByExpireDate($date);
foreach ($rs as $row) { foreach ($participants as $participant) {
$params = array( /* @var $participant \Entities\ValidationParticipant */
'to' => $row['usr_id'], $validationSession = $participant->getSession();
'ssel_id' => $row['ssel_id'], $participantId = $participant->getUsrId();
'from' => $row['owner'], $basketId = $validationSession->getBasket()->getId();
'validate_id' => $row['validate_id'],
'url' => $registry->get('GV_ServerName')
. 'lightbox/validate/' . $row['ssel_id'] . '/?LOG=' . $row['value']
);
$events_mngr->trigger('__VALIDATION_REMINDER__', $params); try {
$token = \random::getValidationToken($participantId, $basketId);
} catch (\Exception_NotFound $e) {
continue;
}
$eventsMngr->trigger('__VALIDATION_REMINDER__', array(
'to' => $participantId,
'ssel_id' => $basketId,
'from' => $validationSession->getInitiatorId(),
'validate_id' => $validationSession->getId(),
'url' => $registry->get('GV_ServerName') . 'lightbox/validate/' . $basketId . '/?LOG=' . $token
));
} }
return $this; return $this;

View File

@@ -110,13 +110,19 @@ class eventsmanager_notify_validationreminder extends eventsmanager_notifyAbstra
$mailed = true; $mailed = true;
} }
try { $core = \bootstrap::getCore();
$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) {
$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); return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);

View File

@@ -221,4 +221,38 @@ class random
return $row; 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'];
}
} }

View File

@@ -770,13 +770,13 @@ class set_export extends set_abstract
* @return \Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\Response
*/ */
public static function stream_file( public static function stream_file(
$file, $exportname, $mime, $disposition = 'attachment') $file, $exportname, $mime, $disposition = 'inline')
{ {
$registry = registry::get_instance(); $registry = registry::get_instance();
$response = new Symfony\Component\HttpFoundation\Response(); $response = new Symfony\Component\HttpFoundation\Response();
$disposition = $disposition != 'attachment' ? ResponseHeaderBag::DISPOSITION_INLINE : ResponseHeaderBag::DISPOSITION_ATTACHMENT; $disposition = $disposition === 'attachment' ? ResponseHeaderBag::DISPOSITION_ATTACHMENT : ResponseHeaderBag::DISPOSITION_INLINE;
$headerDisposition = $response->headers->makeDisposition($disposition, $exportname); $headerDisposition = $response->headers->makeDisposition($disposition, $exportname);
if (is_file($file)) { if (is_file($file)) {

View File

@@ -124,6 +124,7 @@
{% for subdef in previewHtml5 %} {% for subdef in previewHtml5 %}
<source type="{{ subdef.get_mime() }}" src="{{ subdef.get_url() }}" /> <source type="{{ subdef.get_mime() }}" src="{{ subdef.get_url() }}" />
{% endfor %} {% endfor %}
{% trans 'No preview available' %}
</video> </video>
</div> </div>
@@ -374,7 +375,7 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
var scope = $("#prod-tool-box"); var scope = $("#prod-tool-box");
var width = 0; var width = 0;

View File

@@ -18,10 +18,10 @@ class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
public function createApplication() public function createApplication()
{ {
$app = require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Overview.php'; $app = require __DIR__ . '/../../../../lib/Alchemy/Phrasea/Application/Overview.php';
$app['debug'] = true; $app['debug'] = true;
unset($app['exception_handler']); unset($app['exception_handler']);
return $app; return $app;
} }
@@ -33,7 +33,7 @@ class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$content_disposition = explode(';', $response->headers->get('content-disposition')); $content_disposition = explode(';', $response->headers->get('content-disposition'));
$this->assertEquals('attachment', $content_disposition[0]); $this->assertEquals('inline', $content_disposition[0]);
$this->assertEquals(static::$records['record_1']->get_preview()->get_mime(), $response->headers->get('content-type')); $this->assertEquals(static::$records['record_1']->get_preview()->get_mime(), $response->headers->get('content-type'));
$this->assertEquals(static::$records['record_1']->get_preview()->get_size(), $response->headers->get('content-length')); $this->assertEquals(static::$records['record_1']->get_preview()->get_size(), $response->headers->get('content-length'));

View File

@@ -0,0 +1,21 @@
<?php
require_once __DIR__ . '/../../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class ValidationParticipantRepositoryTest extends PhraseanetPHPUnitAuthenticatedAbstract
{
public function testFindNotConfirmedAndNotRemindedParticipants()
{
$this->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));
}
}

View File

@@ -373,7 +373,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
* *
* @return \Entities\Basket * @return \Entities\Basket
*/ */
protected function insertOneValidationBasket() protected function insertOneValidationBasket(array $parameters = array())
{ {
$em = self::$core->getEntityManager(); $em = self::$core->getEntityManager();
@@ -384,8 +384,11 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
$Validation->setBasket($basket); $Validation->setBasket($basket);
$Validation->setInitiator(self::$user); $Validation->setInitiator(self::$user);
if (isset($parameters['expires']) && $parameters['expires'] instanceof \DateTime) {
$Validation->setExpires($parameters['expires']);
}
$basket->setValidation($Validation); $basket->setValidation($Validation);
$em->persist($Validation); $em->persist($Validation);
$em->merge($basket); $em->merge($basket);

View File

@@ -71,7 +71,7 @@ if ($n_files == 1) {
$files = $list['files']; $files = $list['files'];
if (isset($parm['get']) && $parm['get'] == '1') { if (isset($parm['get']) && $parm['get'] == '1') {
$response = set_export::stream_file($zipFile, $export_name, $mime); $response = set_export::stream_file($zipFile, $export_name, $mime, 'attachment');
$response->send(); $response->send();
set_export::log_download($list, $parm['type']); set_export::log_download($list, $parm['type']);

View File

@@ -198,7 +198,7 @@ User_Adapter::updateClientInfos(5);
</head> </head>
<body id="desktop" style="background-color:#808080; overflow:hidden" onload="loaded();" onmousewheel="return(false);" onscroll="evtScrollBody();" > <body id="desktop" style="background-color:#808080; overflow:hidden" onload="loaded();" onscroll="evtScrollBody();" >
<div class="menu" id="flagsMenu" style="z-index:50"> <div class="menu" id="flagsMenu" style="z-index:50">
<?php <?php