summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-07-11 22:43:51 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-07-11 22:43:51 -0100
commitb8f3525600c6d47d088846083e301d233d0fd4cb (patch)
tree54f76217dc8ad6600aa6017dce71bad6dce1f17f /lib
parent623facfb04972f97030a64f9e6c1b63a1c2a3b9c (diff)
update cache in stream
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/QueueProcess.php3
-rw-r--r--lib/Controller/LocalController.php1
-rw-r--r--lib/Db/CacheDocumentsRequestBuilder.php4
-rw-r--r--lib/Db/StreamRequest.php53
-rw-r--r--lib/Service/CurlService.php4
-rw-r--r--lib/Service/DocumentService.php14
6 files changed, 70 insertions, 9 deletions
diff --git a/lib/Command/QueueProcess.php b/lib/Command/QueueProcess.php
index 69006183..ef36d8e0 100644
--- a/lib/Command/QueueProcess.php
+++ b/lib/Command/QueueProcess.php
@@ -109,6 +109,9 @@ class QueueProcess extends Base {
}
+ /**
+ * @param OutputInterface $output
+ */
private function processRequestQueue(OutputInterface $output) {
$total = 0;
$requests = $this->requestQueueService->getRequestStandby($total);
diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php
index 0d2a8ca9..69294bf8 100644
--- a/lib/Controller/LocalController.php
+++ b/lib/Controller/LocalController.php
@@ -380,6 +380,7 @@ class LocalController extends Controller {
/**
* @NoAdminRequired
+ * @NoCSRFRequired
*
* @param int $since
* @param int $limit
diff --git a/lib/Db/CacheDocumentsRequestBuilder.php b/lib/Db/CacheDocumentsRequestBuilder.php
index 300f5066..a75c4a0a 100644
--- a/lib/Db/CacheDocumentsRequestBuilder.php
+++ b/lib/Db/CacheDocumentsRequestBuilder.php
@@ -76,8 +76,8 @@ class CacheDocumentsRequestBuilder extends CoreRequestBuilder {
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->select(
- 'cd.id', 'cd.type', 'cd.media_type', 'cd.mime_type', 'cd.url', 'cd.local_copy',
- 'cd.public', 'cd.error', 'cd.creation', 'cd.caching'
+ 'cd.id', 'cd.type', 'cd.parent_id', 'cd.media_type', 'cd.mime_type', 'cd.url',
+ 'cd.local_copy', 'cd.public', 'cd.error', 'cd.creation', 'cd.caching'
)
->from(self::TABLE_CACHE_DOCUMENTS, 'cd');
diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php
index 34081d82..737dfd3d 100644
--- a/lib/Db/StreamRequest.php
+++ b/lib/Db/StreamRequest.php
@@ -43,6 +43,7 @@ use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
+use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Service\ConfigService;
@@ -132,6 +133,54 @@ class StreamRequest extends StreamRequestBuilder {
/**
+ * @param Document $document
+ */
+ public function updateAttachments(Document $document) {
+ $qb = $this->getStreamSelectSql();
+ $this->limitToIdString($qb, $document->getParentId());
+
+ $cursor = $qb->execute();
+ $data = $cursor->fetch();
+ $cursor->closeCursor();
+
+ if ($data === false) {
+ return;
+ }
+
+ $new = $this->updateAttachmentInList($document, $this->getArray('attachments', $data, []));
+
+ $qb = $this->getStreamUpdateSql();
+ $qb->set(
+ 'attachments', $qb->createNamedParameter(json_encode($new, JSON_UNESCAPED_SLASHES))
+ );
+ $this->limitToIdString($qb, $document->getParentId());
+
+ $qb->execute();
+ }
+
+ /**
+ * @param Document $document
+ * @param array $attachments
+ *
+ * @return array
+ */
+ private function updateAttachmentInList(Document $document, array $attachments): array {
+ $new = [];
+ foreach ($attachments as $attachment) {
+ $tmp = new Document();
+ $tmp->importFromDatabase($attachment);
+ if ($tmp->getId() === $document->getId()) {
+ $new[] = $document;
+ } else {
+ $new[] = $tmp;
+ }
+ }
+
+ return $new;
+ }
+
+
+ /**
* @param string $itemId
* @param string $to
*/
@@ -223,7 +272,8 @@ class StreamRequest extends StreamRequestBuilder {
* @throws SocialAppConfigException
* @throws StreamNotFoundException
*/
- public function getStreamByObjectId(string $objectId, string $type, string $subType = ''): Stream {
+ public function getStreamByObjectId(string $objectId, string $type, string $subType = ''
+ ): Stream {
if ($objectId === '') {
throw new StreamNotFoundException('missing objectId');
};
@@ -702,6 +752,5 @@ class StreamRequest extends StreamRequestBuilder {
$qb->andWhere($filter);
}
-
}
diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php
index 90017e2c..47d2f068 100644
--- a/lib/Service/CurlService.php
+++ b/lib/Service/CurlService.php
@@ -502,8 +502,8 @@ class CurlService {
$this->parseRequestResultCurl($curl, $request);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
- $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
- $request->setContentType(($contentType === null) ? '' : $contentType);
+ $type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
+ $request->setContentType((is_null($type) || is_bool($type)) ? '' : $type);
$request->setResultCode($code);
$this->parseRequestResultCode301($code, $request);
diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php
index d860a018..4fedac0c 100644
--- a/lib/Service/DocumentService.php
+++ b/lib/Service/DocumentService.php
@@ -36,9 +36,11 @@ use Exception;
use OCA\Social\AP;
use OCA\Social\Db\ActorsRequest;
use OCA\Social\Db\CacheDocumentsRequest;
+use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\CacheContentException;
use OCA\Social\Exceptions\CacheContentMimeTypeException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
+use OCA\Social\Exceptions\ItemAlreadyExistsException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
@@ -74,6 +76,8 @@ class DocumentService {
/** @var ActorsRequest */
private $actorRequest;
+ /** @var StreamRequest */
+ private $streamRequest;
/** @var CacheDocumentService */
private $cacheService;
@@ -91,19 +95,20 @@ class DocumentService {
* @param IUrlGenerator $urlGenerator
* @param CacheDocumentsRequest $cacheDocumentsRequest
* @param ActorsRequest $actorRequest
+ * @param StreamRequest $streamRequest
* @param CacheDocumentService $cacheService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
IUrlGenerator $urlGenerator, CacheDocumentsRequest $cacheDocumentsRequest,
- ActorsRequest $actorRequest,
- CacheDocumentService $cacheService,
- ConfigService $configService, MiscService $miscService
+ ActorsRequest $actorRequest, StreamRequest $streamRequest,
+ CacheDocumentService $cacheService, ConfigService $configService, MiscService $miscService
) {
$this->urlGenerator = $urlGenerator;
$this->cacheDocumentsRequest = $cacheDocumentsRequest;
$this->actorRequest = $actorRequest;
+ $this->streamRequest = $streamRequest;
$this->configService = $configService;
$this->cacheService = $cacheService;
$this->miscService = $miscService;
@@ -143,6 +148,8 @@ class DocumentService {
$document->setLocalCopy($localCopy);
$this->cacheDocumentsRequest->endCaching($document);
+ $this->streamRequest->updateAttachments($document);
+
return $document;
} catch (CacheContentMimeTypeException $e) {
$this->miscService->log(
@@ -234,6 +241,7 @@ class DocumentService {
* @throws SocialAppConfigException
* @throws UrlCloudException
* @throws ItemUnknownException
+ * @throws ItemAlreadyExistsException
*/
public function cacheLocalAvatarByUsername(Person $actor): string {
$url = $this->urlGenerator->linkToRouteAbsolute(