From 238b45850b6a3f05168738242f07fed0887ca36b Mon Sep 17 00:00:00 2001 From: huangjx Date: Fri, 28 Jan 2022 21:47:02 +0800 Subject: [PATCH] renamed class DBConn to DbHelper --- lib/Command/Aria2Command.php | 4 +- lib/Controller/Aria2Controller.php | 4 +- lib/Controller/MainController.php | 4 +- lib/Controller/YoutubeController.php | 4 +- lib/Tools/Counters.php | 4 +- lib/Tools/DBConn.php | 127 --------------------------- lib/Tools/YoutubeHelper.php | 4 +- 7 files changed, 12 insertions(+), 139 deletions(-) delete mode 100644 lib/Tools/DBConn.php diff --git a/lib/Command/Aria2Command.php b/lib/Command/Aria2Command.php index 3a9af40..4df71ff 100644 --- a/lib/Command/Aria2Command.php +++ b/lib/Command/Aria2Command.php @@ -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() diff --git a/lib/Controller/Aria2Controller.php b/lib/Controller/Aria2Controller.php index 446cb65..cf8fc01 100644 --- a/lib/Controller/Aria2Controller.php +++ b/lib/Controller/Aria2Controller.php @@ -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); } diff --git a/lib/Controller/MainController.php b/lib/Controller/MainController.php index 3efb80a..dddd7af 100644 --- a/lib/Controller/MainController.php +++ b/lib/Controller/MainController.php @@ -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); } /** diff --git a/lib/Controller/YoutubeController.php b/lib/Controller/YoutubeController.php index 2bd317c..4a57375 100644 --- a/lib/Controller/YoutubeController.php +++ b/lib/Controller/YoutubeController.php @@ -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(); diff --git a/lib/Tools/Counters.php b/lib/Tools/Counters.php index 6fb0c47..4ffc1bd 100644 --- a/lib/Tools/Counters.php +++ b/lib/Tools/Counters.php @@ -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; diff --git a/lib/Tools/DBConn.php b/lib/Tools/DBConn.php deleted file mode 100644 index 4509eea..0000000 --- a/lib/Tools/DBConn.php +++ /dev/null @@ -1,127 +0,0 @@ -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(); - } - -} diff --git a/lib/Tools/YoutubeHelper.php b/lib/Tools/YoutubeHelper.php index 4fe88c1..4e963e7 100644 --- a/lib/Tools/YoutubeHelper.php +++ b/lib/Tools/YoutubeHelper.php @@ -1,7 +1,7 @@ dbconn = new DBConn(); + $this->dbconn = new DbHelper(); $this->tablename = $this->dbconn->queryBuilder->getTableName("ncdownloader_info"); $this->user = \OC::$server->getUserSession()->getUser()->getUID(); }