summaryrefslogtreecommitdiffstats
path: root/lib/private/comments/manager.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/comments/manager.php')
-rw-r--r--lib/private/comments/manager.php56
1 files changed, 48 insertions, 8 deletions
diff --git a/lib/private/comments/manager.php b/lib/private/comments/manager.php
index 28bd3b0916a..36b2d9d08b8 100644
--- a/lib/private/comments/manager.php
+++ b/lib/private/comments/manager.php
@@ -21,6 +21,7 @@
namespace OC\Comments;
use Doctrine\DBAL\Exception\DriverException;
+use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
@@ -28,6 +29,7 @@ use OCP\IDBConnection;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Manager implements ICommentsManager {
@@ -37,20 +39,33 @@ class Manager implements ICommentsManager {
/** @var ILogger */
protected $logger;
- /** @var IComment[] */
- protected $commentsCache = [];
-
/** @var IConfig */
protected $config;
+ /** @var EventDispatcherInterface */
+ protected $dispatcher;
+
+ /** @var IComment[] */
+ protected $commentsCache = [];
+
+ /**
+ * Manager constructor.
+ *
+ * @param IDBConnection $dbConn
+ * @param ILogger $logger
+ * @param IConfig $config
+ * @param EventDispatcherInterface $dispatcher
+ */
public function __construct(
IDBConnection $dbConn,
ILogger $logger,
- IConfig $config
+ IConfig $config,
+ EventDispatcherInterface $dispatcher
) {
$this->dbConn = $dbConn;
$this->logger = $logger;
$this->config = $config;
+ $this->dispatcher = $dispatcher;
}
/**
@@ -384,7 +399,7 @@ class Manager implements ICommentsManager {
* saved in the used data storage. Use save() after setting other fields
* of the comment (e.g. message or verb).
*
- * @param string $actorType the actor type (e.g. 'user')
+ * @param string $actorType the actor type (e.g. 'users')
* @param string $actorId a user id
* @param string $objectType the object type the comment is attached to
* @param string $objectId the object id the comment is attached to
@@ -415,6 +430,13 @@ class Manager implements ICommentsManager {
throw new \InvalidArgumentException('Parameter must be string');
}
+ try {
+ $comment = $this->get($id);
+ } catch (\Exception $e) {
+ // Ignore exceptions, we just don't fire a hook then
+ $comment = null;
+ }
+
$qb = $this->dbConn->getQueryBuilder();
$query = $qb->delete('comments')
->where($qb->expr()->eq('id', $qb->createParameter('id')))
@@ -427,11 +449,19 @@ class Manager implements ICommentsManager {
$this->logger->logException($e, ['app' => 'core_comments']);
return false;
}
+
+ if ($affectedRows > 0 && $comment instanceof IComment) {
+ $this->dispatcher->dispatch(CommentsEvent::EVENT_DELETE, new CommentsEvent(
+ CommentsEvent::EVENT_DELETE,
+ $comment
+ ));
+ }
+
return ($affectedRows > 0);
}
/**
- * saves the comment permanently and returns it
+ * saves the comment permanently
*
* if the supplied comment has an empty ID, a new entry comment will be
* saved and the instance updated with the new ID.
@@ -493,6 +523,11 @@ class Manager implements ICommentsManager {
$comment->setId(strval($qb->getLastInsertId()));
}
+ $this->dispatcher->dispatch(CommentsEvent::EVENT_ADD, new CommentsEvent(
+ CommentsEvent::EVENT_ADD,
+ $comment
+ ));
+
return $affectedRows > 0;
}
@@ -526,6 +561,11 @@ class Manager implements ICommentsManager {
throw new NotFoundException('Comment to update does ceased to exist');
}
+ $this->dispatcher->dispatch(CommentsEvent::EVENT_UPDATE, new CommentsEvent(
+ CommentsEvent::EVENT_UPDATE,
+ $comment
+ ));
+
return $affectedRows > 0;
}
@@ -533,7 +573,7 @@ class Manager implements ICommentsManager {
* removes references to specific actor (e.g. on user delete) of a comment.
* The comment itself must not get lost/deleted.
*
- * @param string $actorType the actor type (e.g. 'user')
+ * @param string $actorType the actor type (e.g. 'users')
* @param string $actorId a user id
* @return boolean
* @since 9.0.0
@@ -560,7 +600,7 @@ class Manager implements ICommentsManager {
/**
* deletes all comments made of a specific object (e.g. on file delete)
*
- * @param string $objectType the object type (e.g. 'file')
+ * @param string $objectType the object type (e.g. 'files')
* @param string $objectId e.g. the file id
* @return boolean
* @since 9.0.0