renamed class DBConn to DbHelper

This commit is contained in:
huangjx
2022-01-28 21:47:02 +08:00
parent 7cf0f0e336
commit 238b45850b
7 changed files with 12 additions and 139 deletions

View File

@@ -2,7 +2,7 @@
namespace OCA\NCDownloader\Command;
use OCA\NCDownloader\Tools\DBConn;
use OCA\NCDownloader\Tools\DbHelper;
use OCA\NCDownloader\Tools\Helper;
use OC\Core\Command\Base;
use Symfony\Component\Console\Input\InputArgument;
@@ -13,7 +13,7 @@ class Aria2Command extends base
{
public function __construct()
{
$this->dbconn = new DBConn();
$this->dbconn = new DbHelper();
parent::__construct();
}
protected function configure()

View File

@@ -3,7 +3,7 @@ namespace OCA\NCDownloader\Controller;
use OCA\NCDownloader\Tools\Aria2;
use OCA\NCDownloader\Tools\Counters;
use OCA\NCDownloader\Tools\DBConn;
use OCA\NCDownloader\Tools\DbHelper;
use OCA\NCDownloader\Tools\folderScan;
use OCA\NCDownloader\Tools\Helper;
use OCA\NCDownloader\Tools\Settings;
@@ -38,7 +38,7 @@ class Aria2Controller extends Controller
//$this->config = \OC::$server->getAppConfig();
$this->aria2 = $aria2;
$this->aria2->init();
$this->dbconn = new DBConn();
$this->dbconn = new DbHelper();
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
}

View File

@@ -4,7 +4,7 @@ namespace OCA\NCDownloader\Controller;
use OCA\NCDownloader\Tools\Aria2;
use OCA\NCDownloader\Tools\Counters;
use OCA\NCDownloader\Tools\DBConn;
use OCA\NCDownloader\Tools\DbHelper;
use OCA\NCDownloader\Tools\Helper;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
@@ -33,7 +33,7 @@ class MainController extends Controller
OC_Util::setupFS();
$this->aria2 = $aria2;
$this->aria2->init();
$this->dbconn = new DBConn();
$this->dbconn = new DbHelper();
$this->counters = new Counters($aria2, $this->dbconn, $UserId);
}
/**

View File

@@ -2,7 +2,7 @@
namespace OCA\NCDownloader\Controller;
use OCA\NCDownloader\Tools\Aria2;
use OCA\NCDownloader\Tools\DBConn;
use OCA\NCDownloader\Tools\DbHelper;
use OCA\NCDownloader\Tools\folderScan;
use OCA\NCDownloader\Tools\Helper;
use OCA\NCDownloader\Tools\Settings;
@@ -28,7 +28,7 @@ class YoutubeController extends Controller
$this->l10n = $IL10N;
$this->settings = new Settings($UserId);
$this->downloadDir = $this->settings->get('ncd_downloader_dir') ?? "/Downloads";
$this->dbconn = new DBConn();
$this->dbconn = new DbHelper();
$this->youtube = $youtube;
$this->aria2 = $aria2;
$this->aria2->init();

View File

@@ -3,13 +3,13 @@
namespace OCA\NCDownloader\Tools;
use OCA\NCDownloader\Tools\Aria2;
use OCA\NCDownloader\Tools\DBConn;
use OCA\NCDownloader\Tools\DbHelper;
class Counters
{
private $minmax = [0, 999];
public function __construct(Aria2 $aria2, DBConn $dbconn, $uid)
public function __construct(Aria2 $aria2, DbHelper $dbconn, $uid)
{
$this->aria2 = $aria2;
$this->dbconn = $dbconn;

View File

@@ -1,127 +0,0 @@
<?php
namespace OCA\NCDownloader\Tools;
class DBConn
{
//@var OC\DB\ConnectionAdapter
private $conn;
private $table = "ncdownloader_info";
public function __construct()
{
$this->conn = \OC::$server->getDatabaseConnection();
$this->queryBuilder = $this->conn->getQueryBuilder();
$this->prefixedTable = $this->queryBuilder->getTableName($this->table);
//$container = \OC::$server->query(\OCP\IServerContainer::class);
//Helper::debug(get_class($container->query(\OCP\RichObjectStrings\IValidator::class)));
//$this->conn = \OC::$server->query(Connection::class);//working only with 22
//$this->connAdapter = \OC::$server->getDatabaseConnection();
//$this->conn = $this->connAdapter->getInner();
}
public function insert($insert)
{
$inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*' . $this->table, $insert, [
'gid',
]);
return $inserted;
}
public function getAll()
{
//OC\DB\QueryBuilder\QueryBuilder
$queryBuilder = $this->queryBuilder
->select('filename', 'type', 'gid', 'timestamp', 'status')
->from($this->table)
->execute();
return $queryBuilder->fetchAll();
}
public function getByUid($uid)
{
$queryBuilder = $this->queryBuilder
->select('*')
->from($this->table)
->where('uid = :uid')
->setParameter('uid', $uid)
->execute();
return $queryBuilder->fetchAll();
}
public function getUidByGid($gid)
{
$queryBuilder = $this->queryBuilder
->select('uid')
->from($this->table)
->where('gid = :gid')
->setParameter('gid', $gid)
->execute();
return $queryBuilder->fetchColumn();
}
public function getYoutubeByUid($uid)
{
$qb = $this->queryBuilder
->select('*')
->from($this->table)
->where('uid = :uid')
->andWhere('type = :type')
->setParameter('uid', $uid)
->setParameter('type', Helper::DOWNLOADTYPE['YOUTUBE-DL'])
->execute();
return $qb->fetchAll();
}
public function getByGid($gid)
{
$queryBuilder = $this->queryBuilder
->select('*')
->from($this->table)
->where('gid = :gid')
->setParameter('gid', $gid)
->execute();
return $queryBuilder->fetch();
}
public function save(array $keys, $values = array(), $conditions = array())
{
return $this->conn->setValues($this->table, $keys, $values, $conditions);
}
public function deleteByGid($gid)
{
$qb = $this->queryBuilder
->delete($this->table)
->where('gid = :gid')
->setParameter('gid', $gid);
return $qb->execute();
}
public function executeUpdate($sql, $values)
{
return $this->conn->executeUpdate($sql, $values);
}
public function updateStatus($gid, $status = 1)
{
$query = $this->queryBuilder;
$query->update($this->table)
->set("status", $query->createNamedParameter($status))
->where('gid = :gid')
->setParameter('gid', $gid);
return $query->execute();
//$sql = sprintf("UPDATE %s set status = ? WHERE gid = ?", $this->prefixedTable);
//$this->execute($sql, [$status, $gid]);
}
public function updateFilename($gid, $filename)
{
$query = $this->queryBuilder;
$query->update($this->table)
->set("filename", $query->createNamedParameter($filename))
->where('gid = :gid')
->andWhere('filename = :filename')
->setParameter('gid', $gid)
->setParameter('filename', 'unknown');
return $query->execute();
}
}

View File

@@ -1,7 +1,7 @@
<?php
namespace OCA\NCDownloader\Tools;
use OCA\NCDownloader\Tools\DBConn;
use OCA\NCDownloader\Tools\DbHelper;
use OCA\NCDownloader\Tools\Helper;
class YoutubeHelper
@@ -18,7 +18,7 @@ class YoutubeHelper
public $filesize = null;
public function __construct()
{
$this->dbconn = new DBConn();
$this->dbconn = new DbHelper();
$this->tablename = $this->dbconn->queryBuilder->getTableName("ncdownloader_info");
$this->user = \OC::$server->getUserSession()->getUser()->getUID();
}