diff options
author | Joas Schilling <coding@schilljs.com> | 2021-12-03 17:15:31 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-02-17 18:31:00 +0300 |
commit | 55121e46170af29d752eece2b99cc72bb8b6f1e2 (patch) | |
tree | e172a19ecc15b8a74d5c76f399b86589f9259116 /lib | |
parent | 4080f6d0905c60741c5acfcfd976e8d4cb226cdc (diff) |
Change database structure
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Federation/FederationManager.php | 6 | ||||
-rw-r--r-- | lib/Manager.php | 31 | ||||
-rw-r--r-- | lib/Migration/Version14000Date20211203132513.php | 47 | ||||
-rw-r--r-- | lib/Model/SelectHelper.php | 3 | ||||
-rw-r--r-- | lib/Room.php | 20 |
5 files changed, 85 insertions, 22 deletions
diff --git a/lib/Federation/FederationManager.php b/lib/Federation/FederationManager.php index f8368b23d..8efd86096 100644 --- a/lib/Federation/FederationManager.php +++ b/lib/Federation/FederationManager.php @@ -135,7 +135,7 @@ class FederationManager { // Add user to the room $room = $this->manager->getRoomById($invitation->getRoomId()); if ( - !$this->notifications->sendShareAccepted($room->getServerUrl(), $invitation->getRemoteId(), $invitation->getAccessToken()) + !$this->notifications->sendShareAccepted($room->getRemoteServer(), $invitation->getRemoteId(), $invitation->getAccessToken()) ) { throw new CannotReachRemoteException(); } @@ -147,7 +147,7 @@ class FederationManager { 'actorId' => $user->getUID(), 'displayName' => $user->getDisplayName(), 'accessToken' => $invitation->getAccessToken(), - 'remoteId' => $invitation->getRemoteId(), + 'remoteId' => $invitation->getRemoteId(), // FIXME this seems unnecessary ] ]; $this->participantService->addUsers($room, $participant, $user); @@ -171,7 +171,7 @@ class FederationManager { $this->invitationMapper->delete($invitation); - $this->notifications->sendShareDeclined($room->getServerUrl(), $invitation->getRemoteId(), $invitation->getAccessToken()); + $this->notifications->sendShareDeclined($room->getRemoteServer(), $invitation->getRemoteId(), $invitation->getAccessToken()); } /** diff --git a/lib/Manager.php b/lib/Manager.php index 993ade134..2e90625a9 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -186,7 +186,8 @@ class Manager { (string) $row['name'], (string) $row['description'], (string) $row['password'], - (string) $row['server_url'], + (string) $row['remote_server'], + (string) $row['remote_token'], (int) $row['active_guests'], (int) $row['default_permissions'], (int) $row['call_permissions'], @@ -662,13 +663,15 @@ class Manager { $query->expr()->eq('a.actor_type', $query->createNamedParameter($actorType)), $query->expr()->eq('a.actor_id', $query->createNamedParameter($actorId)), $query->expr()->eq('a.room_id', 'r.id') - )) - ->where($query->expr()->eq('r.token', $query->createNamedParameter($token))); + )); + if ($serverUrl === null) { - $query->andWhere($query->expr()->isNull('r.server_url')); + $query->where($query->expr()->eq('r.token', $query->createNamedParameter($token))); } else { - $query->andWhere($query->expr()->eq('r.server_url', $query->createNamedParameter($serverUrl))); + $query + ->where($query->expr()->eq('r.remote_token', $query->createNamedParameter($token))) + ->andWhere($query->expr()->eq('r.remote_server', $query->createNamedParameter($serverUrl))); } if ($sessionId !== null) { @@ -702,7 +705,7 @@ class Manager { /** * @param string $token - * @param string|null $preloadUserId Load this participants information if possible + * @param string|null $preloadUserId Load this participant's information if possible * @return Room * @throws RoomNotFoundException */ @@ -715,13 +718,14 @@ class Manager { $query = $this->db->getQueryBuilder(); $helper = new SelectHelper(); $helper->selectRoomsTable($query); - $query->from('talk_rooms', 'r') - ->where($query->expr()->eq('r.token', $query->createNamedParameter($token))); + $query->from('talk_rooms', 'r'); if ($serverUrl === null) { - $query->andWhere($query->expr()->isNull('r.server_url')); + $query->where($query->expr()->eq('r.token', $query->createNamedParameter($token))); } else { - $query->andWhere($query->expr()->eq('r.server_url', $query->createNamedParameter($serverUrl))); + $query + ->where($query->expr()->eq('r.remote_token', $query->createNamedParameter($token))) + ->andWhere($query->expr()->eq('r.remote_server', $query->createNamedParameter($serverUrl))); } @@ -951,7 +955,9 @@ class Manager { * @return Room * @throws DBException */ - public function createRemoteRoom(int $type, string $name, string $token, string $serverUrl): Room { + public function createRemoteRoom(int $type, string $name, string $remoteToken, string $remoteServer): Room { + $token = $this->getNewToken(); + $qb = $this->db->getQueryBuilder(); $qb->insert('talk_rooms') @@ -959,7 +965,8 @@ class Manager { 'name' => $qb->createNamedParameter($name), 'type' => $qb->createNamedParameter($type, IQueryBuilder::PARAM_INT), 'token' => $qb->createNamedParameter($token), - 'server_url' => $qb->createNamedParameter($serverUrl), + 'remote_token' => $qb->createNamedParameter($remoteToken), + 'remote_server' => $qb->createNamedParameter($remoteServer), ]); $qb->executeStatement(); diff --git a/lib/Migration/Version14000Date20211203132513.php b/lib/Migration/Version14000Date20211203132513.php new file mode 100644 index 000000000..2c633e024 --- /dev/null +++ b/lib/Migration/Version14000Date20211203132513.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); + +namespace OCA\Talk\Migration; + +use Closure; +use Doctrine\DBAL\Types\Types; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +class Version14000Date20211203132513 extends SimpleMigrationStep { + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('talk_rooms'); + if (!$table->hasColumn('remote_server')) { + $table->addColumn('remote_server', Types::STRING, [ + 'notnull' => false, + 'length' => 512, + 'default' => null, + ]); + $table->addColumn('remote_token', Types::STRING, [ + 'notnull' => false, + 'length' => 32, + 'default' => null, + ]); + + // Can not be unique as we have null, null for all local rooms. + $table->addIndex(['remote_server', 'remote_token'], 'remote_id'); + } + + if ($table->hasColumn('server_url')) { + $table->dropColumn('server_url'); + } + + return $schema; + } +} diff --git a/lib/Model/SelectHelper.php b/lib/Model/SelectHelper.php index 3b2d81ce3..d08fc8823 100644 --- a/lib/Model/SelectHelper.php +++ b/lib/Model/SelectHelper.php @@ -51,7 +51,8 @@ class SelectHelper { ->addSelect($alias . 'object_type') ->addSelect($alias . 'object_id') ->addSelect($alias . 'listable') - ->addSelect($alias . 'server_url') + ->addSelect($alias . 'remote_server') + ->addSelect($alias . 'remote_token') ->selectAlias($alias . 'id', 'r_id'); } diff --git a/lib/Room.php b/lib/Room.php index 647462b40..d8520258d 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -185,7 +185,9 @@ class Room { /** @var string */ private $password; /** @var string */ - private $serverUrl; + private $remoteServer; + /** @var string */ + private $remoteToken; /** @var int */ private $activeGuests; /** @var int */ @@ -228,7 +230,8 @@ class Room { string $name, string $description, string $password, - string $serverUrl, + string $remoteServer, + string $remoteToken, int $activeGuests, int $defaultPermissions, int $callPermissions, @@ -256,7 +259,8 @@ class Room { $this->name = $name; $this->description = $description; $this->password = $password; - $this->serverUrl = $serverUrl; + $this->remoteServer = $remoteServer; + $this->remoteToken = $remoteToken; $this->activeGuests = $activeGuests; $this->defaultPermissions = $defaultPermissions; $this->callPermissions = $callPermissions; @@ -401,12 +405,16 @@ class Room { return $this->password; } - public function getServerUrl(): string { - return $this->serverUrl; + public function getRemoteServer(): string { + return $this->remoteServer; + } + + public function getRemoteToken(): string { + return $this->remoteToken; } public function isFederatedRemoteRoom(): bool { - return $this->serverUrl !== ''; + return $this->remoteServer !== ''; } public function setParticipant(?string $userId, Participant $participant): void { |