summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-05-11 19:13:46 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-05-12 09:36:59 +0200
commit2e0bef515ec674d0ee4caf63cb26f3b815ea960e (patch)
tree9e0f84bf0d69e1e033759e65cc6c28f23b27aafa
parent637924a13f751ef55addae69a7bd677f825cfea0 (diff)
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>
-rw-r--r--lib/Db/InstancesRequest.php15
-rw-r--r--lib/Db/SocialCrossQueryBuilder.php2
-rw-r--r--lib/Model/Instance.php10
-rw-r--r--lib/Service/InstanceService.php31
-rw-r--r--lib/Service/SignatureService.php4
5 files changed, 36 insertions, 26 deletions
diff --git a/lib/Db/InstancesRequest.php b/lib/Db/InstancesRequest.php
index e1492d8e..1eb68c98 100644
--- a/lib/Db/InstancesRequest.php
+++ b/lib/Db/InstancesRequest.php
@@ -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();
}
diff --git a/lib/Db/SocialCrossQueryBuilder.php b/lib/Db/SocialCrossQueryBuilder.php
index 474a510c..b30ad4e0 100644
--- a/lib/Db/SocialCrossQueryBuilder.php
+++ b/lib/Db/SocialCrossQueryBuilder.php
@@ -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)
);
diff --git a/lib/Model/Instance.php b/lib/Model/Instance.php
index b99c4e50..ec1a4c26 100644
--- a/lib/Model/Instance.php
+++ b/lib/Model/Instance.php
@@ -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;
diff --git a/lib/Service/InstanceService.php b/lib/Service/InstanceService.php
index f12654ad..e1fa915e 100644
--- a/lib/Service/InstanceService.php
+++ b/lib/Service/InstanceService.php
@@ -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();
}
}
diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php
index b58ff31c..5c1b4e86 100644
--- a/lib/Service/SignatureService.php
+++ b/lib/Service/SignatureService.php
@@ -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) {