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/1415/head
Carl Schwan 2022-05-11 19:13:46 +02:00
rodzic 637924a13f
commit 2e0bef515e
5 zmienionych plików z 36 dodań i 26 usunięć

Wyświetl plik

@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\Social\Exceptions\InstanceDoesNotExistException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\Instance;
use OCP\DB\QueryBuilder\IQueryBuilder;
/**
* Class InstancesRequest
@ -54,7 +55,19 @@ class InstancesRequest extends InstancesRequestBuilder {
// $instance->setCreation($now->getTimestamp());
$qb = $this->getInstanceInsertSql();
$qb->setValue('uri', $qb->createNamedParameter($instance->getUri()));
$qb->setValue('uri', $qb->createNamedParameter($instance->getUri()))
->setValue('local', $qb->createNamedParameter($instance->isLocal()), IQueryBuilder::PARAM_BOOL)
->setValue('title', $qb->createNamedParameter($instance->getTitle()))
->setValue('version', $qb->createNamedParameter($instance->getVersion()))
->setValue('short_description', $qb->createNamedParameter($instance->getShortDescription()))
->setValue('description', $qb->createNamedParameter($instance->getDescription()))
->setValue('email', $qb->createNamedParameter($instance->getEmail()))
->setValue('urls', $qb->createNamedParameter(json_encode($instance->getUrls())))
->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('account_prim', $qb->createNamedParameter($instance->getAccountPrim() ? $this->prim($instance->getAccountPrim()) : null));
$qb->executeStatement();
}

Wyświetl plik

@ -96,7 +96,7 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
$expr = $this->expr();
if ($link !== '') {
$this->innerJoin(
$this->leftJoin(
$this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_CACHE_ACTORS, $pf,
$expr->eq('ca.id_prim', $link)
);

Wyświetl plik

@ -246,18 +246,10 @@ class Instance implements IQueryRow, JsonSerializable {
return $this;
}
/**
* @return string
*/
public function getAccountPrim(): string {
public function getAccountPrim(): ?string {
return $this->accountPrim;
}
/**
* @param string $prim
*
* @return Instance
*/
public function setAccountPrim(string $prim): self {
$this->accountPrim = $prim;

Wyświetl plik

@ -36,33 +36,40 @@ use OCA\Social\Db\InstancesRequest;
use OCA\Social\Exceptions\InstanceDoesNotExistException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\Instance;
use OCP\IConfig;
class InstanceService {
use TArrayTools;
private InstancesRequest$instancesRequest;
private InstancesRequest $instancesRequest;
private ConfigService $configService;
private MiscService $miscService;
private IConfig $config;
public function __construct(
InstancesRequest $instancesRequest, ConfigService $configService, MiscService $miscService
InstancesRequest $instancesRequest,
ConfigService $configService,
MiscService $miscService,
IConfig $config
) {
$this->instancesRequest = $instancesRequest;
$this->configService = $configService;
$this->miscService = $miscService;
$this->config = $config;
}
/**
*
*/
public function createLocal(): void {
public function createLocal(): Instance {
$instance = new Instance();
$instance->setLocal(true)
->setVersion($this->config->getAppValue('social', '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;
}
/**
* @param int $format
*
* @return Instance
* @throws InstanceDoesNotExistException
*/
public function getLocal(int $format = ACore::FORMAT_LOCAL): Instance {
@ -71,8 +78,6 @@ class InstanceService {
} catch (InstanceDoesNotExistException $e) {
}
$this->createLocal();
return $this->instancesRequest->getLocal($format);
return $this->createLocal();
}
}

Wyświetl plik

@ -58,7 +58,7 @@ use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\LinkedDataSignature;
use OCA\Social\Model\RequestQueue;
use OCP\Files\AppData\IFactory;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
@ -574,7 +574,7 @@ class SignatureService {
private static function getContextCacheFolder(): ISimpleFolder {
$path = 'context';
$appData = Server::get(IFactory::class)->get(Application::APP_NAME);
$appData = Server::get(IAppDataFactory::class)->get(Application::APP_NAME);
try {
$folder = $appData->getFolder($path);
} catch (NotFoundException $e) {