An attempt to obtain a functional version with the various fixes implemented so far.

This commit is contained in:
darkpisto
2025-12-11 14:05:40 +01:00
parent 6a36b24162
commit ddcaf72e6e
13 changed files with 65 additions and 57 deletions

View File

@@ -2,7 +2,9 @@
namespace OCA\NCDownloader\Db;
class Settings
use OC\AllConfig;
class Settings extends AllConfig
{
//@config OC\AppConfig
private $appConfig;
@@ -10,6 +12,8 @@ class Settings
//@OC\SystemConfig
private $sysConfig;
//@OC\AllConfig
private $allConfig;
private $user;
private $appName;
//type of settings (system = 1 or app =2)
@@ -18,11 +22,13 @@ class Settings
public const TYPE = ['SYSTEM' => 1, 'USER' => 2, 'APP' => 3];
public function __construct($user = null)
{
$this->appConfig = \OC::$server->get(\OCP\IConfig::class);
$this->sysConfig = \OC::$server->get(\OCP\IConfig::class);
//$this->appConfig = \OC::$server->getAppConfig();
//$this->appConfig = \OC::$server->getAppConfig();
$this->sysConfig = \OC::$server->getSystemConfig();
$this->appName = 'ncdownloader';
$this->type = self::TYPE['USER'];
$this->user = $user;
$this->allConfig = new AllConfig($this->sysConfig);
//$this->connAdapter = \OC::$server->getDatabaseConnection();
//$this->conn = $this->connAdapter->getInner();
}
@@ -42,16 +48,16 @@ class Settings
public function get($key, $default = null)
{
if ($this->type == self::TYPE['USER'] && isset($this->user)) {
return $this->appConfig->getUserValue($this->user, $this->appName, $key, $default);
return $this->allConfig->getUserValue($this->user, $this->appName, $key, $default);
} else if ($this->type == self::TYPE['SYSTEM']) {
return $this->appConfig->getSystemValue($key, $default);
return $this->allConfig->getSystemValue($key, $default);
} else {
return $this->appConfig->getAppValue($this->appName, $key, $default);
return $this->allConfig->getAppValue($this->appName, $key, $default);
}
}
public function getAria2()
{
$settings = $this->appConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", '');
$settings = $this->allConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", '');
return json_decode($settings, 1);
}
@@ -74,11 +80,11 @@ class Settings
{
try {
if ($this->type == self::TYPE['USER'] && isset($this->user)) {
$this->appConfig->setUserValue($this->user, $this->appName, $key, $value);
$this->allConfig->setUserValue($this->user, $this->appName, $key, $value);
} else if ($this->type == self::TYPE['SYSTEM']) {
$this->appConfig->setSystemValue($key, $value);
$this->allConfig->setSystemValue($key, $value);
} else {
$this->appConfig->setAppValue($this->appName, $key, $value);
$this->allConfig->setAppValue($this->appName, $key, $value);
}
} catch (\Exception $e) {
return ['error' => $e->getMessage()];
@@ -91,22 +97,22 @@ class Settings
$keys = $this->getAllKeys();
$value = [];
foreach ($keys as $key) {
$value[$key] = $this->appConfig->getAppValue($this->appName, $key);
$value[$key] = $this->allConfig->getAppValue($this->appName, $key);
}
return $value;
}
public function getAllKeys()
{
return $this->appConfig->getAppKeys($this->appName);
return $this->allConfig->getAppKeys($this->appName);
}
public function getAllUserSettings()
{
$keys = $this->appConfig->getUserKeys($this->user, $this->appName);
$keys = $this->allConfig->getUserKeys($this->user, $this->appName);
$value = [];
foreach ($keys as $key) {
$value[$key] = $this->appConfig->getUserValue($this->user, $this->appName, $key);
$value[$key] = $this->allConfig->getUserValue($this->user, $this->appName, $key);
}
return $value;
}
}
}