Fixed deprecation warnings and improved compatibility with newer versions.
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
|
||||
namespace OCA\NCDownloader\Db;
|
||||
|
||||
use OC\AllConfig;
|
||||
|
||||
class Settings extends AllConfig
|
||||
class Settings
|
||||
{
|
||||
//@config OC\AppConfig
|
||||
private $appConfig;
|
||||
@@ -12,8 +10,6 @@ class Settings extends AllConfig
|
||||
//@OC\SystemConfig
|
||||
private $sysConfig;
|
||||
|
||||
//@OC\AllConfig
|
||||
private $allConfig;
|
||||
private $user;
|
||||
private $appName;
|
||||
//type of settings (system = 1 or app =2)
|
||||
@@ -22,12 +18,11 @@ class Settings extends AllConfig
|
||||
public const TYPE = ['SYSTEM' => 1, 'USER' => 2, 'APP' => 3];
|
||||
public function __construct($user = null)
|
||||
{
|
||||
$this->appConfig = \OC::$server->getAppConfig();
|
||||
$this->sysConfig = \OC::$server->getSystemConfig();
|
||||
$this->appConfig = \OC::$server->get(\OCP\IConfig::class);
|
||||
$this->sysConfig = \OC::$server->get(\OCP\IConfig::class);
|
||||
$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();
|
||||
}
|
||||
@@ -47,16 +42,16 @@ class Settings extends AllConfig
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if ($this->type == self::TYPE['USER'] && isset($this->user)) {
|
||||
return $this->allConfig->getUserValue($this->user, $this->appName, $key, $default);
|
||||
return $this->appConfig->getUserValue($this->user, $this->appName, $key, $default);
|
||||
} else if ($this->type == self::TYPE['SYSTEM']) {
|
||||
return $this->allConfig->getSystemValue($key, $default);
|
||||
return $this->appConfig->getSystemValue($key, $default);
|
||||
} else {
|
||||
return $this->allConfig->getAppValue($this->appName, $key, $default);
|
||||
return $this->appConfig->getAppValue($this->appName, $key, $default);
|
||||
}
|
||||
}
|
||||
public function getAria2()
|
||||
{
|
||||
$settings = $this->allConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", '');
|
||||
$settings = $this->appConfig->getUserValue($this->user, $this->appName, "custom_aria2_settings", '');
|
||||
return json_decode($settings, 1);
|
||||
}
|
||||
|
||||
@@ -79,11 +74,11 @@ class Settings extends AllConfig
|
||||
{
|
||||
try {
|
||||
if ($this->type == self::TYPE['USER'] && isset($this->user)) {
|
||||
$this->allConfig->setUserValue($this->user, $this->appName, $key, $value);
|
||||
$this->appConfig->setUserValue($this->user, $this->appName, $key, $value);
|
||||
} else if ($this->type == self::TYPE['SYSTEM']) {
|
||||
$this->allConfig->setSystemValue($key, $value);
|
||||
$this->appConfig->setSystemValue($key, $value);
|
||||
} else {
|
||||
$this->allConfig->setAppValue($this->appName, $key, $value);
|
||||
$this->appConfig->setAppValue($this->appName, $key, $value);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return ['error' => $e->getMessage()];
|
||||
@@ -96,22 +91,22 @@ class Settings extends AllConfig
|
||||
$keys = $this->getAllKeys();
|
||||
$value = [];
|
||||
foreach ($keys as $key) {
|
||||
$value[$key] = $this->allConfig->getAppValue($this->appName, $key);
|
||||
$value[$key] = $this->appConfig->getAppValue($this->appName, $key);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
public function getAllKeys()
|
||||
{
|
||||
return $this->allConfig->getAppKeys($this->appName);
|
||||
return $this->appConfig->getAppKeys($this->appName);
|
||||
}
|
||||
|
||||
public function getAllUserSettings()
|
||||
{
|
||||
$keys = $this->allConfig->getUserKeys($this->user, $this->appName);
|
||||
$keys = $this->appConfig->getUserKeys($this->user, $this->appName);
|
||||
$value = [];
|
||||
foreach ($keys as $key) {
|
||||
$value[$key] = $this->allConfig->getUserValue($this->user, $this->appName, $key);
|
||||
$value[$key] = $this->appConfig->getUserValue($this->user, $this->appName, $key);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user