Create instance if it doesn't exist

Currently mostly with dummy data, we need to expose these options to the
admin

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
pull/1416/head
Carl Schwan 2022-05-11 19:13:46 +02:00
rodzic 191683733d
commit f176b3ce1a
3 zmienionych plików z 17 dodań i 8 usunięć

Wyświetl plik

@ -66,7 +66,7 @@ class InstancesRequest extends InstancesRequestBuilder {
->setValue('stats', $qb->createNamedParameter(json_encode($instance->getStats())))
->setValue('usage', $qb->createNamedParameter(json_encode($instance->getUsage())))
->setValue('image', $qb->createNamedParameter($instance->getImage()))
->setValue('languages', $qb->createNamedParameter(json_encode($instance->getImage())))
->setValue('languages', $qb->createNamedParameter(json_encode($instance->getLanguages())))
->setValue('account_prim', $qb->createNamedParameter($instance->getAccountPrim() ? $this->prim($instance->getAccountPrim()) : null));
$qb->executeStatement();
}
@ -80,7 +80,7 @@ class InstancesRequest extends InstancesRequestBuilder {
*/
public function getLocal(int $format = ACore::FORMAT_ACTIVITYPUB): Instance {
$qb = $this->getInstanceSelectSql($format);
$qb->linkToCacheActors('ca', 'account_prim');
$qb->linkToCacheActors('ca', 'account_prim', false);
$qb->limitToDBFieldInt('local', 1);
$qb->leftJoinCacheDocuments('icon_id', 'ca');

Wyświetl plik

@ -87,7 +87,7 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
* @param string $alias
* @param string $link
*/
public function linkToCacheActors(string $alias = 'ca', string $link = '') {
public function linkToCacheActors(string $alias = 'ca', string $link = '', bool $innerJoin = true) {
if ($this->getType() !== QueryBuilder::SELECT) {
return;
}
@ -96,10 +96,17 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
$expr = $this->expr();
if ($link !== '') {
$this->leftJoin(
$this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_CACHE_ACTORS, $pf,
$expr->eq('ca.id_prim', $link)
);
if ($innerJoin) {
$this->innerJoin(
$this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_CACHE_ACTORS, $pf,
$expr->eq('ca.id_prim', $link)
);
} else {
$this->leftJoin(
$this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_CACHE_ACTORS, $pf,
$expr->eq('ca.id_prim', $link)
);
}
} else {
$this->from(CoreRequestBuilder::TABLE_CACHE_ACTORS, $pf);
}

Wyświetl plik

@ -32,6 +32,7 @@ declare(strict_types=1);
namespace OCA\Social\Service;
use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\Social\AppInfo\Application;
use OCA\Social\Db\InstancesRequest;
use OCA\Social\Exceptions\InstanceDoesNotExistException;
use OCA\Social\Model\ActivityPub\ACore;
@ -61,11 +62,12 @@ class InstanceService {
public function createLocal(): Instance {
$instance = new Instance();
$instance->setLocal(true)
->setVersion($this->config->getAppValue('social', 'installed_version', '0.0'))
->setVersion($this->config->getAppValue(Application::APP_NAME, 'installed_version', '0.0'))
->setApprovalRequired(false)
->setDescription($this->config->getAppValue('theming', 'slogan', 'a safe home for your data'))
->setTitle($this->config->getAppValue('theming', 'name', 'Nextcloud Social'));
$this->instancesRequest->save($instance);
return $instance;
}