kopia lustrzana https://github.com/nextcloud/social
adding Icon to Person
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/53/head
rodzic
28d360083a
commit
031b76b942
|
@ -345,6 +345,13 @@
|
|||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>icon_id</name>
|
||||
<type>text</type>
|
||||
<length>127</length>
|
||||
<notnull>true</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
<name>summary</name>
|
||||
<type>text</type>
|
||||
|
|
|
@ -80,6 +80,12 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey()))
|
||||
->setValue('source', $qb->createNamedParameter($actor->getSource()));
|
||||
|
||||
if ($actor->gotIcon()) {
|
||||
$iconId = $actor->getIcon()
|
||||
->getId();
|
||||
$qb->setValue('icon_id', $qb->createNamedParameter($iconId));
|
||||
}
|
||||
|
||||
$qb->execute();
|
||||
|
||||
return $qb->getLastInsertId();
|
||||
|
@ -121,6 +127,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
public function getFromId(string $id): Person {
|
||||
$qb = $this->getCacheActorsSelectSql();
|
||||
$this->limitToIdString($qb, $id);
|
||||
$this->leftJoinCacheDocuments($qb, 'icon_id');
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
|
@ -145,6 +152,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
public function getFromAccount(string $account): Person {
|
||||
$qb = $this->getCacheActorsSelectSql();
|
||||
$this->limitToAccount($qb, $account);
|
||||
$this->leftJoinCacheDocuments($qb, 'icon_id');
|
||||
|
||||
$cursor = $qb->execute();
|
||||
$data = $cursor->fetch();
|
||||
|
@ -166,6 +174,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
public function searchAccounts(string $search): array {
|
||||
$qb = $this->getCacheActorsSelectSql();
|
||||
$this->searchInAccount($qb, $search);
|
||||
$this->leftJoinCacheDocuments($qb, 'icon_id');
|
||||
|
||||
$accounts = [];
|
||||
$cursor = $qb->execute();
|
||||
|
|
|
@ -112,6 +112,13 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
|||
$actor = new Person();
|
||||
$actor->importFromDatabase($data);
|
||||
|
||||
try {
|
||||
$icon = $this->parseCacheDocumentsLeftJoin($data);
|
||||
$icon->setParent($actor);
|
||||
$actor->setIcon($icon);
|
||||
} catch (InvalidResourceException $e) {
|
||||
}
|
||||
|
||||
return $actor;
|
||||
}
|
||||
|
||||
|
|
|
@ -568,6 +568,36 @@ abstract class ACore implements JsonSerializable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
|
|
@ -216,6 +216,18 @@ class PersonService implements ICoreService {
|
|||
return;
|
||||
}
|
||||
|
||||
if ($person->gotIcon()) {
|
||||
try {
|
||||
$icon = $this->cacheDocumentsRequest->getFromSource(
|
||||
$person->getIcon()
|
||||
->getUrl()
|
||||
);
|
||||
$person->setIcon($icon);
|
||||
} catch (CacheDocumentDoesNotExistException $e) {
|
||||
$this->cacheDocumentsRequest->save($person->getIcon());
|
||||
}
|
||||
}
|
||||
|
||||
$this->cacheActorsRequest->save($person);
|
||||
}
|
||||
|
||||
|
|
|
@ -133,6 +133,10 @@ class ImportService {
|
|||
$item = new Note($root);
|
||||
break;
|
||||
|
||||
case Image::TYPE:
|
||||
$item = new Image($root);
|
||||
break;
|
||||
|
||||
case Follow::TYPE:
|
||||
$item = new Follow($root);
|
||||
break;
|
||||
|
@ -163,6 +167,13 @@ class ImportService {
|
|||
} catch (UnknownItemException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var Document $icon */
|
||||
$icon = $this->createItem($this->getArray('icon', $data, []), $item);
|
||||
$item->setIcon($icon);
|
||||
} catch (UnknownItemException $e) {
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue