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 {
$icon = $this->parseCacheDocumentsLeftJoin($data);
$icon->setParent($actor);
$actor->setIcon($icon);
} catch (InvalidResourceException $e) {
}

Wyświetl plik

@ -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());
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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);

Wyświetl plik

@ -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) {
}