From 29a72c3ededd44ffb44d5bcb02763aabd1f041ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 12 Jul 2018 00:06:27 +0200 Subject: [PATCH] Add columns "object_type" and "object_id" to table "talk_rooms" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that in Oracle string fields have to be nullable to be able to set empty strings on them. As the table "comments" also has columns named "object_type" and "object_id" they must be namespaced when the last comment is included in the room information; otherwise the created comment object would have the object type and id from the room instead of from the comment. Signed-off-by: Daniel Calviño Sánchez Signed-off-by: Joas Schilling --- appinfo/info.xml | 2 +- lib/Manager.php | 6 +- .../Version3003Date20180720162342.php | 55 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 lib/Migration/Version3003Date20180720162342.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 3fc38a2429..c5d3bedb36 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -17,7 +17,7 @@ And in the works for the [coming versions](https://github.com/nextcloud/spreed/m ]]> - 3.99.8 + 3.99.9 agpl Daniel Calviño Sánchez diff --git a/lib/Manager.php b/lib/Manager.php index c15491b5eb..8235a759cd 100644 --- a/lib/Manager.php +++ b/lib/Manager.php @@ -98,6 +98,8 @@ class Manager { if (!empty($row['comment_id'])) { $lastMessage = $this->commentsManager->getCommentFromData(array_merge($row, [ 'id' => $row['comment_id'], + 'object_type' => $row['comment_object_type'], + 'object_id' => $row['comment_object_id'], 'parent_id' => '', 'topmost_parent_id' => '', 'latest_child_timestamp' => null, @@ -140,7 +142,9 @@ class Manager { if ($includeLastMessage) { $query->leftJoin('r','comments', 'c', $query->expr()->eq('r.last_message', 'c.id')); $query->selectAlias('c.id', 'comment_id'); - $query->addSelect('c.actor_id', 'c.actor_type', 'c.message', 'c.creation_timestamp'); + $query->addSelect('c.actor_id', 'c.actor_type', 'c.message', 'c.creation_timestamp', 'c.object_type', 'c.object_id'); + $query->selectAlias('c.object_type', 'comment_object_type'); + $query->selectAlias('c.object_id', 'comment_object_id'); } $result = $query->execute(); diff --git a/lib/Migration/Version3003Date20180720162342.php b/lib/Migration/Version3003Date20180720162342.php new file mode 100644 index 0000000000..8abde02ad0 --- /dev/null +++ b/lib/Migration/Version3003Date20180720162342.php @@ -0,0 +1,55 @@ +. + * + */ + +namespace OCA\Spreed\Migration; + +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +class Version3003Date20180720162342 extends SimpleMigrationStep { + + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('talk_rooms'); + + if (!$table->hasColumn('object_type')) { + $table->addColumn('object_type', Type::STRING, [ + 'notnull' => false, + 'length' => 64, + 'default' => '', + ]); + $table->addColumn('object_id', Type::STRING, [ + 'notnull' => false, + 'length' => 64, + 'default' => '', + ]); + } + + return $schema; + } +}