adding Icon to Person

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/53/head
Maxence Lange 2018-11-23 19:52:14 -01:00 zatwierdzone przez Julius Härtl
rodzic 9aacccf719
commit fa41ac80d4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4C614C6ED2CDE6DF
6 zmienionych plików z 76 dodań i 0 usunięć

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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