summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-01-02 23:31:23 +0100
committerGitHub <noreply@github.com>2019-01-02 23:31:23 +0100
commit6b74286bd0774557ba2e5a3bd994081daf250a69 (patch)
tree7ef6cac556480e3e130057c6cc12d02d8460ec04
parent65dc245807dbdab34b716e602497848248f9e896 (diff)
parented98204d47421587300a6c576df5edb4cdf9e2c3 (diff)
Merge pull request #283 from nextcloud/code/noid/rewrite-exception-on-request
[huge] rewrite of the exceptions while requesting remote instance
-rw-r--r--composer.lock8
-rw-r--r--lib/AP.php20
-rw-r--r--lib/Command/QueueProcess.php2
-rw-r--r--lib/Controller/ActivityPubController.php11
-rw-r--r--lib/Controller/QueueController.php2
-rw-r--r--lib/Controller/SocialPubController.php5
-rw-r--r--lib/Cron/Queue.php2
-rw-r--r--lib/Db/CacheDocumentsRequest.php11
-rw-r--r--lib/Db/RequestQueueRequest.php5
-rw-r--r--lib/Exceptions/CacheContentSizeException.php8
-rw-r--r--lib/Exceptions/ItemUnknownException.php8
-rw-r--r--lib/Exceptions/Request410Exception.php8
-rw-r--r--lib/Exceptions/RequestContentException.php8
-rw-r--r--lib/Exceptions/RequestException.php8
-rw-r--r--lib/Exceptions/RequestNetworkException.php8
-rw-r--r--lib/Exceptions/RequestResultSizeException.php8
-rw-r--r--lib/Exceptions/RequestServerException.php8
-rw-r--r--lib/Exceptions/RetrieveAccountFormatException.php8
-rw-r--r--lib/Exceptions/ServiceAccountAlreadyExistException.php8
-rw-r--r--lib/Exceptions/UnknownItemException.php8
-rw-r--r--lib/Exceptions/WebfingerException.php8
-rw-r--r--lib/Interfaces/Activity/AcceptInterface.php4
-rw-r--r--lib/Interfaces/Activity/AddInterface.php4
-rw-r--r--lib/Interfaces/Activity/BlockInterface.php4
-rw-r--r--lib/Interfaces/Activity/CreateInterface.php4
-rw-r--r--lib/Interfaces/Activity/DeleteInterface.php4
-rw-r--r--lib/Interfaces/Activity/FollowInterface.php18
-rw-r--r--lib/Interfaces/Activity/LikeInterface.php4
-rw-r--r--lib/Interfaces/Activity/RejectInterface.php4
-rw-r--r--lib/Interfaces/Activity/RemoveInterface.php4
-rw-r--r--lib/Interfaces/Activity/UndoInterface.php4
-rw-r--r--lib/Interfaces/Activity/UpdateInterface.php4
-rw-r--r--lib/Model/ActivityPub/Actor/Person.php1
-rw-r--r--lib/Model/ActivityPub/Object/Image.php1
-rw-r--r--lib/Service/ActivityService.php75
-rw-r--r--lib/Service/CacheActorService.php34
-rw-r--r--lib/Service/CacheDocumentService.php56
-rw-r--r--lib/Service/ConfigService.php2
-rw-r--r--lib/Service/CurlService.php183
-rw-r--r--lib/Service/DocumentService.php32
-rw-r--r--lib/Service/FollowService.php32
-rw-r--r--lib/Service/ImportService.php7
-rw-r--r--lib/Service/NoteService.php30
-rw-r--r--lib/Service/QueueService.php15
-rw-r--r--lib/Service/SignatureService.php44
45 files changed, 448 insertions, 284 deletions
diff --git a/composer.lock b/composer.lock
index d0d0f1a7..cbc4c3a8 100644
--- a/composer.lock
+++ b/composer.lock
@@ -12,12 +12,12 @@
"source": {
"type": "git",
"url": "https://github.com/daita/my-small-php-tools.git",
- "reference": "29754f18951856a22c0fd5fc388b6162ea98fe8a"
+ "reference": "0baac1f399b257b00fdc2eafb754396ffa1892f4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/29754f18951856a22c0fd5fc388b6162ea98fe8a",
- "reference": "29754f18951856a22c0fd5fc388b6162ea98fe8a",
+ "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/0baac1f399b257b00fdc2eafb754396ffa1892f4",
+ "reference": "0baac1f399b257b00fdc2eafb754396ffa1892f4",
"shasum": ""
},
"require": {
@@ -40,7 +40,7 @@
}
],
"description": "My small PHP Tools",
- "time": "2018-12-18T00:38:01+00:00"
+ "time": "2018-12-27T11:14:55+00:00"
},
{
"name": "digitalbazaar/json-ld",
diff --git a/lib/AP.php b/lib/AP.php
index 951e358d..c205a2a3 100644
--- a/lib/AP.php
+++ b/lib/AP.php
@@ -34,7 +34,7 @@ namespace OCA\Social;
use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\SocialAppConfigException;
-use OCA\Social\Exceptions\UnknownItemException;
+use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\Activity\AcceptInterface;
use OCA\Social\Interfaces\Activity\AddInterface;
use OCA\Social\Interfaces\Activity\BlockInterface;
@@ -174,7 +174,7 @@ class AP {
* @return ACore
* @throws RedundancyLimitException
* @throws SocialAppConfigException
- * @throws UnknownItemException
+ * @throws ItemUnknownException
*/
public function getItemFromData(array $data, $parent = null, int $level = 0): ACore {
if (++$level > self::REDUNDANCY_LIMIT) {
@@ -189,14 +189,14 @@ class AP {
try {
$object = $this->getItemFromData($this->getArray('object', $data, []), $item, $level);
$item->setObject($object);
- } catch (UnknownItemException $e) {
+ } catch (ItemUnknownException $e) {
}
try {
/** @var Document $icon */
$icon = $this->getItemFromData($this->getArray('icon', $data, []), $item, $level);
$item->setIcon($icon);
- } catch (UnknownItemException $e) {
+ } catch (ItemUnknownException $e) {
}
return $item;
@@ -208,7 +208,7 @@ class AP {
*
* @return ACore
* @throws SocialAppConfigException
- * @throws UnknownItemException
+ * @throws ItemUnknownException
*/
public function getSimpleItemFromData(array $data): Acore {
$item = $this->getItemFromType($this->get('type', $data, ''));
@@ -223,7 +223,7 @@ class AP {
* @param string $type
*
* @return ACore
- * @throws UnknownItemException
+ * @throws ItemUnknownException
*/
public function getItemFromType(string $type) {
switch ($type) {
@@ -273,7 +273,7 @@ class AP {
return new Update();
default:
- throw new UnknownItemException();
+ throw new ItemUnknownException();
}
}
@@ -282,7 +282,7 @@ class AP {
* @param ACore $activity
*
* @return IActivityPubInterface
- * @throws UnknownItemException
+ * @throws ItemUnknownException
*/
public function getInterfaceForItem(Acore $activity): IActivityPubInterface {
return $this->getInterfaceFromType($activity->getType());
@@ -293,7 +293,7 @@ class AP {
* @param string $type
*
* @return IActivityPubInterface
- * @throws UnknownItemException
+ * @throws ItemUnknownException
*/
public function getInterfaceFromType(string $type): IActivityPubInterface {
switch ($type) {
@@ -350,7 +350,7 @@ class AP {
break;
default:
- throw new UnknownItemException();
+ throw new ItemUnknownException();
}
return $service;
diff --git a/lib/Command/QueueProcess.php b/lib/Command/QueueProcess.php
index e73229ec..20ea8f14 100644
--- a/lib/Command/QueueProcess.php
+++ b/lib/Command/QueueProcess.php
@@ -32,7 +32,6 @@ namespace OCA\Social\Command;
use OC\Core\Command\Base;
-use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Service\ActivityService;
use OCA\Social\Service\ConfigService;
@@ -113,7 +112,6 @@ class QueueProcess extends Base {
$output->write('.');
try {
$this->activityService->manageRequest($request);
- } catch (RequestException $e) {
} catch (SocialAppConfigException $e) {
}
}
diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php
index b6c9b958..dd8b57bc 100644
--- a/lib/Controller/ActivityPubController.php
+++ b/lib/Controller/ActivityPubController.php
@@ -35,7 +35,8 @@ use Exception;
use OC\AppFramework\Http;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\SignatureIsGoneException;
-use OCA\Social\Exceptions\UnknownItemException;
+use OCA\Social\Exceptions\ItemUnknownException;
+use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\FollowService;
use OCA\Social\Service\ImportService;
@@ -112,6 +113,7 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
+ * @throws UrlCloudException
*/
public function actor(string $username): Response {
if (!$this->checkSourceActivityStreams()) {
@@ -143,6 +145,7 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
+ * @throws UrlCloudException
*/
public function actorAlias(string $username): Response {
return $this->actor($username);
@@ -172,7 +175,7 @@ class ActivityPubController extends Controller {
try {
$this->importService->parseIncomingRequest($activity);
- } catch (UnknownItemException $e) {
+ } catch (ItemUnknownException $e) {
}
return $this->success([]);
@@ -213,7 +216,7 @@ class ActivityPubController extends Controller {
try {
$this->importService->parseIncomingRequest($activity);
- } catch (UnknownItemException $e) {
+ } catch (ItemUnknownException $e) {
}
return $this->success([]);
@@ -249,6 +252,7 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
+ * @throws UrlCloudException
*/
public function followers(string $username): Response {
@@ -278,6 +282,7 @@ class ActivityPubController extends Controller {
* @param string $username
*
* @return Response
+ * @throws UrlCloudException
*/
public function following(string $username): Response {
if (!$this->checkSourceActivityStreams()) {
diff --git a/lib/Controller/QueueController.php b/lib/Controller/QueueController.php
index bd764050..4fd4c10f 100644
--- a/lib/Controller/QueueController.php
+++ b/lib/Controller/QueueController.php
@@ -32,7 +32,6 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TAsync;
use OCA\Social\AppInfo\Application;
-use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Model\RequestQueue;
use OCA\Social\Service\ActivityService;
@@ -99,7 +98,6 @@ class QueueController extends Controller {
$request->setTimeout(ActivityService::TIMEOUT_ASYNC);
try {
$this->activityService->manageRequest($request);
- } catch (RequestException $e) {
} catch (SocialAppConfigException $e) {
}
}
diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php
index 18c669d1..ce9f131b 100644
--- a/lib/Controller/SocialPubController.php
+++ b/lib/Controller/SocialPubController.php
@@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
+use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Service\AccountService;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\FollowService;
@@ -117,6 +118,7 @@ class SocialPubController extends Controller {
$page = new PublicTemplateResponse(Application::APP_NAME, 'main', $data);
$page->setStatus($status);
$page->setHeaderTitle($this->l10n->t('Social'));
+
return $page;
}
@@ -131,6 +133,7 @@ class SocialPubController extends Controller {
* @param string $username
*
* @return Response
+ * @throws UrlCloudException
*/
public function actor(string $username): Response {
return $this->renderPage($username);
@@ -147,6 +150,7 @@ class SocialPubController extends Controller {
* @param string $username
*
* @return TemplateResponse
+ * @throws UrlCloudException
*/
public function followers(string $username): Response {
return $this->renderPage($username);
@@ -163,6 +167,7 @@ class SocialPubController extends Controller {
* @param string $username
*
* @return TemplateResponse
+ * @throws UrlCloudException
*/
public function following(string $username): Response {
return $this->renderPage($username);
diff --git a/lib/Cron/Queue.php b/lib/Cron/Queue.php
index a2315504..21f15fdb 100644
--- a/lib/Cron/Queue.php
+++ b/lib/Cron/Queue.php
@@ -33,7 +33,6 @@ namespace OCA\Social\Cron;
use OC\BackgroundJob\TimedJob;
use OCA\Social\AppInfo\Application;
-use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Service\ActivityService;
use OCA\Social\Service\MiscService;
@@ -94,7 +93,6 @@ class Queue extends TimedJob {
$request->setTimeout(ActivityService::TIMEOUT_SERVICE);
try {
$this->activityService->manageRequest($request);
- } catch (RequestException $e) {
} catch (SocialAppConfigException $e) {
}
}
diff --git a/lib/Db/CacheDocumentsRequest.php b/lib/Db/CacheDocumentsRequest.php
index 43b9ad3e..9d7777c9 100644
--- a/lib/Db/CacheDocumentsRequest.php
+++ b/lib/Db/CacheDocumentsRequest.php
@@ -173,5 +173,16 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
$qb->execute();
}
+
+ /**
+ * @param string $id
+ */
+ public function deleteById(string $id) {
+ $qb = $this->getCacheDocumentsDeleteSql();
+ $this->limitToIdString($qb, $id);
+
+ $qb->execute();
+ }
+
}
diff --git a/lib/Db/RequestQueueRequest.php b/lib/Db/RequestQueueRequest.php
index 941c1913..fbfa127e 100644
--- a/lib/Db/RequestQueueRequest.php
+++ b/lib/Db/RequestQueueRequest.php
@@ -32,7 +32,6 @@ namespace OCA\Social\Db;
use DateTime;
-use Exception;
use OCA\Social\Exceptions\QueueStatusException;
use OCA\Social\Model\RequestQueue;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -50,8 +49,6 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
* create a new Queue in the database.
*
* @param RequestQueue[] $queues
- *
- * @throws Exception
*/
public function multiple(array $queues) {
foreach ($queues as $queue) {
@@ -64,8 +61,6 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
* create a new Queue in the database.
*
* @param RequestQueue $queue
- *
- * @throws Exception
*/
public function create(RequestQueue $queue) {
$qb = $this->getQueueInsertSql();
diff --git a/lib/Exceptions/CacheContentSizeException.php b/lib/Exceptions/CacheContentSizeException.php
deleted file mode 100644
index 1a264915..00000000
--- a/lib/Exceptions/CacheContentSizeException.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace OCA\Social\Exceptions;
-
-class CacheContentSizeException extends \Exception {
-
-}
-
diff --git a/lib/Exceptions/ItemUnknownException.php b/lib/Exceptions/ItemUnknownException.php
new file mode 100644
index 00000000..c0210a65
--- /dev/null
+++ b/lib/Exceptions/ItemUnknownException.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace OCA\Social\Exceptions;
+
+class ItemUnknownException extends \Exception {
+
+}
+
diff --git a/lib/Exceptions/Request410Exception.php b/lib/Exceptions/Request410Exception.php
deleted file mode 100644
index 85bc8405..00000000
--- a/lib/Exceptions/Request410Exception.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace OCA\Social\Exceptions;
-
-class Request410Exception extends \Exception {
-
-}
-
diff --git a/lib/Exceptions/RequestContentException.php b/lib/Exceptions/RequestContentException.php
new file mode 100644
index 00000000..9cc44b8c
--- /dev/null
+++ b/lib/Exceptions/RequestContentException.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace OCA\Social\Exceptions;
+
+class RequestContentException extends \Exception {
+
+}
+
diff --git a/lib/Exceptions/RequestException.php b/lib/Exceptions/RequestException.php
deleted file mode 100644
index 6769dd32..00000000
--- a/lib/Exceptions/RequestException.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace OCA\Social\Exceptions;
-
-class RequestException extends \Exception {
-
-}
-
diff --git a/lib/Exceptions/RequestNetworkException.php b/lib/Exceptions/RequestNetworkException.php
new file mode 100644
index 00000000..c9c7c215
--- /dev/null
+++ b/lib/Exceptions/RequestNetworkException.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace OCA\Social\Exceptions;
+
+class RequestNetworkException extends \Exception {
+
+}
+
diff --git a/lib/Exceptions/RequestResultSizeException.php b/lib/Exceptions/RequestResultSizeException.php
new file mode 100644
index 00000000..557852d1
--- /dev/null
+++ b/lib/Exceptions/RequestResultSizeException.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace OCA\Social\Exceptions;
+
+class RequestResultSizeException extends \Exception {
+
+}
+
diff --git a/lib/Exceptions/RequestServerException.php b/lib/Exceptions/RequestServerException.php
new file mode 100644
index 00000000..09f4cea4
--- /dev/null
+++ b/lib/Exceptions/RequestServerException.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace OCA\Social\Exceptions;
+
+class RequestServerException extends \Exception {
+
+}
+
diff --git a/lib/Exceptions/RetrieveAccountFormatException.php b/lib/Exceptions/RetrieveAccountFormatException.php
new file mode 100644
index 00000000..5f888934
--- /dev/null
+++ b/lib/Exceptions/RetrieveAccountFormatException.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace OCA\Social\Exceptions;
+
+class RetrieveAccountFormatException extends \Exception {
+
+}
+
diff --git a/lib/Exceptions/ServiceAccountAlreadyExistException.php b/lib/Exceptions/ServiceAccountAlreadyExistException.php
deleted file mode 100644
index 5dffe6f4..00000000
--- a/lib/Exceptions/ServiceAccountAlreadyExistException.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace OCA\Social\Exceptions;
-
-class ServiceAccountAlreadyExistException extends \Exception {
-
-}
-
diff --git a/lib/Exceptions/UnknownItemException.php b/lib/Exceptions/UnknownItemException.php
deleted file mode 100644
index 5d494101..00000000
--- a/lib/Exceptions/UnknownItemException.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace OCA\Social\Exceptions;
-
-class UnknownItemException extends \Exception {
-
-}
-
diff --git a/lib/Exceptions/WebfingerException.php b/lib/Exceptions/WebfingerException.php
deleted file mode 100644
index b9aac463..00000000
--- a/lib/Exceptions/WebfingerException.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace OCA\Social\Exceptions;
-
-class WebfingerException extends \Exception {
-
-}
-
diff --git a/lib/Interfaces/Activity/AcceptInterface.php b/lib/Interfaces/Activity/AcceptInterface.php
index d2addb8e..5e3aa5fb 100644
--- a/lib/Interfaces/Activity/AcceptInterface.php
+++ b/lib/Interfaces/Activity/AcceptInterface.php
@@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
-use OCA\Social\Exceptions\UnknownItemException;
+use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@@ -68,7 +68,7 @@ class AcceptInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
- } catch (UnknownItemException $e) {
+ } catch (ItemUnknownException $e) {
}
}
diff --git a/lib/Interfaces/Activity/AddInterface.php b/lib/Interfaces/Activity/AddInterface.php
index efd0adce..706460ab 100644
--- a/lib/Interfaces/Activity/AddInterface.php
+++ b/lib/Interfaces/Activity/AddInterface.php
@@ -33,7 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\ItemNotFoundException;
-use OCA\Social\Exceptions\UnknownItemException;
+use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Service\MiscService;
@@ -68,7 +68,7 @@ class AddInterface implements IActivityPubInterface {
try {
$service = AP::$activityPub->getInterfaceForItem($item->getObject());
$service->activity($item, $object);
- } catch (UnknownItemException $e) {
+ } catch (ItemUnknownException $e) {
}
}
diff --git a/lib/Interfaces/Activity/BlockInterface.php b/lib/Interfaces/Acti