]> source.dussan.org Git - nextcloud-server.git/commitdiff
Disable reactions if database don't support utf8mb4
authorVitor Mattos <vitor@php.rio>
Thu, 13 Jan 2022 14:08:52 +0000 (11:08 -0300)
committerVitor Mattos <vitor@php.rio>
Fri, 21 Jan 2022 11:39:37 +0000 (08:39 -0300)
Fix column size

Signed-off-by: Vitor Mattos <vitor@php.rio>
lib/private/Comments/Manager.php
tests/lib/Comments/ManagerTest.php

index 5c7e532f177176eada82323c855f8f17183caf69..534de6a937bc510524c7ef2bfd43223771fe108f 100644 (file)
@@ -102,7 +102,9 @@ class Manager implements ICommentsManager {
                }
                $data['children_count'] = (int)$data['children_count'];
                $data['reference_id'] = $data['reference_id'] ?? null;
-               $data['reactions'] = json_decode($data['reactions'], true);
+               if ($this->supportReactions()) {
+                       $data['reactions'] = json_decode($data['reactions'], true);
+               }
                return $data;
        }
 
@@ -910,6 +912,9 @@ class Manager implements ICommentsManager {
        }
 
        private function deleteReaction(IComment $reaction): void {
+               if (!$this->supportReactions()) {
+                       return;
+               }
                $qb = $this->dbConn->getQueryBuilder();
                $qb->delete('reactions')
                        ->where($qb->expr()->eq('parent_id', $qb->createNamedParameter($reaction->getParentId())))
@@ -930,6 +935,9 @@ class Manager implements ICommentsManager {
         * @since 24.0.0
         */
        public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment {
+               if (!$this->supportReactions()) {
+                       throw new NotFoundException('The database does not support reactions');
+               }
                $qb = $this->dbConn->getQueryBuilder();
                $messageId = $qb
                        ->select('message_id')
@@ -955,6 +963,7 @@ class Manager implements ICommentsManager {
         * @since 24.0.0
         */
        public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): ?array {
+               $this->throwIfNotSupportReactions();
                $qb = $this->dbConn->getQueryBuilder();
                $result = $qb
                        ->select('message_id')
@@ -975,6 +984,10 @@ class Manager implements ICommentsManager {
                return $comments;
        }
 
+       public function supportReactions(): bool {
+               return $this->dbConn->supports4ByteText();
+       }
+
        /**
         * Retrieve all reactions of a message
         *
@@ -984,6 +997,9 @@ class Manager implements ICommentsManager {
         * @since 24.0.0
         */
        public function retrieveAllReactions(int $parentId): array {
+               if (!$this->supportReactions()) {
+                       return [];
+               }
                $qb = $this->dbConn->getQueryBuilder();
                $result = $qb
                        ->select('message_id')
@@ -1124,6 +1140,9 @@ class Manager implements ICommentsManager {
        }
 
        private function addReaction(IComment $reaction): void {
+               if (!$this->supportReactions()) {
+                       return;
+               }
                // Prevent violate constraint
                $qb = $this->dbConn->getQueryBuilder();
                $qb->select($qb->func()->count('*'))
index e588630a48399891228092d8267a1f50f271649f..2a837a02abf39f59d7386d7693a442b33d57ba45 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace Test\Comments;
 
-use Doctrine\DBAL\Platforms\MySQLPlatform;
 use OC\Comments\Comment;
 use OC\Comments\Manager;
 use OCP\AppFramework\Utility\ITimeFactory;
@@ -876,9 +875,7 @@ class ManagerTest extends TestCase {
        }
 
        private function skipIfNotSupport4ByteUTF() {
-               // 4 byte UTF doesn't work on mysql
-               $params = \OC::$server->get(\OC\DB\Connection::class)->getParams();
-               if (\OC::$server->getDatabaseConnection()->getDatabasePlatform() instanceof MySQLPlatform && $params['charset'] !== 'utf8mb4') {
+               if (!$this->getManager()->supportReactions()) {
                        $this->markTestSkipped('MySQL doesn\'t support 4 byte UTF-8');
                }
        }