зеркало из https://github.com/nextcloud/spreed.git
Make sure column names are lowercase to not break postgres
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Родитель
d0967b313f
Коммит
2121735753
|
@ -67,11 +67,11 @@ class Manager {
|
|||
*/
|
||||
public function createRoomObject(array $row) {
|
||||
$activeSince = null;
|
||||
if (!empty($row['activeSince'])) {
|
||||
$activeSince = new \DateTime($row['activeSince']);
|
||||
if (!empty($row['active_since'])) {
|
||||
$activeSince = new \DateTime($row['active_since']);
|
||||
}
|
||||
|
||||
return new Room($this, $this->db, $this->secureRandom, $this->dispatcher, $this->hasher, (int) $row['id'], (int) $row['type'], $row['token'], $row['name'], $row['password'], (int) $row['activeGuests'], $activeSince);
|
||||
return new Room($this, $this->db, $this->secureRandom, $this->dispatcher, $this->hasher, (int) $row['id'], (int) $row['type'], $row['token'], $row['name'], $row['password'], (int) $row['active_guests'], $activeSince);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ class Manager {
|
|||
* @return Participant
|
||||
*/
|
||||
public function createParticipantObject(Room $room, array $row) {
|
||||
return new Participant($this->db, $room, $row['userId'], (int) $row['participantType'], (int) $row['lastPing'], $row['sessionId'], (bool) $row['inCall']);
|
||||
return new Participant($this->db, $room, $row['user_id'], (int) $row['participant_type'], (int) $row['last_ping'], $row['session_id'], (bool) $row['in_call']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,17 +92,17 @@ class Manager {
|
|||
$query->select('*')
|
||||
->from('talk_rooms', 'r')
|
||||
->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
|
||||
$query->expr()->eq('p.userId', $query->createNamedParameter($participant)),
|
||||
$query->expr()->eq('p.roomId', 'r.id')
|
||||
$query->expr()->eq('p.user_id', $query->createNamedParameter($participant)),
|
||||
$query->expr()->eq('p.room_id', 'r.id')
|
||||
))
|
||||
->where($query->expr()->isNotNull('p.userId'));
|
||||
->where($query->expr()->isNotNull('p.user_id'));
|
||||
|
||||
$result = $query->execute();
|
||||
$rooms = [];
|
||||
while ($row = $result->fetch()) {
|
||||
$room = $this->createRoomObject($row);
|
||||
if ($participant !== null && isset($row['userId'])) {
|
||||
$room->setParticipant($row['userId'], $this->createParticipantObject($room, $row));
|
||||
if ($participant !== null && isset($row['user_id'])) {
|
||||
$room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row));
|
||||
}
|
||||
$rooms[] = $room;
|
||||
}
|
||||
|
@ -128,10 +128,10 @@ class Manager {
|
|||
if ($participant !== null) {
|
||||
// Non guest user
|
||||
$query->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
|
||||
$query->expr()->eq('p.userId', $query->createNamedParameter($participant)),
|
||||
$query->expr()->eq('p.roomId', 'r.id')
|
||||
$query->expr()->eq('p.user_id', $query->createNamedParameter($participant)),
|
||||
$query->expr()->eq('p.room_id', 'r.id')
|
||||
))
|
||||
->andWhere($query->expr()->isNotNull('p.userId'));
|
||||
->andWhere($query->expr()->isNotNull('p.user_id'));
|
||||
}
|
||||
|
||||
$result = $query->execute();
|
||||
|
@ -143,8 +143,8 @@ class Manager {
|
|||
}
|
||||
|
||||
$room = $this->createRoomObject($row);
|
||||
if ($participant !== null && isset($row['userId'])) {
|
||||
$room->setParticipant($row['userId'], $this->createParticipantObject($room, $row));
|
||||
if ($participant !== null && isset($row['user_id'])) {
|
||||
$room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row));
|
||||
}
|
||||
|
||||
if ($participant === null && $room->getType() !== Room::PUBLIC_CALL) {
|
||||
|
@ -173,8 +173,8 @@ class Manager {
|
|||
if ($participant !== null) {
|
||||
// Non guest user
|
||||
$query->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
|
||||
$query->expr()->eq('p.userId', $query->createNamedParameter($participant)),
|
||||
$query->expr()->eq('p.roomId', 'r.id')
|
||||
$query->expr()->eq('p.user_id', $query->createNamedParameter($participant)),
|
||||
$query->expr()->eq('p.room_id', 'r.id')
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -187,15 +187,15 @@ class Manager {
|
|||
}
|
||||
|
||||
$room = $this->createRoomObject($row);
|
||||
if ($participant !== null && isset($row['userId'])) {
|
||||
$room->setParticipant($row['userId'], $this->createParticipantObject($room, $row));
|
||||
if ($participant !== null && isset($row['user_id'])) {
|
||||
$room->setParticipant($row['user_id'], $this->createParticipantObject($room, $row));
|
||||
}
|
||||
|
||||
if ($room->getType() === Room::PUBLIC_CALL) {
|
||||
return $room;
|
||||
}
|
||||
|
||||
if ($participant !== null && $row['userId'] === $participant) {
|
||||
if ($participant !== null && $row['user_id'] === $participant) {
|
||||
return $room;
|
||||
}
|
||||
|
||||
|
@ -260,8 +260,8 @@ class Manager {
|
|||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('talk_participants', 'p')
|
||||
->leftJoin('p', 'talk_rooms', 'r', $query->expr()->eq('p.roomId', 'r.id'))
|
||||
->where($query->expr()->eq('p.sessionId', $query->createNamedParameter($sessionId)))
|
||||
->leftJoin('p', 'talk_rooms', 'r', $query->expr()->eq('p.room_id', 'r.id'))
|
||||
->where($query->expr()->eq('p.session_id', $query->createNamedParameter($sessionId)))
|
||||
->setMaxResults(1);
|
||||
|
||||
$result = $query->execute();
|
||||
|
@ -272,13 +272,13 @@ class Manager {
|
|||
throw new RoomNotFoundException();
|
||||
}
|
||||
|
||||
if ((string) $userId !== $row['userId']) {
|
||||
if ((string) $userId !== $row['user_id']) {
|
||||
throw new RoomNotFoundException();
|
||||
}
|
||||
|
||||
$room = $this->createRoomObject($row);
|
||||
$participant = $this->createParticipantObject($room, $row);
|
||||
$room->setParticipant($row['userId'], $participant);
|
||||
$room->setParticipant($row['user_id'], $participant);
|
||||
|
||||
if ($room->getType() === Room::PUBLIC_CALL || !in_array($participant->getParticipantType(), [Participant::GUEST, Participant::USER_SELF_JOINED], true)) {
|
||||
return $room;
|
||||
|
@ -298,16 +298,16 @@ class Manager {
|
|||
$query->select('*')
|
||||
->from('talk_rooms', 'r1')
|
||||
->leftJoin('r1', 'talk_participants', 'p1', $query->expr()->andX(
|
||||
$query->expr()->eq('p1.userId', $query->createNamedParameter($participant1)),
|
||||
$query->expr()->eq('p1.roomId', 'r1.id')
|
||||
$query->expr()->eq('p1.user_id', $query->createNamedParameter($participant1)),
|
||||
$query->expr()->eq('p1.room_id', 'r1.id')
|
||||
))
|
||||
->leftJoin('r1', 'talk_participants', 'p2', $query->expr()->andX(
|
||||
$query->expr()->eq('p2.userId', $query->createNamedParameter($participant2)),
|
||||
$query->expr()->eq('p2.roomId', 'r1.id')
|
||||
$query->expr()->eq('p2.user_id', $query->createNamedParameter($participant2)),
|
||||
$query->expr()->eq('p2.room_id', 'r1.id')
|
||||
))
|
||||
->where($query->expr()->eq('r1.type', $query->createNamedParameter(Room::ONE_TO_ONE_CALL, IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->isNotNull('p1.userId'))
|
||||
->andWhere($query->expr()->isNotNull('p2.userId'));
|
||||
->andWhere($query->expr()->isNotNull('p1.user_id'))
|
||||
->andWhere($query->expr()->isNotNull('p2.user_id'));
|
||||
|
||||
$result = $query->execute();
|
||||
$row = $result->fetch();
|
||||
|
@ -377,9 +377,9 @@ class Manager {
|
|||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->neq('sessionId', $query->createNamedParameter('0')))
|
||||
->orderBy('lastPing', 'DESC')
|
||||
->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->neq('session_id', $query->createNamedParameter('0')))
|
||||
->orderBy('last_ping', 'DESC')
|
||||
->setMaxResults(1);
|
||||
$result = $query->execute();
|
||||
$row = $result->fetch();
|
||||
|
@ -389,7 +389,7 @@ class Manager {
|
|||
return null;
|
||||
}
|
||||
|
||||
return $row['sessionId'];
|
||||
return $row['session_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -404,15 +404,15 @@ class Manager {
|
|||
|
||||
// Delete all messages from or to the current user
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('sessionId')
|
||||
$query->select('session_id')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)));
|
||||
->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
|
||||
$result = $query->execute();
|
||||
|
||||
$sessionIds = [];
|
||||
while ($row = $result->fetch()) {
|
||||
if ($row['sessionId'] !== '0') {
|
||||
$sessionIds[] = $row['sessionId'];
|
||||
if ($row['session_id'] !== '0') {
|
||||
$sessionIds[] = $row['session_id'];
|
||||
}
|
||||
}
|
||||
$result->closeCursor();
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCA\Spreed\Migration;
|
||||
|
||||
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
use OCP\Migration\IOutput;
|
||||
|
||||
class Version2001Date20180103144447 extends SimpleMigrationStep {
|
||||
|
||||
/** @var IDBConnection */
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @param IDBConnection $connection
|
||||
*/
|
||||
public function __construct(IDBConnection $connection) {
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param IOutput $output
|
||||
* @param \Closure $schemaClosure The `\Closure` returns a `Schema`
|
||||
* @param array $options
|
||||
* @return null|Schema
|
||||
* @since 13.0.0
|
||||
*/
|
||||
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
|
||||
/** @var Schema $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
$table = $schema->getTable('talk_rooms');
|
||||
|
||||
if (!$table->hasColumn('active_since')) {
|
||||
$table->addColumn('active_since', Type::DATETIME, [
|
||||
'notnull' => false,
|
||||
]);
|
||||
$table->addColumn('active_guests', Type::INTEGER, [
|
||||
'notnull' => true,
|
||||
'length' => 4,
|
||||
'default' => 0,
|
||||
'unsigned' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
$table = $schema->getTable('talk_participants');
|
||||
|
||||
if (!$table->hasColumn('user_id')) {
|
||||
$table->addColumn('user_id', Type::STRING, [
|
||||
'notnull' => false,
|
||||
'length' => 255,
|
||||
]);
|
||||
$table->addColumn('room_id', Type::INTEGER, [
|
||||
'notnull' => true,
|
||||
'length' => 11,
|
||||
]);
|
||||
$table->addColumn('last_ping', Type::INTEGER, [
|
||||
'notnull' => true,
|
||||
'length' => 11,
|
||||
]);
|
||||
$table->addColumn('session_id', Type::STRING, [
|
||||
'notnull' => true,
|
||||
'length' => 255,
|
||||
]);
|
||||
$table->addColumn('participant_type', Type::SMALLINT, [
|
||||
'notnull' => true,
|
||||
'length' => 6,
|
||||
'default' => 0,
|
||||
]);
|
||||
$table->addColumn('in_call', Type::BOOLEAN, [
|
||||
'default' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IOutput $output
|
||||
* @param \Closure $schemaClosure The `\Closure` returns a `Schema`
|
||||
* @param array $options
|
||||
* @since 13.0.0
|
||||
*/
|
||||
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
|
||||
|
||||
if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
|
||||
// Couldn't install prior anyway, so we can skip this update step as well
|
||||
return;
|
||||
}
|
||||
|
||||
$update = $this->connection->getQueryBuilder();
|
||||
$update->update('talk_rooms')
|
||||
->set('active_since', 'activeSince')
|
||||
->set('active_guests', 'activeGuests');
|
||||
$update->execute();
|
||||
|
||||
$update = $this->connection->getQueryBuilder();
|
||||
$update->update('talk_participants')
|
||||
->set('user_id', 'userId')
|
||||
->set('room_id', 'roomId')
|
||||
->set('last_ping', 'lastPing')
|
||||
->set('session_id', 'sessionId')
|
||||
->set('participant_type', 'participantType')
|
||||
->set('in_call', 'inCall');
|
||||
$update->execute();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCA\Spreed\Migration;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use OCP\Migration\SimpleMigrationStep;
|
||||
use OCP\Migration\IOutput;
|
||||
|
||||
class Version2001Date20180103150836 extends SimpleMigrationStep {
|
||||
|
||||
/**
|
||||
* @param IOutput $output
|
||||
* @param \Closure $schemaClosure The `\Closure` returns a `Schema`
|
||||
* @param array $options
|
||||
* @return null|Schema
|
||||
* @since 13.0.0
|
||||
*/
|
||||
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
|
||||
/** @var Schema $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
$table = $schema->getTable('talk_rooms');
|
||||
if ($table->hasColumn('activeSince')) {
|
||||
$table->dropColumn('activeSince');
|
||||
$table->dropColumn('activeGuests');
|
||||
}
|
||||
|
||||
$table = $schema->getTable('talk_participants');
|
||||
if ($table->hasColumn('userId')) {
|
||||
$table->dropColumn('userId');
|
||||
$table->dropColumn('roomId');
|
||||
$table->dropColumn('lastPing');
|
||||
$table->dropColumn('sessionId');
|
||||
$table->dropColumn('participantType');
|
||||
$table->dropColumn('inCall');
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
}
|
160
lib/Room.php
160
lib/Room.php
|
@ -178,8 +178,8 @@ class Room {
|
|||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->eq('roomId', $query->createNamedParameter($this->getId())));
|
||||
->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->getId())));
|
||||
$result = $query->execute();
|
||||
$row = $result->fetch();
|
||||
$result->closeCursor();
|
||||
|
@ -209,8 +209,8 @@ class Room {
|
|||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId)))
|
||||
->andWhere($query->expr()->eq('roomId', $query->createNamedParameter($this->getId())));
|
||||
->where($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)))
|
||||
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->getId())));
|
||||
$result = $query->execute();
|
||||
$row = $result->fetch();
|
||||
$result->closeCursor();
|
||||
|
@ -231,7 +231,7 @@ class Room {
|
|||
|
||||
// Delete all participants
|
||||
$query->delete('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
$query->execute();
|
||||
|
||||
// Delete room
|
||||
|
@ -319,7 +319,7 @@ class Room {
|
|||
if ($isGuest && $this->getType() === self::PUBLIC_CALL) {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->update('talk_rooms')
|
||||
->set('activeGuests', $query->createFunction($query->getColumnName('activeGuests') . ' + 1'))
|
||||
->set('active_guests', $query->createFunction($query->getColumnName('active_guests') . ' + 1'))
|
||||
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
$query->execute();
|
||||
|
||||
|
@ -332,9 +332,9 @@ class Room {
|
|||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->update('talk_rooms')
|
||||
->set('activeSince', $query->createNamedParameter($since, 'datetime'))
|
||||
->set('active_since', $query->createNamedParameter($since, 'datetime'))
|
||||
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->isNull('activeSince'));
|
||||
->andWhere($query->expr()->isNull('active_since'));
|
||||
$query->execute();
|
||||
|
||||
$this->activeSince = $since;
|
||||
|
@ -348,8 +348,8 @@ class Room {
|
|||
public function resetActiveSince() {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->update('talk_rooms')
|
||||
->set('activeGuests', $query->createNamedParameter(0))
|
||||
->set('activeSince', $query->createNamedParameter(null, 'datetime'))
|
||||
->set('active_guests', $query->createNamedParameter(0))
|
||||
->set('active_since', $query->createNamedParameter(null, 'datetime'))
|
||||
->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
$query->execute();
|
||||
|
||||
|
@ -388,8 +388,8 @@ class Room {
|
|||
// Kick all guests and users that were not invited
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->delete('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->in('participantType', $query->createNamedParameter([Participant::GUEST, Participant::USER_SELF_JOINED], IQueryBuilder::PARAM_INT_ARRAY)));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->in('participant_type', $query->createNamedParameter([Participant::GUEST, Participant::USER_SELF_JOINED], IQueryBuilder::PARAM_INT_ARRAY)));
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
@ -413,18 +413,18 @@ class Room {
|
|||
$query->insert('talk_participants')
|
||||
->values(
|
||||
[
|
||||
'userId' => $query->createParameter('userId'),
|
||||
'sessionId' => $query->createParameter('sessionId'),
|
||||
'participantType' => $query->createParameter('participantType'),
|
||||
'roomId' => $query->createNamedParameter($this->getId()),
|
||||
'lastPing' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
|
||||
'user_id' => $query->createParameter('user_id'),
|
||||
'session_id' => $query->createParameter('session_id'),
|
||||
'participant_type' => $query->createParameter('participant_type'),
|
||||
'room_id' => $query->createNamedParameter($this->getId()),
|
||||
'last_ping' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
|
||||
]
|
||||
);
|
||||
|
||||
foreach ($participants as $participant) {
|
||||
$query->setParameter('userId', $participant['userId'])
|
||||
->setParameter('sessionId', isset($participant['sessionId']) ? $participant['sessionId'] : '0')
|
||||
->setParameter('participantType', isset($participant['participantType']) ? $participant['participantType'] : Participant::USER, IQueryBuilder::PARAM_INT);
|
||||
$query->setParameter('user_id', $participant['userId'])
|
||||
->setParameter('session_id', isset($participant['sessionId']) ? $participant['sessionId'] : '0')
|
||||
->setParameter('participant_type', isset($participant['participantType']) ? $participant['participantType'] : Participant::USER, IQueryBuilder::PARAM_INT);
|
||||
|
||||
$query->execute();
|
||||
}
|
||||
|
@ -446,9 +446,9 @@ class Room {
|
|||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->update('talk_participants')
|
||||
->set('participantType', $query->createNamedParameter($participantType, IQueryBuilder::PARAM_INT))
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('userId', $query->createNamedParameter($participant)));
|
||||
->set('participant_type', $query->createNamedParameter($participantType, IQueryBuilder::PARAM_INT))
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($participant)));
|
||||
$query->execute();
|
||||
|
||||
$this->dispatcher->dispatch(self::class . '::postSetParticipantType', new GenericEvent($this, [
|
||||
|
@ -467,8 +467,8 @@ class Room {
|
|||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->delete('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('userId', $query->createNamedParameter($user->getUID())));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($user->getUID())));
|
||||
$query->execute();
|
||||
|
||||
$this->dispatcher->dispatch(self::class . '::postRemoveUser', new GenericEvent($this, [
|
||||
|
@ -486,8 +486,8 @@ class Room {
|
|||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->delete('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('sessionId', $query->createNamedParameter($participant->getSessionId())));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($participant->getSessionId())));
|
||||
$query->execute();
|
||||
|
||||
$this->dispatcher->dispatch(self::class . '::postRemoveBySession', new GenericEvent($this, [
|
||||
|
@ -509,12 +509,12 @@ class Room {
|
|||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->update('talk_participants')
|
||||
->set('sessionId', $query->createParameter('sessionId'))
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('userId', $query->createNamedParameter($userId)));
|
||||
->set('session_id', $query->createParameter('session_id'))
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
|
||||
|
||||
$sessionId = $this->secureRandom->generate(255);
|
||||
$query->setParameter('sessionId', $sessionId);
|
||||
$query->setParameter('session_id', $sessionId);
|
||||
$result = $query->execute();
|
||||
|
||||
if ($result === 0) {
|
||||
|
@ -532,7 +532,7 @@ class Room {
|
|||
|
||||
while (!$this->isSessionUnique($sessionId)) {
|
||||
$sessionId = $this->secureRandom->generate(255);
|
||||
$query->setParameter('sessionId', $sessionId);
|
||||
$query->setParameter('session_id', $sessionId);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
@ -550,17 +550,17 @@ class Room {
|
|||
// Reset sessions on all normal rooms
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->update('talk_participants')
|
||||
->set('sessionId', $query->createNamedParameter('0'))
|
||||
->set('inCall', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
|
||||
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->neq('participantType', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
|
||||
->set('session_id', $query->createNamedParameter('0'))
|
||||
->set('in_call', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
|
||||
->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->neq('participant_type', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
|
||||
$query->execute();
|
||||
|
||||
// And kill session on all self joined rooms
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->delete('talk_participants')
|
||||
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->eq('participantType', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
|
||||
->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)))
|
||||
->andWhere($query->expr()->eq('participant_type', $query->createNamedParameter(Participant::USER_SELF_JOINED, IQueryBuilder::PARAM_INT)));
|
||||
$query->execute();
|
||||
|
||||
$this->dispatcher->dispatch(self::class . '::postUserDisconnectRoom', new GenericEvent($this));
|
||||
|
@ -581,12 +581,12 @@ class Room {
|
|||
|
||||
$sessionId = $this->secureRandom->generate(255);
|
||||
while (!$this->db->insertIfNotExist('*PREFIX*talk_participants', [
|
||||
'userId' => '',
|
||||
'roomId' => $this->getId(),
|
||||
'lastPing' => 0,
|
||||
'sessionId' => $sessionId,
|
||||
'participantType' => Participant::GUEST,
|
||||
], ['sessionId'])) {
|
||||
'user_id' => '',
|
||||
'room_id' => $this->getId(),
|
||||
'last_ping' => 0,
|
||||
'session_id' => $sessionId,
|
||||
'participant_type' => Participant::GUEST,
|
||||
], ['session_id'])) {
|
||||
$sessionId = $this->secureRandom->generate(255);
|
||||
}
|
||||
|
||||
|
@ -612,9 +612,9 @@ class Room {
|
|||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->update('talk_participants')
|
||||
->set('inCall', $query->createNamedParameter((int) $active, IQueryBuilder::PARAM_INT))
|
||||
->where($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId)))
|
||||
->andWhere($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
->set('in_call', $query->createNamedParameter((int) $active, IQueryBuilder::PARAM_INT))
|
||||
->where($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)))
|
||||
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
$query->execute();
|
||||
|
||||
if ($active) {
|
||||
|
@ -644,7 +644,7 @@ class Room {
|
|||
$query = $this->db->getQueryBuilder();
|
||||
$query->selectAlias($query->createFunction('COUNT(*)'), 'num_sessions')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId)));
|
||||
->where($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)));
|
||||
$result = $query->execute();
|
||||
$numSessions = (int) $result->fetchColumn();
|
||||
$result->closeCursor();
|
||||
|
@ -657,9 +657,9 @@ class Room {
|
|||
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->delete('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->emptyString('userId'))
|
||||
->andWhere($query->expr()->lte('lastPing', $query->createNamedParameter(time() - 30, IQueryBuilder::PARAM_INT)));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->emptyString('user_id'))
|
||||
->andWhere($query->expr()->lte('last_ping', $query->createNamedParameter(time() - 30, IQueryBuilder::PARAM_INT)));
|
||||
$query->execute();
|
||||
|
||||
$this->dispatcher->dispatch(self::class . '::postCleanGuests', new GenericEvent($this));
|
||||
|
@ -673,28 +673,28 @@ class Room {
|
|||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('*')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
|
||||
if ($lastPing > 0) {
|
||||
$query->andWhere($query->expr()->gt('lastPing', $query->createNamedParameter($lastPing, IQueryBuilder::PARAM_INT)));
|
||||
$query->andWhere($query->expr()->gt('last_ping', $query->createNamedParameter($lastPing, IQueryBuilder::PARAM_INT)));
|
||||
}
|
||||
|
||||
$result = $query->execute();
|
||||
|
||||
$users = $guests = [];
|
||||
while ($row = $result->fetch()) {
|
||||
if ($row['userId'] !== '' && $row['userId'] !== null) {
|
||||
$users[$row['userId']] = [
|
||||
'inCall' => (bool) $row['inCall'],
|
||||
'lastPing' => (int) $row['lastPing'],
|
||||
'sessionId' => $row['sessionId'],
|
||||
'participantType' => (int) $row['participantType'],
|
||||
if ($row['user_id'] !== '' && $row['user_id'] !== null) {
|
||||
$users[$row['user_id']] = [
|
||||
'inCall' => (bool) $row['in_call'],
|
||||
'lastPing' => (int) $row['last_ping'],
|
||||
'sessionId' => $row['session_id'],
|
||||
'participantType' => (int) $row['participant_type'],
|
||||
];
|
||||
} else {
|
||||
$guests[] = [
|
||||
'inCall' => (bool) $row['inCall'],
|
||||
'lastPing' => (int) $row['lastPing'],
|
||||
'sessionId' => $row['sessionId'],
|
||||
'inCall' => (bool) $row['in_call'],
|
||||
'lastPing' => (int) $row['last_ping'],
|
||||
'sessionId' => $row['session_id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -711,15 +711,15 @@ class Room {
|
|||
*/
|
||||
public function getActiveSessions() {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('sessionId')
|
||||
$query->select('session_id')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->neq('sessionId', $query->createNamedParameter('0')));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->neq('session_id', $query->createNamedParameter('0')));
|
||||
$result = $query->execute();
|
||||
|
||||
$sessions = [];
|
||||
while ($row = $result->fetch()) {
|
||||
$sessions[] = $row['sessionId'];
|
||||
$sessions[] = $row['session_id'];
|
||||
}
|
||||
$result->closeCursor();
|
||||
|
||||
|
@ -732,16 +732,16 @@ class Room {
|
|||
*/
|
||||
public function getInactiveUserIds() {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('userId')
|
||||
$query->select('user_id')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('sessionId', $query->createNamedParameter('0')))
|
||||
->andWhere($query->expr()->nonEmptyString('userId'));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('session_id', $query->createNamedParameter('0')))
|
||||
->andWhere($query->expr()->nonEmptyString('user_id'));
|
||||
$result = $query->execute();
|
||||
|
||||
$userIds = [];
|
||||
while ($row = $result->fetch()) {
|
||||
$userIds[] = $row['userId'];
|
||||
$userIds[] = $row['user_id'];
|
||||
}
|
||||
$result->closeCursor();
|
||||
|
||||
|
@ -753,10 +753,10 @@ class Room {
|
|||
*/
|
||||
public function hasSessionsInCall() {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->select('sessionId')
|
||||
$query->select('session_id')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('inCall', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
|
||||
->andWhere($query->expr()->eq('in_call', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
|
||||
->setMaxResults(1);
|
||||
$result = $query->execute();
|
||||
$row = $result->fetch();
|
||||
|
@ -773,10 +773,10 @@ class Room {
|
|||
$query = $this->db->getQueryBuilder();
|
||||
$query->selectAlias($query->createFunction('COUNT(*)'), 'num_participants')
|
||||
->from('talk_participants')
|
||||
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
->where($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
|
||||
if ($lastPing > 0) {
|
||||
$query->andWhere($query->expr()->gt('lastPing', $query->createNamedParameter($lastPing, IQueryBuilder::PARAM_INT)));
|
||||
$query->andWhere($query->expr()->gt('last_ping', $query->createNamedParameter($lastPing, IQueryBuilder::PARAM_INT)));
|
||||
}
|
||||
|
||||
$result = $query->execute();
|
||||
|
@ -794,10 +794,10 @@ class Room {
|
|||
public function ping($userId, $sessionId, $timestamp) {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->update('talk_participants')
|
||||
->set('lastPing', $query->createNamedParameter($timestamp, IQueryBuilder::PARAM_INT))
|
||||
->where($query->expr()->eq('userId', $query->createNamedParameter((string) $userId)))
|
||||
->andWhere($query->expr()->eq('sessionId', $query->createNamedParameter($sessionId)))
|
||||
->andWhere($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
->set('last_ping', $query->createNamedParameter($timestamp, IQueryBuilder::PARAM_INT))
|
||||
->where($query->expr()->eq('user_id', $query->createNamedParameter((string) $userId)))
|
||||
->andWhere($query->expr()->eq('session_id', $query->createNamedParameter($sessionId)))
|
||||
->andWhere($query->expr()->eq('room_id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
||||
|
||||
$query->execute();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче