summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Sein <ivan@struktur.de>2017-11-02 12:08:06 +0100
committerGitHub <noreply@github.com>2017-11-02 12:08:06 +0100
commit7d8b5f0c89d668d6d40a24cd3e95c7e25ec9c41d (patch)
treeae563d405efe527b0678092e7be6b9d9e86f05f8
parent08b470a1a53632edba47fd1a2fc46cea0c3b163a (diff)
parent23511a9324b81c56ce1ada6465341513bbf4ecba (diff)
Merge pull request #453 from nextcloud/unify-database
Unify database table namespace
-rw-r--r--appinfo/info.xml9
-rw-r--r--lib/Manager.php34
-rw-r--r--lib/Migration/Version2000Date20171026140256.php (renamed from lib/Migration/EmptyNameInsteadOfRandom.php)31
-rw-r--r--lib/Migration/Version2000Date20171026140257.php (renamed from lib/Migration/FillRoomTokens.php)34
-rw-r--r--lib/Migration/Version2001Date20171026134605.php387
-rw-r--r--lib/Migration/Version2001Date20171026141336.php57
-rw-r--r--lib/Room.php52
-rw-r--r--lib/Signaling/Messages.php12
-rw-r--r--tests/integration/spreedcheats/lib/Controller/ApiController.php6
-rw-r--r--tests/php/Migration/EmptyNameInsteadOfRandomTest.php132
10 files changed, 518 insertions, 236 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 9582de5b1..07590aebf 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -38,7 +38,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
<bugs>https://github.com/nextcloud/spreed/issues</bugs>
<repository type="git">https://github.com/nextcloud/spreed.git</repository>
- <version>2.1.8</version>
+ <version>2.1.9</version>
<dependencies>
<nextcloud min-version="13" max-version="13" />
@@ -74,13 +74,6 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m
</providers>
</activity>
- <repair-steps>
- <post-migration>
- <step>OCA\Spreed\Migration\EmptyNameInsteadOfRandom</step>
- <step>OCA\Spreed\Migration\FillRoomTokens</step>
- </post-migration>
- </repair-steps>
-
<contactsmenu>
<provider>OCA\Spreed\ContactsMenu\Providers\CallProvider</provider>
</contactsmenu>
diff --git a/lib/Manager.php b/lib/Manager.php
index ec10f0485..042911d05 100644
--- a/lib/Manager.php
+++ b/lib/Manager.php
@@ -89,8 +89,8 @@ class Manager {
public function getRoomsForParticipant($participant) {
$query = $this->db->getQueryBuilder();
$query->select('*')
- ->from('spreedme_rooms', 'r')
- ->leftJoin('r', 'spreedme_room_participants', 'p', $query->expr()->andX(
+ ->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')
))
@@ -121,12 +121,12 @@ class Manager {
public function getRoomForParticipant($roomId, $participant) {
$query = $this->db->getQueryBuilder();
$query->select('*')
- ->from('spreedme_rooms', 'r')
+ ->from('talk_rooms', 'r')
->where($query->expr()->eq('id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
if ($participant !== null) {
// Non guest user
- $query->leftJoin('r', 'spreedme_room_participants', 'p', $query->expr()->andX(
+ $query->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
$query->expr()->eq('p.userId', $query->createNamedParameter($participant)),
$query->expr()->eq('p.roomId', 'r.id')
))
@@ -165,13 +165,13 @@ class Manager {
public function getRoomForParticipantByToken($token, $participant) {
$query = $this->db->getQueryBuilder();
$query->select('*')
- ->from('spreedme_rooms', 'r')
+ ->from('talk_rooms', 'r')
->where($query->expr()->eq('token', $query->createNamedParameter($token)))
->setMaxResults(1);
if ($participant !== null) {
// Non guest user
- $query->leftJoin('r', 'spreedme_room_participants', 'p', $query->expr()->andX(
+ $query->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
$query->expr()->eq('p.userId', $query->createNamedParameter($participant)),
$query->expr()->eq('p.roomId', 'r.id')
));
@@ -209,7 +209,7 @@ class Manager {
public function getRoomById($roomId) {
$query = $this->db->getQueryBuilder();
$query->select('*')
- ->from('spreedme_rooms')
+ ->from('talk_rooms')
->where($query->expr()->eq('id', $query->createNamedParameter($roomId, IQueryBuilder::PARAM_INT)));
$result = $query->execute();
@@ -231,7 +231,7 @@ class Manager {
public function getRoomByToken($token) {
$query = $this->db->getQueryBuilder();
$query->select('*')
- ->from('spreedme_rooms')
+ ->from('talk_rooms')
->where($query->expr()->eq('token', $query->createNamedParameter($token)));
$result = $query->execute();
@@ -258,8 +258,8 @@ class Manager {
$query = $this->db->getQueryBuilder();
$query->select('*')
- ->from('spreedme_rooms', 'r')
- ->leftJoin('r', 'spreedme_room_participants', 'p', $query->expr()->andX(
+ ->from('talk_rooms', 'r')
+ ->leftJoin('r', 'talk_participants', 'p', $query->expr()->andX(
$query->expr()->eq('p.sessionId', $query->createNamedParameter($sessionId)),
$query->expr()->eq('p.roomId', 'r.id')
))
@@ -297,12 +297,12 @@ class Manager {
public function getOne2OneRoom($participant1, $participant2) {
$query = $this->db->getQueryBuilder();
$query->select('*')
- ->from('spreedme_rooms', 'r1')
- ->leftJoin('r1', 'spreedme_room_participants', 'p1', $query->expr()->andX(
+ ->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')
))
- ->leftJoin('r1', 'spreedme_room_participants', 'p2', $query->expr()->andX(
+ ->leftJoin('r1', 'talk_participants', 'p2', $query->expr()->andX(
$query->expr()->eq('p2.userId', $query->createNamedParameter($participant2)),
$query->expr()->eq('p2.roomId', 'r1.id')
))
@@ -352,7 +352,7 @@ class Manager {
$token = $this->getNewToken();
$query = $this->db->getQueryBuilder();
- $query->insert('spreedme_rooms')
+ $query->insert('talk_rooms')
->values(
[
'name' => $query->createNamedParameter($name),
@@ -377,7 +377,7 @@ class Manager {
$query = $this->db->getQueryBuilder();
$query->select('*')
- ->from('spreedme_room_participants')
+ ->from('talk_participants')
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)))
->andWhere($query->expr()->neq('sessionId', $query->createNamedParameter('0')))
->orderBy('lastPing', 'DESC')
@@ -406,7 +406,7 @@ class Manager {
// Delete all messages from or to the current user
$query = $this->db->getQueryBuilder();
$query->select('sessionId')
- ->from('spreedme_room_participants')
+ ->from('talk_participants')
->where($query->expr()->eq('userId', $query->createNamedParameter($userId)));
$result = $query->execute();
@@ -431,7 +431,7 @@ class Manager {
$query = $this->db->getQueryBuilder();
$query->select('id')
- ->from('spreedme_rooms')
+ ->from('talk_rooms')
->where($query->expr()->eq('token', $query->createParameter('token')));
$i = 0;
diff --git a/lib/Migration/EmptyNameInsteadOfRandom.php b/lib/Migration/Version2000Date20171026140256.php
index b21e6a958..8302fc9eb 100644
--- a/lib/Migration/EmptyNameInsteadOfRandom.php
+++ b/lib/Migration/Version2000Date20171026140256.php
@@ -20,18 +20,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-
namespace OCA\Spreed\Migration;
-
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
+use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-class EmptyNameInsteadOfRandom implements IRepairStep {
+/**
+ * Auto-generated migration step: Please modify to your needs!
+ */
+class Version2000Date20171026140256 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
@@ -54,24 +55,13 @@ class EmptyNameInsteadOfRandom implements IRepairStep {
}
/**
- * Returns the step's name
- *
- * @return string
- * @since 9.1.0
- */
- public function getName() {
- return 'Remove random call names';
- }
-
- /**
- * Run repair step.
- * Must throw exception on error.
- *
- * @since 9.1.0
* @param IOutput $output
- * @throws \Exception in case of failure
+ * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
+ * @param array $options
+ * @since 13.0.0
*/
- public function run(IOutput $output) {
+ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
+
if (!version_compare($this->config->getAppValue('spreed', 'installed_version', '0.0.0'), '1.1.4', '<')) {
return;
}
@@ -98,5 +88,6 @@ class EmptyNameInsteadOfRandom implements IRepairStep {
->execute();
}
$output->finishProgress();
+
}
}
diff --git a/lib/Migration/FillRoomTokens.php b/lib/Migration/Version2000Date20171026140257.php
index 34f5312d2..411e3c1c5 100644
--- a/lib/Migration/FillRoomTokens.php
+++ b/lib/Migration/Version2000Date20171026140257.php
@@ -20,19 +20,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-
namespace OCA\Spreed\Migration;
-
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
-use OCP\IGroupManager;
+use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
use OCP\Security\ISecureRandom;
-class FillRoomTokens implements IRepairStep {
+/**
+ * Auto-generated migration step: Please modify to your needs!
+ */
+class Version2000Date20171026140257 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
@@ -59,27 +59,12 @@ class FillRoomTokens implements IRepairStep {
}
/**
- * Returns the step's name
- *
- * @return string
- * @since 9.1.0
- */
- public function getName() {
- return 'Add room tokens';
- }
-
- /**
- * Run repair step.
- * Must throw exception on error.
- *
- * @since 9.1.0
* @param IOutput $output
- * @throws \Exception in case of failure
+ * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
+ * @param array $options
+ * @since 13.0.0
*/
- public function run(IOutput $output) {
- if (!version_compare($this->config->getAppValue('spreed', 'installed_version', '0.0.0'), '1.2.1', '<')) {
- return;
- }
+ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
$chars = str_replace(['l', '0', '1'], '', ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
$entropy = (int) $this->config->getAppValue('spreed', 'token_entropy', 8);
@@ -106,6 +91,7 @@ class FillRoomTokens implements IRepairStep {
->execute();
}
$output->finishProgress();
+
}
/**
diff --git a/lib/Migration/Version2001Date20171026134605.php b/lib/Migration/Version2001Date20171026134605.php
new file mode 100644
index 000000000..807ab68f5
--- /dev/null
+++ b/lib/Migration/Version2001Date20171026134605.php
@@ -0,0 +1,387 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 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\Exception\TableNotFoundException;
+use Doctrine\DBAL\Schema\Schema;
+use Doctrine\DBAL\Types\Type;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+class Version2001Date20171026134605 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();
+
+ if (!$schema->hasTable('talk_signaling')) {
+ $table = $schema->createTable('talk_signaling');
+
+ $table->addColumn('sender', Type::STRING, [
+ 'notnull' => true,
+ 'length' => 255,
+ ]);
+ $table->addColumn('recipient', Type::STRING, [
+ 'notnull' => true,
+ 'length' => 255,
+ ]);
+ $table->addColumn('message', Type::TEXT, [
+ 'notnull' => true,
+ ]);
+ $table->addColumn('timestamp', Type::INTEGER, [
+ 'notnull' => true,
+ 'length' => 11,
+ ]);
+
+ $table->addIndex(['recipient', 'timestamp'], 'ts_recipient_time');
+ }
+
+ if (!$schema->hasTable('talk_rooms')) {
+ $table = $schema->createTable('talk_rooms');
+
+ $table->addColumn('id', Type::INTEGER, [
+ 'autoincrement' => true,
+ 'notnull' => true,
+ 'length' => 11,
+ ]);
+ $table->addColumn('name', Type::STRING, [
+ 'notnull' => false,
+ 'length' => 255,
+ 'default' => '',
+ ]);
+ $table->addColumn('token', Type::STRING, [
+ 'notnull' => false,
+ 'length' => 32,
+ 'default' => '',
+ ]);
+ $table->addColumn('type', Type::INTEGER, [
+ 'notnull' => true,
+ 'length' => 11,
+ ]);
+ $table->addColumn('password', Type::STRING, [
+ 'notnull' => false,
+ 'length' => 255,
+ 'default' => '',
+ ]);
+ $table->addColumn('activeSince', Type::DATETIME, [
+ 'notnull' => false,
+ ]);
+ $table->addColumn('activeGuests', Type::INTEGER, [
+ 'notnull' => true,
+ 'length' => 4,
+ 'default' => 0,
+ 'unsigned' => true,
+ ]);
+
+ $table->setPrimaryKey(['id']);
+ $table->addUniqueIndex(['token'], 'tr_room_token');
+ }
+
+ if (!$schema->hasTable('talk_participants')) {
+ $table = $schema->createTable('talk_participants');
+
+ $table->addColumn('userId', Type::STRING, [
+ 'notnull' => false,
+ 'length' => 255,
+ ]);
+ $table->addColumn('roomId', Type::INTEGER, [
+ 'notnull' => true,
+ 'length' => 11,
+ ]);
+ $table->addColumn('lastPing', Type::INTEGER, [
+ 'notnull' => true,
+ 'length' => 11,
+ ]);
+ $table->addColumn('sessionId', Type::STRING, [
+ 'notnull' => true,
+ 'length' => 255,
+ ]);
+ $table->addColumn('participantType', Type::SMALLINT, [
+ 'notnull' => true,
+ 'length' => 6,
+ '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) {
+ $roomIdMap = $this->copyRooms();
+ $this->copyParticipants($roomIdMap);
+ $this->fixNotifications($roomIdMap);
+ $this->fixActivities($roomIdMap);
+ $this->fixActivityMails($roomIdMap);
+ }
+
+ /**
+ * @return int[]
+ */
+ protected function copyRooms() {
+ $roomIdMap = [];
+
+ $insert = $this->connection->getQueryBuilder();
+ $insert->insert('talk_rooms')
+ ->values([
+ 'name' => $insert->createParameter('name'),
+ 'token' => $insert->createParameter('token'),
+ 'type' => $insert->createParameter('type'),
+ 'password' => $insert->createParameter('password'),
+ ]);
+
+ $query = $this->connection->getQueryBuilder();
+ $query->select('*')
+ ->from('spreedme_rooms');
+
+ $result = $query->execute();
+ while ($row = $result->fetch()) {
+ $insert
+ ->setParameter('name', $row['name'])
+ ->setParameter('token', $row['token'])
+ ->setParameter('type', (int) $row['type'], IQueryBuilder::PARAM_INT)
+ ->setParameter('password', $row['password']);
+ $insert->execute();
+
+ $roomIdMap[(int)$row['id']] = $insert->getLastInsertId();
+ }
+ $result->closeCursor();
+
+ return $roomIdMap;
+ }
+
+ /**
+ * @param int[] $roomIdMap
+ */
+ protected function copyParticipants(array $roomIdMap) {
+
+ $insert = $this->connection->getQueryBuilder();
+ $insert->insert('talk_participants')
+ ->values([
+ 'userId' => $insert->createParameter('userId'),
+ 'roomId' => $insert->createParameter('roomId'),
+ 'lastPing' => $insert->createParameter('lastPing'),
+ 'sessionId' => $insert->createParameter('sessionId'),
+ 'participantType' => $insert->createParameter('participantType'),
+ ]);
+
+ $query = $this->connection->getQueryBuilder();
+ $query->select('*')
+ ->from('spreedme_room_participants');
+
+ $result = $query->execute();
+ while ($row = $result->fetch()) {
+ if (!isset($roomIdMap[(int) $row['roomId']])) {
+ continue;
+ }
+
+ $insert
+ ->setParameter('userId', $row['userId'])
+ ->setParameter('roomId', $roomIdMap[(int) $row['roomId']], IQueryBuilder::PARAM_INT)
+ ->setParameter('lastPing', (int) $row['lastPing'], IQueryBuilder::PARAM_INT)
+ ->setParameter('sessionId', $row['sessionId'])
+ ->setParameter('participantType', (int) $row['participantType'], IQueryBuilder::PARAM_INT)
+ ;
+ $insert->execute();
+ }
+ $result->closeCursor();