summaryrefslogtreecommitdiffstats
path: root/lib/Db/FollowsRequest.php
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-11-16 10:48:31 -0100
committerMaxence Lange <maxence@artificial-owl.com>2018-11-16 10:48:31 -0100
commitee7e735722b7b085dc70eaab7bc7ef423a850bd8 (patch)
tree882ae62a9d8d8df7c29bd80c91aaf7d2486daaf0 /lib/Db/FollowsRequest.php
parent31867cfbb74123ce59f9eb0b474d03f93dd8d296 (diff)
saving follows in database
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Db/FollowsRequest.php')
-rw-r--r--lib/Db/FollowsRequest.php55
1 files changed, 32 insertions, 23 deletions
diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php
index 8b3ee499..6dd84ac1 100644
--- a/lib/Db/FollowsRequest.php
+++ b/lib/Db/FollowsRequest.php
@@ -32,7 +32,9 @@ namespace OCA\Social\Db;
use Exception;
+use OCA\Social\Exceptions\FollowDoesNotExistException;
use OCA\Social\Model\ActivityPub\Follow;
+use OCA\Social\Model\ActivityPub\Person;
/**
@@ -47,42 +49,49 @@ class FollowsRequest extends FollowsRequestBuilder {
* Insert a new Note in the database.
*
* @param Follow $follow
- *
- * @return int
- * @throws Exception
*/
- public function save(Follow $follow): int {
+ public function save(Follow $follow) {
+ $qb = $this->getFollowsInsertSql();
+ $qb->setValue('id', $qb->createNamedParameter($follow->getId()))
+ ->setValue('actor_id', $qb->createNamedParameter($follow->getActorId()))
+ ->setValue('object_id', $qb->createNamedParameter($follow->getObjectId()));
+
+ $qb->execute();
+ }
- try {
- $qb = $this->getFollowsInsertSql();
- $qb->setValue('id', $qb->createNamedParameter($follow->getId()))
- ->setValue('actor_id', $qb->createNamedParameter($follow->getActorId()))
- ->setValue('object_id', $qb->createNamedParameter($follow->getObjectId()));
- $qb->execute();
+ /**
+ * @param Person $actor
+ * @param Person $remote
+ *
+ * @return Follow
+ * @throws FollowDoesNotExistException
+ */
+ public function getByPersons(Person $actor, Person $remote) {
+ $qb = $this->getFollowsSelectSql();
+ $this->limitToActorId($qb, $actor->getId());
+ $this->limitToObjectId($qb, $remote->getId());
- return $qb->getLastInsertId();
- } catch (Exception $e) {
- throw $e;
+ $cursor = $qb->execute();
+ $data = $cursor->fetch();
+ $cursor->closeCursor();
+
+ if ($data === false) {
+ throw new FollowDoesNotExistException();
}
+
+ return $this->parseFollowsSelectSql($data);
}
/**
* @param Follow $follow
- *
- * @throws Exception
*/
public function delete(Follow $follow) {
+ $qb = $this->getFollowsDeleteSql();
+ $this->limitToIdString($qb, $follow->getId());
- try {
- $qb = $this->getFollowsDeleteSql();
- $this->limitToIdString($qb, $follow->getId());
-
- $qb->execute();
- } catch (Exception $e) {
- throw $e;
- }
+ $qb->execute();
}