summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-08-21 11:22:24 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-08-22 18:35:47 -0100
commitdbd85cff3b4f8392dae9f82c588ac0f0f414e3db (patch)
treedeaaeb574264369e86ec2e912ab5c746422e027f /lib/Service
parent48e013cb98e47083d80efbd529bfa594cc027690 (diff)
remove invalid follows/streams on check
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/CheckService.php68
1 files changed, 65 insertions, 3 deletions
diff --git a/lib/Service/CheckService.php b/lib/Service/CheckService.php
index 3e65a26f..97b6f3cf 100644
--- a/lib/Service/CheckService.php
+++ b/lib/Service/CheckService.php
@@ -28,7 +28,10 @@ use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TStringTools;
use Exception;
use GuzzleHttp\Exception\ClientException;
+use OCA\Social\Db\CacheActorsRequest;
use OCA\Social\Db\FollowsRequest;
+use OCA\Social\Db\StreamRequest;
+use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCP\AppFramework\Http;
use OCP\Http\Client\IClientService;
@@ -68,11 +71,20 @@ class CheckService {
/** @var IURLGenerator */
private $urlGenerator;
+ /** @var FollowsRequest */
+ private $followRequest;
+
+ /** @var CacheActorsRequest */
+ private $cacheActorsRequest;
+
+ /** @var StreamRequest */
+ private $streamRequest;
+
/** @var ConfigService */
private $configService;
- /** @var FollowsRequest */
- private $followRequest;
+ /** @var MiscService */
+ private $miscService;
/**
@@ -84,11 +96,17 @@ class CheckService {
* @param IRequest $request
* @param IURLGenerator $urlGenerator
* @param FollowsRequest $followRequest
+ * @param CacheActorsRequest $cacheActorsRequest
+ * @param StreamRequest $streamRequest
* @param ConfigService $configService
+ * @param MiscService $miscService
*/
public function __construct(
ICache $cache, IConfig $config, IClientService $clientService, IRequest $request,
- IURLGenerator $urlGenerator, FollowsRequest $followRequest, ConfigService $configService
+ IURLGenerator $urlGenerator, FollowsRequest $followRequest,
+ CacheActorsRequest $cacheActorsRequest, StreamRequest $streamRequest,
+ ConfigService $configService,
+ MiscService $miscService
) {
$this->cache = $cache;
$this->config = $config;
@@ -96,7 +114,10 @@ class CheckService {
$this->request = $request;
$this->urlGenerator = $urlGenerator;
$this->followRequest = $followRequest;
+ $this->cacheActorsRequest = $cacheActorsRequest;
+ $this->streamRequest = $streamRequest;
$this->configService = $configService;
+ $this->miscService = $miscService;
}
@@ -156,6 +177,8 @@ class CheckService {
public function checkInstallationStatus() {
$this->configService->setCoreValue('public_webfinger', 'social/lib/webfinger.php');
$this->configService->setCoreValue('public_host-meta', 'social/lib/hostmeta.php');
+ $this->removeInvalidFollows();
+ $this->removeInvalidNotes();
$this->checkStatusTableFollows();
}
@@ -180,6 +203,45 @@ class CheckService {
/**
+ *
+ */
+ public function removeInvalidFollows() {
+ $count = 0;
+ $follows = $this->followRequest->getAll();
+ foreach ($follows as $follow) {
+ try {
+ $this->cacheActorsRequest->getFromId($follow->getActorId());
+ $this->cacheActorsRequest->getFromId($follow->getObjectId());
+ } catch (CacheActorDoesNotExistException $e) {
+ $this->followRequest->deleteFollowById($follow->getId());
+ $count++;
+ }
+ }
+
+ $this->miscService->log('removeInvalidFollows removed ' . $count . ' entries', 1);
+ }
+
+
+ /**
+ *
+ */
+ public function removeInvalidNotes() {
+ $count = 0;
+ $streams = $this->streamRequest->getAll();
+ foreach ($streams as $stream) {
+ try {
+ // Check if it's enough for Note, Announce, ...
+ $this->cacheActorsRequest->getFromId($stream->getAttributedTo());
+ } catch (CacheActorDoesNotExistException $e) {
+ $this->streamRequest->deleteStreamById($stream->getId());
+ $count++;
+ }
+ }
+
+ $this->miscService->log('removeInvalidNotes removed ' . $count . ' entries', 1);
+ }
+
+ /**
* @param string $base
*
* @return bool