diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-03-14 04:59:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-14 04:59:47 +0100 |
commit | 26c2ec4081470c018a1ebe85dea6afeedc7c3e1c (patch) | |
tree | 0219c076d8499b272a283e0e83bf977f013035c2 /lib/Db | |
parent | 952e9dd4ed098428c1a9715485bfbe5bc3c5d804 (diff) | |
parent | 1bd6e3f44f93669ea87501601224de0c9613fb8e (diff) |
Merge pull request #352 from nextcloud/feature/noid/attachments
Incoming Attachments.
Diffstat (limited to 'lib/Db')
-rw-r--r-- | lib/Db/CacheDocumentsRequest.php | 45 | ||||
-rw-r--r-- | lib/Db/CoreRequestBuilder.php | 12 | ||||
-rw-r--r-- | lib/Db/HashtagsRequest.php | 4 | ||||
-rw-r--r-- | lib/Db/HashtagsRequestBuilder.php | 2 | ||||
-rw-r--r-- | lib/Db/NotesRequest.php | 13 | ||||
-rw-r--r-- | lib/Db/NotesRequestBuilder.php | 2 | ||||
-rw-r--r-- | lib/Db/StreamQueueRequestBuilder.php | 1 |
7 files changed, 68 insertions, 11 deletions
diff --git a/lib/Db/CacheDocumentsRequest.php b/lib/Db/CacheDocumentsRequest.php index f874feac..b095499a 100644 --- a/lib/Db/CacheDocumentsRequest.php +++ b/lib/Db/CacheDocumentsRequest.php @@ -56,6 +56,7 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder { ->setValue('mime_type', $qb->createNamedParameter($document->getMimeType())) ->setValue('error', $qb->createNamedParameter($document->getError())) ->setValue('local_copy', $qb->createNamedParameter($document->getLocalCopy())) + ->setValue('parent_id', $qb->createNamedParameter($document->getParentId())) ->setValue('public', $qb->createNamedParameter(($document->isPublic()) ? '1' : '0')) ->setValue( 'creation', @@ -69,6 +70,29 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder { /** + * insert cache about an Actor in database. + * + * @param Document $document + */ + public function update(Document $document) { + $qb = $this->getCacheDocumentsInsertSql(); + $qb->set('type', $qb->createNamedParameter($document->getType())) + ->set('url', $qb->createNamedParameter($document->getUrl())) + ->set('media_type', $qb->createNamedParameter($document->getMediaType())) + ->set('mime_type', $qb->createNamedParameter($document->getMimeType())) + ->set('error', $qb->createNamedParameter($document->getError())) + ->set('local_copy', $qb->createNamedParameter($document->getLocalCopy())) + ->set('parent_id', $qb->createNamedParameter($document->getParentId())) + ->set('public', $qb->createNamedParameter(($document->isPublic()) ? '1' : '0')) + ->set( + 'creation', + $qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE) + ); + $qb->execute(); + } + + + /** * @param Document $document */ public function initCaching(Document $document) { @@ -101,7 +125,7 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder { * @return Document * @throws CacheDocumentDoesNotExistException */ - public function getBySource(string $url) { + public function getByUrl(string $url) { $qb = $this->getCacheDocumentsSelectSql(); $this->limitToUrl($qb, $url); @@ -146,6 +170,24 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder { /** + * @param Document $item + * + * @return bool + */ + public function isDuplicate(Document $item): bool { + $qb = $this->getCacheDocumentsSelectSql(); + $this->limitToUrl($qb, $item->getUrl()); + $this->limitToParentId($qb, $item->getParentId()); + + $cursor = $qb->execute(); + $data = $cursor->fetch(); + $cursor->closeCursor(); + + return ($data !== false); + } + + + /** * @return Document[] * @throws Exception */ @@ -187,5 +229,6 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder { $qb->execute(); } + } diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index d6b25953..ac1956be 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -66,6 +66,7 @@ class CoreRequestBuilder { const TABLE_QUEUE_STREAM = 'social_queue_stream'; + /** @var IDBConnection */ protected $dbConnection; @@ -395,6 +396,17 @@ class CoreRequestBuilder { /** + * Limit the request to the parent_id + * + * @param IQueryBuilder $qb + * @param string $parentId + */ + protected function limitToParentId(IQueryBuilder &$qb, string $parentId) { + $this->limitToDBField($qb, 'parent_id', $parentId); + } + + + /** * @param IQueryBuilder $qb * @param int $since * @param int $limit diff --git a/lib/Db/HashtagsRequest.php b/lib/Db/HashtagsRequest.php index 7cf9c167..70f15282 100644 --- a/lib/Db/HashtagsRequest.php +++ b/lib/Db/HashtagsRequest.php @@ -32,11 +32,7 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; -use DateTime; -use OCA\Social\Exceptions\FollowDoesNotExistException; use OCA\Social\Exceptions\HashtagDoesNotExistException; -use OCA\Social\Model\ActivityPub\Activity\Follow; -use OCP\DB\QueryBuilder\IQueryBuilder; /** diff --git a/lib/Db/HashtagsRequestBuilder.php b/lib/Db/HashtagsRequestBuilder.php index b3f1b946..2297d280 100644 --- a/lib/Db/HashtagsRequestBuilder.php +++ b/lib/Db/HashtagsRequestBuilder.php @@ -32,8 +32,6 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; -use OCA\Social\Exceptions\InvalidResourceException; -use OCA\Social\Model\ActivityPub\Activity\Follow; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index db50bd58..4f44415a 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -32,6 +32,7 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Model\Cache; use DateTime; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCA\Social\Exceptions\NoteNotFoundException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Actor\Person; @@ -69,7 +70,12 @@ class NotesRequest extends NotesRequestBuilder { /** @var Note $stream */ $qb->setValue( 'hashtags', $qb->createNamedParameter(json_encode($stream->getHashtags())) - ); + ) + ->setValue( + 'attachments', $qb->createNamedParameter( + json_encode($stream->getAttachments(), JSON_UNESCAPED_SLASHES) + ) + ); } $qb->execute(); @@ -86,7 +92,10 @@ class NotesRequest extends NotesRequestBuilder { $this->limitToIdString($qb, $stream->getId()); - $qb->execute(); + try { + $qb->execute(); + } catch (UniqueConstraintViolationException $e) { + } } diff --git a/lib/Db/NotesRequestBuilder.php b/lib/Db/NotesRequestBuilder.php index bd9e3a7b..011c478a 100644 --- a/lib/Db/NotesRequestBuilder.php +++ b/lib/Db/NotesRequestBuilder.php @@ -84,7 +84,7 @@ class NotesRequestBuilder extends CoreRequestBuilder { $qb->selectDistinct('sn.id') ->addSelect( 'sn.type', 'sn.to', 'sn.to_array', 'sn.cc', 'sn.bcc', 'sn.content', - 'sn.summary', 'sn.published', 'sn.published_time', 'sn.cache', 'sn.object_id', + 'sn.summary', 'sn.attachments', 'sn.published', 'sn.published_time', 'sn.cache', 'sn.object_id', 'sn.attributed_to', 'sn.in_reply_to', 'sn.source', 'sn.local', 'sn.instances', 'sn.creation' ) diff --git a/lib/Db/StreamQueueRequestBuilder.php b/lib/Db/StreamQueueRequestBuilder.php index f4ac89a5..b66cec1c 100644 --- a/lib/Db/StreamQueueRequestBuilder.php +++ b/lib/Db/StreamQueueRequestBuilder.php @@ -31,7 +31,6 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; -use OCA\Social\Model\RequestQueue; use OCA\Social\Model\StreamQueue; use OCP\DB\QueryBuilder\IQueryBuilder; |