2020-09-01 14:14:19 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2020-09-01 14:14:19 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-09-08 13:46:22 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-09-01 14:14:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Service;
|
|
|
|
|
2022-05-11 17:13:46 +00:00
|
|
|
use OCA\Social\AppInfo\Application;
|
2020-09-01 14:14:19 +00:00
|
|
|
use OCA\Social\Db\InstancesRequest;
|
|
|
|
use OCA\Social\Exceptions\InstanceDoesNotExistException;
|
|
|
|
use OCA\Social\Model\ActivityPub\ACore;
|
|
|
|
use OCA\Social\Model\Instance;
|
2023-05-25 20:45:28 +00:00
|
|
|
use OCA\Social\Tools\Traits\TArrayTools;
|
2022-05-11 17:13:46 +00:00
|
|
|
use OCP\IConfig;
|
2020-09-01 14:14:19 +00:00
|
|
|
|
|
|
|
class InstanceService {
|
|
|
|
use TArrayTools;
|
|
|
|
|
2022-05-11 17:13:46 +00:00
|
|
|
private InstancesRequest $instancesRequest;
|
2022-04-15 11:01:18 +00:00
|
|
|
private ConfigService $configService;
|
|
|
|
private MiscService $miscService;
|
2022-05-11 17:13:46 +00:00
|
|
|
private IConfig $config;
|
2020-09-01 14:14:19 +00:00
|
|
|
|
|
|
|
public function __construct(
|
2022-05-11 17:13:46 +00:00
|
|
|
InstancesRequest $instancesRequest,
|
|
|
|
ConfigService $configService,
|
|
|
|
MiscService $miscService,
|
2024-10-28 12:53:06 +00:00
|
|
|
IConfig $config,
|
2020-09-01 14:14:19 +00:00
|
|
|
) {
|
|
|
|
$this->instancesRequest = $instancesRequest;
|
|
|
|
$this->configService = $configService;
|
|
|
|
$this->miscService = $miscService;
|
2022-05-11 17:13:46 +00:00
|
|
|
$this->config = $config;
|
2020-09-01 14:14:19 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 17:13:46 +00:00
|
|
|
public function createLocal(): Instance {
|
|
|
|
$instance = new Instance();
|
|
|
|
$instance->setLocal(true)
|
2023-06-20 10:02:58 +00:00
|
|
|
->setVersion($this->config->getAppValue(Application::APP_ID, 'installed_version', '0.0'))
|
2022-05-11 17:13:46 +00:00
|
|
|
->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);
|
2022-05-11 17:13:46 +00:00
|
|
|
|
2022-05-11 17:13:46 +00:00
|
|
|
return $instance;
|
2020-09-01 14:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws InstanceDoesNotExistException
|
|
|
|
*/
|
|
|
|
public function getLocal(int $format = ACore::FORMAT_LOCAL): Instance {
|
|
|
|
try {
|
|
|
|
return $this->instancesRequest->getLocal($format);
|
|
|
|
} catch (InstanceDoesNotExistException $e) {
|
|
|
|
}
|
|
|
|
|
2022-05-11 17:13:46 +00:00
|
|
|
return $this->createLocal();
|
2020-09-01 14:14:19 +00:00
|
|
|
}
|
|
|
|
}
|