directly set parent on setIcon/setObject

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/144/head
Maxence Lange 2018-12-05 20:21:37 -01:00
rodzic 589e39b572
commit ae90cc6117
5 zmienionych plików z 40 dodań i 36 usunięć

Wyświetl plik

@ -114,7 +114,6 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
try { try {
$icon = $this->parseCacheDocumentsLeftJoin($data); $icon = $this->parseCacheDocumentsLeftJoin($data);
$icon->setParent($actor);
$actor->setIcon($icon); $actor->setIcon($icon);
} catch (InvalidResourceException $e) { } catch (InvalidResourceException $e) {
} }

Wyświetl plik

@ -68,6 +68,9 @@ abstract class ACore extends Item implements JsonSerializable {
/** @var ACore */ /** @var ACore */
private $object = null; private $object = null;
/** @var Document */
private $icon = null;
/** @var ICoreService */ /** @var ICoreService */
private $saveAs; private $saveAs;
@ -125,12 +128,45 @@ abstract class ACore extends Item implements JsonSerializable {
* *
* @return ACore * @return ACore
*/ */
public function setObject(ACore $object): ACore { public function setObject(ACore &$object): ACore {
$object->setParent($this);
$this->object = $object; $this->object = $object;
return $this; 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 * @param ICoreService $class
*/ */
@ -511,6 +547,7 @@ abstract class ACore extends Item implements JsonSerializable {
$this->addEntry('object', $this->getObjectId()); $this->addEntry('object', $this->getObjectId());
} }
// TODO - moving the $this->icon to Model/Person ?
if ($this->gotIcon()) { if ($this->gotIcon()) {
$this->addEntryItem('icon', $this->getIcon()); $this->addEntryItem('icon', $this->getIcon());
} }

Wyświetl plik

@ -84,9 +84,6 @@ class Item {
/** @var string */ /** @var string */
private $actorId = ''; private $actorId = '';
/** @var Document */
private $icon = null;
/** @var string */ /** @var string */
private $iconId = ''; 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 * @return string

Wyświetl plik

@ -160,7 +160,6 @@ class ActivityService {
public function createActivity(Person $actor, ACore $item, ACore &$activity = null): string { public function createActivity(Person $actor, ACore $item, ACore &$activity = null): string {
$activity = new Create(); $activity = new Create();
$item->setParent($activity);
// $this->activityStreamsService->initCore($activity); // $this->activityStreamsService->initCore($activity);

Wyświetl plik

@ -34,6 +34,7 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Traits\TArrayTools; use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception; use Exception;
use OCA\Social\Exceptions\ActivityPubFormatException; use OCA\Social\Exceptions\ActivityPubFormatException;
use OCA\Social\Exceptions\InvalidResourceEntryException;
use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnknownItemException; use OCA\Social\Exceptions\UnknownItemException;
@ -131,6 +132,7 @@ class ImportService {
* @throws UnknownItemException * @throws UnknownItemException
* @throws UrlCloudException * @throws UrlCloudException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws InvalidResourceEntryException
*/ */
private function importFromData(array $data, $root = null): ACore { private function importFromData(array $data, $root = null): ACore {
@ -182,7 +184,6 @@ class ImportService {
try { try {
$object = $this->importFromData($this->getArray('object', $data, []), $item); $object = $this->importFromData($this->getArray('object', $data, []), $item);
$object->setParent($item);
$item->setObject($object); $item->setObject($object);
} catch (UnknownItemException $e) { } catch (UnknownItemException $e) {
} }
@ -190,7 +191,6 @@ class ImportService {
try { try {
/** @var Document $icon */ /** @var Document $icon */
$icon = $this->importFromData($this->getArray('icon', $data, []), $item); $icon = $this->importFromData($this->getArray('icon', $data, []), $item);
$icon->setParent($item);
$item->setIcon($icon); $item->setIcon($icon);
} catch (UnknownItemException $e) { } catch (UnknownItemException $e) {
} }