storing Actor source

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/32/head
Maxence Lange 2018-11-15 14:26:56 -01:00
rodzic 8c5624be53
commit d31dcf4e87
6 zmienionych plików z 77 dodań i 38 usunięć

Wyświetl plik

@ -207,6 +207,13 @@
<length>127</length>
</field>
<field>
<name>source</name>
<type>text</type>
<length>3000</length>
<notnull>true</notnull>
</field>
<field>
<name>creation</name>
<type>timestamp</type>
@ -236,8 +243,8 @@
<field>
<name>local</name>
<type>text</type>
<length>7</length>
<type>boolean</type>
<default>false</default>
<notnull>true</notnull>
</field>
@ -318,6 +325,13 @@
<notnull>true</notnull>
</field>
<field>
<name>source</name>
<type>text</type>
<length>3000</length>
<notnull>true</notnull>
</field>
<field>
<name>creation</name>
<type>timestamp</type>

Wyświetl plik

@ -5,7 +5,7 @@
<name>Social</name>
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
<description><![CDATA[test]]></description>
<version>0.0.29</version>
<version>0.0.32</version>
<licence>agpl</licence>
<author mail="maxence@artificial-owl.com">Maxence Lange</author>
<author mail="jus@bitgrid.net">Julius Härtl</author>

Wyświetl plik

@ -61,35 +61,31 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
* @param bool $local
*
* @return int
* @throws \Exception
*/
public function save(Person $actor, bool $local = false): int {
try {
$qb = $this->getCacheActorsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($actor->getId()))
->setValue('account', $qb->createNamedParameter($actor->getAccount()))
->setValue('local', $qb->createNamedParameter(($local) ? '1' : '0'))
->setValue('following', $qb->createNamedParameter($actor->getFollowing()))
->setValue('followers', $qb->createNamedParameter($actor->getFollowers()))
->setValue('inbox', $qb->createNamedParameter($actor->getInbox()))
->setValue('shared_inbox', $qb->createNamedParameter($actor->getSharedInbox()))
->setValue('outbox', $qb->createNamedParameter($actor->getOutbox()))
->setValue('featured', $qb->createNamedParameter($actor->getFeatured()))
->setValue('url', $qb->createNamedParameter($actor->getUrl()))
->setValue(
'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
)
->setValue('name', $qb->createNamedParameter($actor->getName()))
->setValue('summary', $qb->createNamedParameter($actor->getSummary()))
->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey()));
$qb = $this->getCacheActorsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($actor->getId()))
->setValue('account', $qb->createNamedParameter($actor->getAccount()))
->setValue('local', $qb->createNamedParameter(($local) ? '1' : '0'))
->setValue('following', $qb->createNamedParameter($actor->getFollowing()))
->setValue('followers', $qb->createNamedParameter($actor->getFollowers()))
->setValue('inbox', $qb->createNamedParameter($actor->getInbox()))
->setValue('shared_inbox', $qb->createNamedParameter($actor->getSharedInbox()))
->setValue('outbox', $qb->createNamedParameter($actor->getOutbox()))
->setValue('featured', $qb->createNamedParameter($actor->getFeatured()))
->setValue('url', $qb->createNamedParameter($actor->getUrl()))
->setValue(
'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
)
->setValue('name', $qb->createNamedParameter($actor->getName()))
->setValue('summary', $qb->createNamedParameter($actor->getSummary()))
->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey()))
->setValue('source', $qb->createNamedParameter($actor->getSource()));
$qb->execute();
$qb->execute();
return $qb->getLastInsertId();
} catch (\Exception $e) {
throw $e;
}
return $qb->getLastInsertId();
}

Wyświetl plik

@ -112,6 +112,10 @@ abstract class ACore implements JsonSerializable {
/** @var bool */
private $completeDetails = false;
/** @var string */
private $source = '';
/**
* Core constructor.
*
@ -155,7 +159,9 @@ abstract class ACore implements JsonSerializable {
* @return ACore
*/
public function setType(string $type): ACore {
$this->type = $type;
if ($type !== '') {
$this->type = $type;
}
return $this;
}
@ -706,11 +712,31 @@ abstract class ACore implements JsonSerializable {
}
/**
* @return string
*/
public function getSource(): string {
return $this->source;
}
/**
* @param string $source
*
* @return ACore
*/
public function setSource(string $source): ACore {
$this->source = $source;
return $this;
}
/**
* @param array $data
*/
public function import(array $data) {
$this->setId($this->get('id', $data, ''));
$this->setType($this->get('type', $data, ''));
$this->setUrl($this->get('url', $data, ''));
$this->setSummary($this->get('summary', $data, ''));
$this->setToArray($this->getArray('to', $data, []));
@ -718,6 +744,7 @@ abstract class ACore implements JsonSerializable {
$this->setPublished($this->get('published', $data, ''));
$this->setActorId($this->get('actor', $data, ''));
$this->setObjectId($this->get('object', $data, ''));
$this->setSource($this->get('source', $data, ''));
}
@ -766,6 +793,10 @@ abstract class ACore implements JsonSerializable {
$this->addEntry('object', $this->getObjectId());
}
if ($this->isCompleteDetails()) {
$this->addEntry('source', $this->getSource());
}
return $this->getEntries();
}

Wyświetl plik

@ -352,15 +352,11 @@ class Person extends ACore implements JsonSerializable {
*/
public function setLocal(bool $local): Person {
$this->local = $local;
return $this;
}
/**
* @param array $data
*/
@ -377,12 +373,12 @@ class Person extends ACore implements JsonSerializable {
->setFollowing($this->get('following', $data, ''))
->setSharedInbox($this->get('shared_inbox', $data, ''))
->setFeatured($this->get('featured', $data, ''))
->setLocal(($this->get('local', $data, '') === '1'))
->setLocal(($this->getInt('local', $data, 0) === 1))
->setCreation($this->getInt('creation', $data, 0));
if ($this->getPreferredUsername() === '') {
$this->setType('Invalid');
}
// if ($this->getPreferredUsername() === '') {
// $this->setType('Invalid');
// }
}
@ -411,7 +407,7 @@ class Person extends ACore implements JsonSerializable {
'owner' => $this->getId(),
'publicKeyPem' => $this->getPublicKey()
],
'local' => $this->isLocal()
'local' => $this->isLocal()
]
);
}

Wyświetl plik

@ -92,6 +92,7 @@ class PersonService implements ICoreService {
}
try {
$actor->setSource(json_encode($actor, JSON_UNESCAPED_SLASHES));
$this->save($actor, true);
} catch (Exception $e) {
}
@ -125,6 +126,7 @@ class PersonService implements ICoreService {
$object = $this->instanceService->retrieveObject($id);
$actor = new Person();
$actor->import($object);
$actor->setSource(json_encode($object, JSON_UNESCAPED_SLASHES));
$actor->setPreferredUsername($this->get('preferredUsername', $object, ''));
$actor->setPublicKey($this->get('publicKey.publicKeyPem', $object));