Skip to content

Commit

Permalink
Notifications : support du changement d'utilisateur
Browse files Browse the repository at this point in the history
Dans le cas où un autre utilisateur se connecte à une appli qui a déjà un token
  • Loading branch information
Florent Thévenet committed Jun 7, 2014
1 parent cdf7381 commit be21c22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
33 changes: 24 additions & 9 deletions src/Payutc/Bom/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,35 @@ public static function addDevice($type, $token, $user) {
throw new NotificationInvalidDeviceType("Choose between 'iOS' or 'Android'.");
}

try {
Dbal::conn()->insert('t_notification_not',
array('not_user' => 1,
$conn = Dbal::conn();
$conn->beginTransaction();
$qb = $conn->createQueryBuilder()
->select('not_id', 'not_user')
->from('t_notification_not', 'n')
->where('not_type LIKE :type AND not_token LIKE :token')
->setParameter('type', $type)
->setParameter('token', $token);
$query = $qb->execute();

if ($query->rowCount() == 0) {
$conn->insert('t_notification_not',
array('not_user' => $user->getId(),
'not_type' => $type,
'not_token' => $token
),
array('integer', 'string', 'string'));
return Dbal::conn()->lastInsertId();
} catch (\Doctrine\DBAL\DBALException $e) {
if (strpos($e->getPrevious()->getMessage(), "Integrity constraint violation: 1062")) {
return false;
} else {
throw $e;
$id = $conn->lastInsertId();
} else {
$data = $query->fetch();
if ($data['not_user'] != $user->getId()) {
$conn->update('t_notification_not',
array('not_user' => $user->getId()),
array('not_id' => $data['not_id']),
array('integer', 'integer'));
}
$id = $data['not_id'];
}
$conn->commit();
return $id;
}
}
3 changes: 2 additions & 1 deletion src/Payutc/Service/NOTIFICATIONS.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class NOTIFICATIONS extends \ServiceBase {
*/
public function addDevice($type, $token) {
$this->checkRight(false, false, false);
Notification::addDevice($type, $token, $this->user());
$id = Notification::addDevice($type, $token, $this->user());
return true;
}
}

0 comments on commit be21c22

Please sign in to comment.