Fixed deprecation warnings and improved compatibility with newer versions.
This commit is contained in:
@@ -11,7 +11,6 @@ use OCP\AppFramework\Http\JSONResponse;
|
|||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OC_Util;
|
|
||||||
use \OC\Files\Filesystem;
|
use \OC\Files\Filesystem;
|
||||||
|
|
||||||
class Aria2Controller extends Controller
|
class Aria2Controller extends Controller
|
||||||
@@ -34,9 +33,9 @@ class Aria2Controller extends Controller
|
|||||||
$this->uid = $UserId;
|
$this->uid = $UserId;
|
||||||
$this->l10n = $IL10N;
|
$this->l10n = $IL10N;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->urlGenerator = \OC::$server->getURLGenerator();
|
$this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class);
|
||||||
$this->downloadDir = Helper::getDownloadDir();
|
$this->downloadDir = Helper::getDownloadDir();
|
||||||
OC_Util::setupFS();
|
\OC_Util::setupFS();
|
||||||
//$this->config = \OC::$server->getAppConfig();
|
//$this->config = \OC::$server->getAppConfig();
|
||||||
$this->aria2 = $aria2;
|
$this->aria2 = $aria2;
|
||||||
$this->aria2->init();
|
$this->aria2->init();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use OCP\AppFramework\Http\TemplateResponse;
|
|||||||
//use OCP\Files\IRootFolder;
|
//use OCP\Files\IRootFolder;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OC_Util;
|
use OCP\Util;
|
||||||
|
|
||||||
class MainController extends Controller
|
class MainController extends Controller
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,7 @@ class MainController extends Controller
|
|||||||
//$this->rootFolder = $rootFolder;
|
//$this->rootFolder = $rootFolder;
|
||||||
$this->aria2 = $aria2;
|
$this->aria2 = $aria2;
|
||||||
$this->aria2->init();
|
$this->aria2->init();
|
||||||
$this->urlGenerator = \OC::$server->getURLGenerator();
|
$this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class);
|
||||||
$this->dbconn = new DbHelper();
|
$this->dbconn = new DbHelper();
|
||||||
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
|
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
|
||||||
$this->ytdl = $ytdl;
|
$this->ytdl = $ytdl;
|
||||||
@@ -63,8 +63,8 @@ class MainController extends Controller
|
|||||||
{
|
{
|
||||||
// $str = \OC::$server->getDatabaseConnection()->getInner()->getPrefix();
|
// $str = \OC::$server->getDatabaseConnection()->getInner()->getPrefix();
|
||||||
//$config = \OC::$server->getAppConfig();
|
//$config = \OC::$server->getAppConfig();
|
||||||
OC_Util::addScript($this->appName, 'app');
|
Util::addScript($this->appName, 'app');
|
||||||
OC_Util::addStyle($this->appName, 'app');
|
Util::addStyle($this->appName, 'app');
|
||||||
|
|
||||||
$params = $this->buildParams();
|
$params = $this->buildParams();
|
||||||
$response = new TemplateResponse($this->appName, 'Index', $params);
|
$response = new TemplateResponse($this->appName, 'Index', $params);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class SearchController extends Controller
|
|||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->appName = $appName;
|
$this->appName = $appName;
|
||||||
$this->uid = $UserId;
|
$this->uid = $UserId;
|
||||||
$this->urlGenerator = \OC::$server->getURLGenerator();
|
$this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class);
|
||||||
$this->search = new siteSearch();
|
$this->search = new siteSearch();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class YtdlController extends Controller
|
|||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
$this->appName = $appName;
|
$this->appName = $appName;
|
||||||
$this->uid = $UserId;
|
$this->uid = $UserId;
|
||||||
$this->urlGenerator = \OC::$server->getURLGenerator();
|
$this->urlGenerator = \OC::$server->get(\OCP\IURLGenerator::class);
|
||||||
$this->l10n = $IL10N;
|
$this->l10n = $IL10N;
|
||||||
$this->downloadDir = Helper::getDownloadDir();
|
$this->downloadDir = Helper::getDownloadDir();
|
||||||
$this->dbconn = new DbHelper();
|
$this->dbconn = new DbHelper();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Helper
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->conn = \OC::$server->getDatabaseConnection();
|
$this->conn = \OC::$server->get(\OCP\IDBConnection::class);
|
||||||
$this->queryBuilder = $this->conn->getQueryBuilder();
|
$this->queryBuilder = $this->conn->getQueryBuilder();
|
||||||
$this->prefixedTable = $this->queryBuilder->getTableName($this->table);
|
$this->prefixedTable = $this->queryBuilder->getTableName($this->table);
|
||||||
//$container = \OC::$server->query(\OCP\IServerContainer::class);
|
//$container = \OC::$server->query(\OCP\IServerContainer::class);
|
||||||
@@ -130,7 +130,7 @@ class Helper
|
|||||||
|
|
||||||
public function getDBType(): string
|
public function getDBType(): string
|
||||||
{
|
{
|
||||||
return \OC::$server->getConfig()->getSystemValue('dbtype', "mysql");
|
return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('dbtype', "mysql");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getExtra($data)
|
public function getExtra($data)
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
namespace OCA\NCDownloader\Db;
|
namespace OCA\NCDownloader\Db;
|
||||||
|
|
||||||
use OC\AllConfig;
|
class Settings
|
||||||
|
|
||||||
class Settings extends AllConfig
|
|
||||||
{
|
{
|
||||||
//@config OC\AppConfig
|
//@config OC\AppConfig
|
||||||
private $appConfig;
|
private $appConfig;
|
||||||
@@ -12,8 +10,6 @@ class Settings extends AllConfig
|
|||||||
//@OC\SystemConfig
|
//@OC\SystemConfig
|
||||||
private $sysConfig;
|
private $sysConfig;
|
||||||
|
|
||||||
//@OC\AllConfig
|
|
||||||
private $allConfig;
|
|
||||||
private $user;
|
private $user;
|
||||||
private $appName;
|
private $appName;
|
||||||
//type of settings (system = 1 or app =2)
|
//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 const TYPE = ['SYSTEM' => 1, 'USER' => 2, 'APP' => 3];
|
||||||
public function __construct($user = null)
|
public function __construct($user = null)
|
||||||
{
|
{
|
||||||
$this->appConfig = \OC::$server->getAppConfig();
|
$this->appConfig = \OC::$server->get(\OCP\IConfig::class);
|
||||||
$this->sysConfig = \OC::$server->getSystemConfig();
|
$this->sysConfig = \OC::$server->get(\OCP\IConfig::class);
|
||||||
$this->appName = 'ncdownloader';
|
$this->appName = 'ncdownloader';
|
||||||
$this->type = self::TYPE['USER'];
|
$this->type = self::TYPE['USER'];
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->allConfig = new AllConfig($this->sysConfig);
|
|
||||||
//$this->connAdapter = \OC::$server->getDatabaseConnection();
|
//$this->connAdapter = \OC::$server->getDatabaseConnection();
|
||||||
//$this->conn = $this->connAdapter->getInner();
|
//$this->conn = $this->connAdapter->getInner();
|
||||||
}
|
}
|
||||||
@@ -47,16 +42,16 @@ class Settings extends AllConfig
|
|||||||
public function get($key, $default = null)
|
public function get($key, $default = null)
|
||||||
{
|
{
|
||||||
if ($this->type == self::TYPE['USER'] && isset($this->user)) {
|
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']) {
|
} else if ($this->type == self::TYPE['SYSTEM']) {
|
||||||
return $this->allConfig->getSystemValue($key, $default);
|
return $this->appConfig->getSystemValue($key, $default);
|
||||||
} else {
|
} else {
|
||||||
return $this->allConfig->getAppValue($this->appName, $key, $default);
|
return $this->appConfig->getAppValue($this->appName, $key, $default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function getAria2()
|
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);
|
return json_decode($settings, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +74,11 @@ class Settings extends AllConfig
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($this->type == self::TYPE['USER'] && isset($this->user)) {
|
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']) {
|
} else if ($this->type == self::TYPE['SYSTEM']) {
|
||||||
$this->allConfig->setSystemValue($key, $value);
|
$this->appConfig->setSystemValue($key, $value);
|
||||||
} else {
|
} else {
|
||||||
$this->allConfig->setAppValue($this->appName, $key, $value);
|
$this->appConfig->setAppValue($this->appName, $key, $value);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return ['error' => $e->getMessage()];
|
return ['error' => $e->getMessage()];
|
||||||
@@ -96,22 +91,22 @@ class Settings extends AllConfig
|
|||||||
$keys = $this->getAllKeys();
|
$keys = $this->getAllKeys();
|
||||||
$value = [];
|
$value = [];
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$value[$key] = $this->allConfig->getAppValue($this->appName, $key);
|
$value[$key] = $this->appConfig->getAppValue($this->appName, $key);
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
public function getAllKeys()
|
public function getAllKeys()
|
||||||
{
|
{
|
||||||
return $this->allConfig->getAppKeys($this->appName);
|
return $this->appConfig->getAppKeys($this->appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllUserSettings()
|
public function getAllUserSettings()
|
||||||
{
|
{
|
||||||
$keys = $this->allConfig->getUserKeys($this->user, $this->appName);
|
$keys = $this->appConfig->getUserKeys($this->user, $this->appName);
|
||||||
$value = [];
|
$value = [];
|
||||||
foreach ($keys as $key) {
|
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;
|
return $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ class siteSearch
|
|||||||
private $defaultSite = __NAMESPACE__ . '\Sites\TPB';
|
private $defaultSite = __NAMESPACE__ . '\Sites\TPB';
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->container = \OC::$server->query(IServerContainer::class);
|
$this->container = \OC::$server->get(IServerContainer::class);
|
||||||
$this->site = __NAMESPACE__ . '\Sites\TPB';
|
$this->site = __NAMESPACE__ . '\Sites\TPB';
|
||||||
}
|
}
|
||||||
public function go($keyword): array
|
public function go($keyword): array
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ use OCP\Settings\ISettings;
|
|||||||
use OCA\NCDownloader\Db\Settings;
|
use OCA\NCDownloader\Db\Settings;
|
||||||
use OCA\NCDownloader\Tools\Helper;
|
use OCA\NCDownloader\Tools\Helper;
|
||||||
|
|
||||||
|
use OCP\IUserManager;
|
||||||
|
|
||||||
class Personal implements ISettings
|
class Personal implements ISettings
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -19,18 +21,22 @@ class Personal implements ISettings
|
|||||||
private $timeFactory;
|
private $timeFactory;
|
||||||
/** @var IConfig */
|
/** @var IConfig */
|
||||||
private $config;
|
private $config;
|
||||||
|
/** @var IUserManager */
|
||||||
|
private $userManager;
|
||||||
private $uid;
|
private $uid;
|
||||||
private $settings;
|
private $settings;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IDBConnection $connection,
|
IDBConnection $connection,
|
||||||
ITimeFactory $timeFactory,
|
ITimeFactory $timeFactory,
|
||||||
IConfig $config
|
IConfig $config,
|
||||||
|
IUserManager $userManager
|
||||||
) {
|
) {
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->timeFactory = $timeFactory;
|
$this->timeFactory = $timeFactory;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->uid = \OC::$server->getUserSession()->getUser()->getUID();
|
$this->userManager = $userManager;
|
||||||
|
$this->uid = \OC::$server->get(\OCP\IUserSession::class)->getUser()->getUID();
|
||||||
$this->settings = new Settings($this->uid);
|
$this->settings = new Settings($this->uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +46,10 @@ class Personal implements ISettings
|
|||||||
public function getForm()
|
public function getForm()
|
||||||
{
|
{
|
||||||
$path = '/apps/ncdownloader/personal/save';
|
$path = '/apps/ncdownloader/personal/save';
|
||||||
$parameters = [
|
$user = $this->userManager->get($this->uid);
|
||||||
|
$groupManager = \OC::$server->get(\OCP\IGroupManager::class);
|
||||||
|
$isAdmin = ($user !== null) ? $groupManager->isInGroup($user->getUID(), 'admin') : false;
|
||||||
|
$parameters = [
|
||||||
"settings" => [
|
"settings" => [
|
||||||
"ncd_downloader_dir" => Helper::getDownloadDir(),
|
"ncd_downloader_dir" => Helper::getDownloadDir(),
|
||||||
"ncd_torrents_dir" => $this->settings->get("ncd_torrents_dir"),
|
"ncd_torrents_dir" => $this->settings->get("ncd_torrents_dir"),
|
||||||
@@ -49,7 +58,7 @@ class Personal implements ISettings
|
|||||||
'ncd_seed_time' => $this->settings->get("ncd_seed_time"),
|
'ncd_seed_time' => $this->settings->get("ncd_seed_time"),
|
||||||
"path" => $path,
|
"path" => $path,
|
||||||
"disallow_aria2_settings" => Helper::getAdminSettings("disallow_aria2_settings"),
|
"disallow_aria2_settings" => Helper::getAdminSettings("disallow_aria2_settings"),
|
||||||
"is_admin" => \OC_User::isAdminUser($this->uid),
|
"is_admin" => $isAdmin,
|
||||||
],
|
],
|
||||||
"options" => [
|
"options" => [
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use OCA\NCDownloader\Aria2\Options as aria2Options;
|
|||||||
use OCA\NCDownloader\Db\Settings;
|
use OCA\NCDownloader\Db\Settings;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC_Util;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use OCA\NCDownloader\Aria2\Aria2;
|
use OCA\NCDownloader\Aria2\Aria2;
|
||||||
use OCA\NCDownloader\Ytdl\Ytdl;
|
use OCA\NCDownloader\Ytdl\Ytdl;
|
||||||
@@ -160,7 +159,19 @@ class Helper
|
|||||||
{
|
{
|
||||||
if (!isset($filter)) {
|
if (!isset($filter)) {
|
||||||
$filter = array(
|
$filter = array(
|
||||||
'status', 'followedBy', 'totalLength', 'errorMessage', 'dir', 'uploadLength', 'completedLength', 'downloadSpeed', 'files', 'numSeeders', 'connections', 'gid', 'following',
|
'status',
|
||||||
|
'followedBy',
|
||||||
|
'totalLength',
|
||||||
|
'errorMessage',
|
||||||
|
'dir',
|
||||||
|
'uploadLength',
|
||||||
|
'completedLength',
|
||||||
|
'downloadSpeed',
|
||||||
|
'files',
|
||||||
|
'numSeeders',
|
||||||
|
'connections',
|
||||||
|
'gid',
|
||||||
|
'following',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$value = array_filter($data, function ($k) use ($filter) {
|
$value = array_filter($data, function ($k) use ($filter) {
|
||||||
@@ -225,8 +236,7 @@ class Helper
|
|||||||
if ($memcache->hasKey($program)) {
|
if ($memcache->hasKey($program)) {
|
||||||
return $memcache->get($program);
|
return $memcache->get($program);
|
||||||
}
|
}
|
||||||
|
$dataPath = \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory');
|
||||||
$dataPath = \OC::$server->getSystemConfig()->getValue('datadirectory');
|
|
||||||
$paths = ['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/opt/bin', $dataPath . "/bin"];
|
$paths = ['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin', '/sbin', '/bin', '/opt/bin', $dataPath . "/bin"];
|
||||||
$result = $default;
|
$result = $default;
|
||||||
$exeSniffer = new ExecutableFinder();
|
$exeSniffer = new ExecutableFinder();
|
||||||
@@ -393,13 +403,13 @@ class Helper
|
|||||||
|
|
||||||
public static function getDataDir(): string
|
public static function getDataDir(): string
|
||||||
{
|
{
|
||||||
return \OC::$server->getSystemConfig()->getValue('datadirectory');
|
return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('datadirectory');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getLocalFolder(string $path): string
|
public static function getLocalFolder(string $path): string
|
||||||
{
|
{
|
||||||
if (self::getUID()) {
|
if (self::getUID()) {
|
||||||
OC_Util::setupFS();
|
\OC_Util::setupFS();
|
||||||
//get the real path of the file in the filesystem
|
//get the real path of the file in the filesystem
|
||||||
return \OC\Files\Filesystem::getLocalFile($path);
|
return \OC\Files\Filesystem::getLocalFile($path);
|
||||||
}
|
}
|
||||||
@@ -488,7 +498,7 @@ class Helper
|
|||||||
|
|
||||||
public static function getAppPath(): string
|
public static function getAppPath(): string
|
||||||
{
|
{
|
||||||
return \OC::$server->getAppManager()->getAppPath('ncdownloader');
|
return \OC::$server->get(\OCP\App\IAppManager::class)->getAppPath('ncdownloader');
|
||||||
}
|
}
|
||||||
public static function folderUpdated(string $dir): bool
|
public static function folderUpdated(string $dir): bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Helper
|
|||||||
{
|
{
|
||||||
$this->dbconn = new DbHelper();
|
$this->dbconn = new DbHelper();
|
||||||
$this->tablename = $this->dbconn->queryBuilder->getTableName("ncdownloader_info");
|
$this->tablename = $this->dbconn->queryBuilder->getTableName("ncdownloader_info");
|
||||||
$this->user = \OC::$server->getUserSession()->getUser()->getUID();
|
$this->user = \OC::$server->get(\OCP\IUserSession::class)->getUser()->getUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function create()
|
public static function create()
|
||||||
|
|||||||
Reference in New Issue
Block a user