Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2020-04-02 12:34:21 +0300
committerGitHub <noreply@github.com>2020-04-02 12:34:21 +0300
commitbc6a5ef5c4431ca662424dbd1125e65e74b27fa8 (patch)
treea4ca41650699b5d9f9356eb4e7d5a5a10ab15ab2 /lib
parentc1368b86963b93a42ec98a856f8d307d922c8967 (diff)
parent1f5ba56235349ad811329b80cc1a2338dc8c79c7 (diff)
Merge pull request #19890 from nextcloud/enh/comments-reference-id
Add optional comments reference_id
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/private/Comments/Comment.php31
-rw-r--r--lib/private/Comments/Manager.php84
-rw-r--r--lib/private/DB/MissingColumnInformation.php43
-rw-r--r--lib/public/Comments/IComment.php17
-rw-r--r--lib/public/IDBConnection.php2
7 files changed, 159 insertions, 22 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 4cf77a34a5c..9a1f5befb4d 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -738,6 +738,7 @@ return array(
'OC\\Core\\Command\\Config\\System\\DeleteConfig' => $baseDir . '/core/Command/Config/System/DeleteConfig.php',
'OC\\Core\\Command\\Config\\System\\GetConfig' => $baseDir . '/core/Command/Config/System/GetConfig.php',
'OC\\Core\\Command\\Config\\System\\SetConfig' => $baseDir . '/core/Command/Config/System/SetConfig.php',
+ 'OC\\Core\\Command\\Db\\AddMissingColumns' => $baseDir . '/core/Command/Db/AddMissingColumns.php',
'OC\\Core\\Command\\Db\\AddMissingIndices' => $baseDir . '/core/Command/Db/AddMissingIndices.php',
'OC\\Core\\Command\\Db\\ConvertFilecacheBigInt' => $baseDir . '/core/Command/Db/ConvertFilecacheBigInt.php',
'OC\\Core\\Command\\Db\\ConvertMysqlToMB4' => $baseDir . '/core/Command/Db/ConvertMysqlToMB4.php',
@@ -873,6 +874,7 @@ return array(
'OC\\DB\\MigrationException' => $baseDir . '/lib/private/DB/MigrationException.php',
'OC\\DB\\MigrationService' => $baseDir . '/lib/private/DB/MigrationService.php',
'OC\\DB\\Migrator' => $baseDir . '/lib/private/DB/Migrator.php',
+ 'OC\\DB\\MissingColumnInformation' => $baseDir . '/lib/private/DB/MissingColumnInformation.php',
'OC\\DB\\MissingIndexInformation' => $baseDir . '/lib/private/DB/MissingIndexInformation.php',
'OC\\DB\\MySQLMigrator' => $baseDir . '/lib/private/DB/MySQLMigrator.php',
'OC\\DB\\MySqlTools' => $baseDir . '/lib/private/DB/MySqlTools.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index c3a1a6a6264..318888bd434 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -767,6 +767,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Command\\Config\\System\\DeleteConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/DeleteConfig.php',
'OC\\Core\\Command\\Config\\System\\GetConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/GetConfig.php',
'OC\\Core\\Command\\Config\\System\\SetConfig' => __DIR__ . '/../../..' . '/core/Command/Config/System/SetConfig.php',
+ 'OC\\Core\\Command\\Db\\AddMissingColumns' => __DIR__ . '/../../..' . '/core/Command/Db/AddMissingColumns.php',
'OC\\Core\\Command\\Db\\AddMissingIndices' => __DIR__ . '/../../..' . '/core/Command/Db/AddMissingIndices.php',
'OC\\Core\\Command\\Db\\ConvertFilecacheBigInt' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertFilecacheBigInt.php',
'OC\\Core\\Command\\Db\\ConvertMysqlToMB4' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertMysqlToMB4.php',
@@ -902,6 +903,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\DB\\MigrationException' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationException.php',
'OC\\DB\\MigrationService' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationService.php',
'OC\\DB\\Migrator' => __DIR__ . '/../../..' . '/lib/private/DB/Migrator.php',
+ 'OC\\DB\\MissingColumnInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingColumnInformation.php',
'OC\\DB\\MissingIndexInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingIndexInformation.php',
'OC\\DB\\MySQLMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/MySQLMigrator.php',
'OC\\DB\\MySqlTools' => __DIR__ . '/../../..' . '/lib/private/DB/MySqlTools.php',
diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php
index 71687c7a609..3b4a523b884 100644
--- a/lib/private/Comments/Comment.php
+++ b/lib/private/Comments/Comment.php
@@ -42,6 +42,7 @@ class Comment implements IComment {
'actorId' => '',
'objectType' => '',
'objectId' => '',
+ 'referenceId' => null,
'creationDT' => null,
'latestChildDT' => null,
];
@@ -396,6 +397,36 @@ class Comment implements IComment {
}
/**
+ * returns the reference id of the comment
+ *
+ * @return string|null
+ * @since 19.0.0
+ */
+ public function getReferenceId(): ?string {
+ return $this->data['referenceId'];
+ }
+
+ /**
+ * sets (overwrites) the reference id of the comment
+ *
+ * @param string $referenceId e.g. sha256 hash sum
+ * @return IComment
+ * @since 19.0.0
+ */
+ public function setReferenceId(?string $referenceId): IComment {
+ if ($referenceId === null) {
+ $this->data['referenceId'] = $referenceId;
+ } else {
+ $referenceId = trim($referenceId);
+ if ($referenceId === '') {
+ throw new \InvalidArgumentException('Non empty string expected.');
+ }
+ $this->data['referenceId'] = $referenceId;
+ }
+ return $this;
+ }
+
+ /**
* sets the comment data based on an array with keys as taken from the
* database.
*
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index f1c72243597..d04f3f965b3 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -29,6 +29,7 @@
namespace OC\Comments;
use Doctrine\DBAL\Exception\DriverException;
+use Doctrine\DBAL\Exception\InvalidFieldNameException;
use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsEventHandler;
@@ -96,6 +97,7 @@ class Manager implements ICommentsManager {
$data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']);
}
$data['children_count'] = (int)$data['children_count'];
+ $data['reference_id'] = $data['reference_id'] ?? null;
return $data;
}
@@ -744,23 +746,46 @@ class Manager implements ICommentsManager {
* @param IComment $comment
* @return bool
*/
- protected function insert(IComment &$comment) {
+ protected function insert(IComment $comment): bool {
+
+ try {
+ $result = $this->insertQuery($comment, true);
+ } catch (InvalidFieldNameException $e) {
+ // The reference id field was only added in Nextcloud 19.
+ // In order to not cause too long waiting times on the update,
+ // it was decided to only add it lazy, as it is also not a critical
+ // feature, but only helps to have a better experience while commenting.
+ // So in case the reference_id field is missing,
+ // we simply save the comment without that field.
+ $result = $this->insertQuery($comment, false);
+ }
+
+ return $result;
+ }
+
+ protected function insertQuery(IComment $comment, bool $tryWritingReferenceId): bool {
$qb = $this->dbConn->getQueryBuilder();
- $affectedRows = $qb
- ->insert('comments')
- ->values([
- 'parent_id' => $qb->createNamedParameter($comment->getParentId()),
- 'topmost_parent_id' => $qb->createNamedParameter($comment->getTopmostParentId()),
- 'children_count' => $qb->createNamedParameter($comment->getChildrenCount()),
- 'actor_type' => $qb->createNamedParameter($comment->getActorType()),
- 'actor_id' => $qb->createNamedParameter($comment->getActorId()),
- 'message' => $qb->createNamedParameter($comment->getMessage()),
- 'verb' => $qb->createNamedParameter($comment->getVerb()),
- 'creation_timestamp' => $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime'),
- 'latest_child_timestamp' => $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'),
- 'object_type' => $qb->createNamedParameter($comment->getObjectType()),
- 'object_id' => $qb->createNamedParameter($comment->getObjectId()),
- ])
+
+ $values = [
+ 'parent_id' => $qb->createNamedParameter($comment->getParentId()),
+ 'topmost_parent_id' => $qb->createNamedParameter($comment->getTopmostParentId()),
+ 'children_count' => $qb->createNamedParameter($comment->getChildrenCount()),
+ 'actor_type' => $qb->createNamedParameter($comment->getActorType()),
+ 'actor_id' => $qb->createNamedParameter($comment->getActorId()),
+ 'message' => $qb->createNamedParameter($comment->getMessage()),
+ 'verb' => $qb->createNamedParameter($comment->getVerb()),
+ 'creation_timestamp' => $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime'),
+ 'latest_child_timestamp' => $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'),
+ 'object_type' => $qb->createNamedParameter($comment->getObjectType()),
+ 'object_id' => $qb->createNamedParameter($comment->getObjectId()),
+ ];
+
+ if ($tryWritingReferenceId) {
+ $values['reference_id'] = $qb->createNamedParameter($comment->getReferenceId());
+ }
+
+ $affectedRows = $qb->insert('comments')
+ ->values($values)
->execute();
if ($affectedRows > 0) {
@@ -785,8 +810,21 @@ class Manager implements ICommentsManager {
$this->sendEvent(CommentsEvent::EVENT_PRE_UPDATE, $this->get($comment->getId()));
$this->uncache($comment->getId());
+ try {
+ $result = $this->updateQuery($comment, true);
+ } catch (InvalidFieldNameException $e) {
+ // See function insert() for explanation
+ $result = $this->updateQuery($comment, false);
+ }
+
+ $this->sendEvent(CommentsEvent::EVENT_UPDATE, $comment);
+
+ return $result;
+ }
+
+ protected function updateQuery(IComment $comment, bool $tryWritingReferenceId): bool {
$qb = $this->dbConn->getQueryBuilder();
- $affectedRows = $qb
+ $qb
->update('comments')
->set('parent_id', $qb->createNamedParameter($comment->getParentId()))
->set('topmost_parent_id', $qb->createNamedParameter($comment->getTopmostParentId()))
@@ -798,17 +836,19 @@ class Manager implements ICommentsManager {
->set('creation_timestamp', $qb->createNamedParameter($comment->getCreationDateTime(), 'datetime'))
->set('latest_child_timestamp', $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'))
->set('object_type', $qb->createNamedParameter($comment->getObjectType()))
- ->set('object_id', $qb->createNamedParameter($comment->getObjectId()))
- ->where($qb->expr()->eq('id', $qb->createParameter('id')))
- ->setParameter('id', $comment->getId())
+ ->set('object_id', $qb->createNamedParameter($comment->getObjectId()));
+
+ if ($tryWritingReferenceId) {
+ $qb->set('reference_id', $qb->createNamedParameter($comment->getReferenceId()));
+ }
+
+ $affectedRows = $qb->where($qb->expr()->eq('id', $qb->createNamedParameter($comment->getId())))
->execute();
if ($affectedRows === 0) {
throw new NotFoundException('Comment to update does ceased to exist');
}
- $this->sendEvent(CommentsEvent::EVENT_UPDATE, $comment);
-
return $affectedRows > 0;
}
diff --git a/lib/private/DB/MissingColumnInformation.php b/lib/private/DB/MissingColumnInformation.php
new file mode 100644
index 00000000000..bcf585848fd
--- /dev/null
+++ b/lib/private/DB/MissingColumnInformation.php
@@ -0,0 +1,43 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020 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 OC\DB;
+
+class MissingColumnInformation {
+
+ private $listOfMissingColumns = [];
+
+ public function addHintForMissingColumn(string $tableName, string $columnName): void {
+ $this->listOfMissingColumns[] = [
+ 'tableName' => $tableName,
+ 'columnName' => $columnName,
+ ];
+ }
+
+ public function getListOfMissingColumns(): array {
+ return $this->listOfMissingColumns;
+ }
+}
diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php
index aac68a4036b..b98a015a30e 100644
--- a/lib/public/Comments/IComment.php
+++ b/lib/public/Comments/IComment.php
@@ -263,4 +263,21 @@ interface IComment {
*/
public function setObject($objectType, $objectId);
+ /**
+ * returns the reference id of the comment
+ *
+ * @return string|null
+ * @since 19.0.0
+ */
+ public function getReferenceId(): ?string;
+
+ /**
+ * sets (overwrites) the reference id of the comment
+ *
+ * @param string|null $referenceId e.g. sha256 hash sum
+ * @return IComment
+ * @since 19.0.0
+ */
+ public function setReferenceId(?string $referenceId): IComment;
+
}
diff --git a/lib/public/IDBConnection.php b/lib/public/IDBConnection.php
index 0cc29d3be46..a7aa9d448f1 100644
--- a/lib/public/IDBConnection.php
+++ b/lib/public/IDBConnection.php
@@ -51,6 +51,8 @@ interface IDBConnection {
const ADD_MISSING_INDEXES_EVENT = self::class . '::ADD_MISSING_INDEXES';
const CHECK_MISSING_INDEXES_EVENT = self::class . '::CHECK_MISSING_INDEXES';
+ const ADD_MISSING_COLUMNS_EVENT = self::class . '::ADD_MISSING_COLUMNS';
+ const CHECK_MISSING_COLUMNS_EVENT = self::class . '::CHECK_MISSING_COLUMNS';
/**
* Gets the QueryBuilder for the connection.