summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-12-05 20:21:37 -0100
committerMaxence Lange <maxence@artificial-owl.com>2018-12-05 20:21:37 -0100
commitae90cc61171a470f5e078aa7a6b172fbc583a4fd (patch)
tree8458028b6cac595e6d3de51964b9d0e637612889 /lib
parent589e39b5729cb509083db398e792cc001d1b391f (diff)
directly set parent on setIcon/setObject
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Db/CacheActorsRequestBuilder.php1
-rw-r--r--lib/Model/ActivityPub/ACore.php39
-rw-r--r--lib/Model/ActivityPub/Item.php31
-rw-r--r--lib/Service/ActivityService.php1
-rw-r--r--lib/Service/ImportService.php4
5 files changed, 40 insertions, 36 deletions
diff --git a/lib/Db/CacheActorsRequestBuilder.php b/lib/Db/CacheActorsRequestBuilder.php
index dc037646..4833d0e9 100644
--- a/lib/Db/CacheActorsRequestBuilder.php
+++ b/lib/Db/CacheActorsRequestBuilder.php
@@ -114,7 +114,6 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
try {
$icon = $this->parseCacheDocumentsLeftJoin($data);
- $icon->setParent($actor);
$actor->setIcon($icon);
} catch (InvalidResourceException $e) {
}
diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php
index a3be9fd1..3e76e2fc 100644
--- a/lib/Model/ActivityPub/ACore.php
+++ b/lib/Model/ActivityPub/ACore.php
@@ -68,6 +68,9 @@ abstract class ACore extends Item implements JsonSerializable {
/** @var ACore */
private $object = null;
+ /** @var Document */
+ private $icon = null;
+
/** @var ICoreService */
private $saveAs;
@@ -125,12 +128,45 @@ abstract class ACore extends Item implements JsonSerializable {
*
* @return ACore
*/
- public function setObject(ACore $object): ACore {
+ public function setObject(ACore &$object): ACore {
+ $object->setParent($this);
$this->object = $object;
return $this;
}
+
+ /**
+ * @return bool
+ */
+ public function gotIcon(): bool {
+ if ($this->icon === null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @return Document
+ */
+ public function getIcon(): Document {
+ return $this->icon;
+ }
+
+ /**
+ * @param Document $icon
+ *
+ * @return ACore
+ */
+ public function setIcon(Document &$icon): ACore {
+ $icon->setParent($this);
+ $this->icon = $icon;
+
+ return $this;
+ }
+
+
/**
* @param ICoreService $class
*/
@@ -511,6 +547,7 @@ abstract class ACore extends Item implements JsonSerializable {
$this->addEntry('object', $this->getObjectId());
}
+ // TODO - moving the $this->icon to Model/Person ?
if ($this->gotIcon()) {
$this->addEntryItem('icon', $this->getIcon());
}
diff --git a/lib/Model/ActivityPub/Item.php b/lib/Model/ActivityPub/Item.php
index 7692cd0b..b96550a0 100644
--- a/lib/Model/ActivityPub/Item.php
+++ b/lib/Model/ActivityPub/Item.php
@@ -84,9 +84,6 @@ class Item {
/** @var string */
private $actorId = '';
- /** @var Document */
- private $icon = null;
-
/** @var string */
private $iconId = '';
@@ -514,34 +511,6 @@ class Item {
}
- /**
- * @return bool
- */
- public function gotIcon(): bool {
- if ($this->icon === null) {
- return false;
- }
-
- return true;
- }
-
- /**
- * @return Document
- */
- public function getIcon(): Document {
- return $this->icon;
- }
-
- /**
- * @param Document $icon
- *
- * @return Item
- */
- public function setIcon(Document $icon): Item {
- $this->icon = $icon;
-
- return $this;
- }
/**
* @return string
diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php
index 45f3aa20..1dd74c0c 100644
--- a/lib/Service/ActivityService.php
+++ b/lib/Service/ActivityService.php
@@ -160,7 +160,6 @@ class ActivityService {
public function createActivity(Person $actor, ACore $item, ACore &$activity = null): string {
$activity = new Create();
- $item->setParent($activity);
// $this->activityStreamsService->initCore($activity);
diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php
index 6ed9be1f..f87b0b4b 100644
--- a/lib/Service/ImportService.php
+++ b/lib/Service/ImportService.php
@@ -34,6 +34,7 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\Exceptions\ActivityPubFormatException;
+use OCA\Social\Exceptions\InvalidResourceEntryException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException;
@@ -131,6 +132,7 @@ class ImportService {
* @throws UnknownItemException
* @throws UrlCloudException
* @throws SocialAppConfigException
+ * @throws InvalidResourceEntryException
*/
private function importFromData(array $data, $root = null): ACore {
@@ -182,7 +184,6 @@ class ImportService {
try {
$object = $this->importFromData($this->getArray('object', $data, []), $item);
- $object->setParent($item);
$item->setObject($object);
} catch (UnknownItemException $e) {
}
@@ -190,7 +191,6 @@ class ImportService {
try {
/** @var Document $icon */
$icon = $this->importFromData($this->getArray('icon', $data, []), $item);
- $icon->setParent($item);
$item->setIcon($icon);
} catch (UnknownItemException $e) {
}