summaryrefslogtreecommitdiffstats
path: root/lib/private/comments/manager.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-02-05 10:45:16 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2016-02-05 11:30:53 +0100
commite86dcdacc8b1167a461b399c39c8aaf556ee4a7c (patch)
tree2f0da80b5e4c9180ba98506cd44cb8ff18e0fe84 /lib/private/comments/manager.php
parent0ed2108b7f3a8537643b89823d628e4db18ecf61 (diff)
downloadnextcloud-server-e86dcdacc8b1167a461b399c39c8aaf556ee4a7c.tar.gz
nextcloud-server-e86dcdacc8b1167a461b399c39c8aaf556ee4a7c.zip
Dispatch events when adding, updating and deleting comments
Diffstat (limited to 'lib/private/comments/manager.php')
-rw-r--r--lib/private/comments/manager.php48
1 files changed, 43 insertions, 5 deletions
diff --git a/lib/private/comments/manager.php b/lib/private/comments/manager.php
index 0cacc1cce71..21baeb6fee3 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;
}
/**
@@ -415,6 +430,19 @@ 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;
+ }
+ if ($comment instanceof IComment) {
+ $this->dispatcher->dispatch(CommentsEvent::EVENT_DELETE, new CommentsEvent(
+ CommentsEvent::EVENT_DELETE,
+ $comment
+ ));
+ }
+
$qb = $this->dbConn->getQueryBuilder();
$query = $qb->delete('comments')
->where($qb->expr()->eq('id', $qb->createParameter('id')))
@@ -431,7 +459,7 @@ class Manager implements ICommentsManager {
}
/**
- * 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 +521,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 +559,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;
}