From d2679fae39b2ade41b34eb4ff8d6bfa5b86720db Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 29 Dec 2020 15:28:56 -0300 Subject: [PATCH 1/5] remove all " of colum names --- controller/btdownloader.php | 2 +- controller/ftpdownloader.php | 2 +- controller/httpdownloader.php | 2 +- controller/lib/api.php | 12 ++++++------ controller/lib/settings.php | 20 ++++++++++---------- controller/lib/tools.php | 12 ++++++------ controller/queue.php | 29 +++++++++++++++-------------- controller/ytdownloader.php | 2 +- 8 files changed, 41 insertions(+), 40 deletions(-) diff --git a/controller/btdownloader.php b/controller/btdownloader.php index 08fa43c2..162809d4 100644 --- a/controller/btdownloader.php +++ b/controller/btdownloader.php @@ -163,7 +163,7 @@ public function add() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES(?, ?, ?, ?, ?, ?)'; + (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/ftpdownloader.php b/controller/ftpdownloader.php index 45b2c56c..e567c3ff 100644 --- a/controller/ftpdownloader.php +++ b/controller/ftpdownloader.php @@ -147,7 +147,7 @@ public function add() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES(?, ?, ?, ?, ?, ?)'; + (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/httpdownloader.php b/controller/httpdownloader.php index b6358e34..38f54c3a 100644 --- a/controller/httpdownloader.php +++ b/controller/httpdownloader.php @@ -149,7 +149,7 @@ public function add() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES(?, ?, ?, ?, ?, ?)'; + (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/lib/api.php b/controller/lib/api.php index 63d9a9a0..02830d38 100644 --- a/controller/lib/api.php +++ b/controller/lib/api.php @@ -153,7 +153,7 @@ public static function add($URL) VALUES(?, ?, ?, ?, ?, ?, ?)'; if (self::$DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - ("UID", "GID", "FILENAME", "PROTOCOL", "IS_CLEANED", "STATUS", "TIMESTAMP") + (uid, gid, filename, protocol, is_cleaned, status, timestamp) VALUES(?, ?, ?, ?, ?, ?, ?)'; } @@ -216,8 +216,8 @@ public static function getQueue() .' ORDER BY `TIMESTAMP` ASC'; if (self::$DbType == 1) { $SQL = 'SELECT * FROM *PREFIX*ocdownloader_queue - WHERE "UID" = ? AND "STATUS" IN '.$StatusReq.' AND "IS_CLEANED" IN '.$IsCleanedReq - .' ORDER BY "TIMESTAMP" ASC'; + WHERE uid = ? AND status IN '.$StatusReq.' AND is_cleaned IN '.$IsCleanedReq + .' ORDER BY timestamp ASC'; } $Query = \OC_DB::prepare($SQL); $Request = $Query->execute($Params); @@ -281,7 +281,7 @@ public static function getQueue() WHERE `UID` = ? AND `GID` = ?'; if (self::$DbType == 1) { $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue - WHERE "UID" = ? AND "GID" = ?'; + WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -297,7 +297,7 @@ public static function getQueue() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if (self::DbType == 1) { $addSQL = 'INSERT INTO *PREFIX*ocdownloader_queue - ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES(?, ?, ?, ?, ?, ?)'; + (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; } $addQuery = \OC_DB::prepare($addSQL); $addQuery->execute(array( @@ -316,7 +316,7 @@ public static function getQueue() SET `STATUS` = ? WHERE `UID` = ? AND `GID` = ? AND `STATUS` != ?'; if (self::$DbType == 1) { $SQL = 'UPDATE *PREFIX*ocdownloader_queue - SET "STATUS" = ? WHERE "UID" = ? AND "GID" = ? AND "STATUS" != ?'; + SET status = ? WHERE uid = ? AND gid = ? AND status != ?'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/lib/settings.php b/controller/lib/settings.php index 4f28d7d3..28bc763b 100644 --- a/controller/lib/settings.php +++ b/controller/lib/settings.php @@ -53,8 +53,8 @@ public function checkIfKeyExists() $SQL = 'SELECT `VAL` FROM `*PREFIX*ocdownloader_'.$this->Table.'` WHERE `KEY` = ?' .(!is_null($this->UID) ? ' AND `UID` = ?' : '') . ' LIMIT 1'; if ($this->DbType == 1) { - $SQL = 'SELECT "val" FROM *PREFIX*ocdownloader_'.$this->Table.' WHERE "key" = ?' - .(!is_null($this->UID) ? ' AND "uid" = ?' : '').' LIMIT 1'; + $SQL = 'SELECT val FROM *PREFIX*ocdownloader_'.$this->Table.' WHERE key = ?' + .(!is_null($this->UID) ? ' AND uid = ?' : '').' LIMIT 1'; } $Query = \OC_DB::prepare($SQL); if (!is_null($this->UID)) { @@ -74,8 +74,8 @@ public function getValue() $SQL = 'SELECT `VAL` FROM `*PREFIX*ocdownloader_'.$this->Table.'` WHERE `KEY` = ?' .(!is_null($this->UID) ? ' AND `UID` = ?' : '').' LIMIT 1'; if ($this->DbType == 1) { - $SQL = 'SELECT "val" FROM *PREFIX*ocdownloader_'.$this->Table.' WHERE "key" = ?' - .(!is_null($this->UID) ? ' AND "uid" = ?' : '').' LIMIT 1'; + $SQL = 'SELECT val FROM *PREFIX*ocdownloader_'.$this->Table.' WHERE key = ?' + .(!is_null($this->UID) ? ' AND uid = ?' : '').' LIMIT 1'; } $Query = \OC_DB::prepare($SQL); @@ -96,8 +96,8 @@ public function getAllValues() $SQL = 'SELECT `KEY`, `VAL` FROM `*PREFIX*ocdownloader_'.$this->Table.'`' .(!is_null($this->UID) ? ' WHERE `UID` = ?' : ''); if ($this->DbType == 1) { - $SQL = 'SELECT "key", "val" FROM *PREFIX*ocdownloader_'.$this->Table.'' - .(!is_null($this->UID) ? ' WHERE "uid" = ?' : ''); + $SQL = 'SELECT key, val FROM *PREFIX*ocdownloader_'.$this->Table.'' + .(!is_null($this->UID) ? ' WHERE uid = ?' : ''); } $Query = \OC_DB::prepare($SQL); @@ -113,8 +113,8 @@ public function updateValue($Value) $SQL = 'UPDATE `*PREFIX*ocdownloader_' . $this->Table . '`SET `VAL` = ? WHERE `KEY` = ?' .(!is_null($this->UID) ? ' AND `UID` = ?' : ''); if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_' . $this->Table . 'SET "val" = ? WHERE "key" = ?' - .(!is_null($this->UID) ? ' AND "uid" = ?' : ''); + $SQL = 'UPDATE *PREFIX*ocdownloader_' . $this->Table . ' SET val = ? WHERE key = ?' + .(!is_null($this->UID) ? ' AND uid = ?' : ''); } $Query = \OC_DB::prepare($SQL); @@ -130,8 +130,8 @@ public function insertValue($Value) $SQL = 'INSERT INTO `*PREFIX*ocdownloader_'.$this->Table.'`(`KEY`, `VAL`' .(!is_null($this->UID) ? ', `UID`' : '') . ') VALUES(?, ?' .(!is_null($this->UID) ? ', ?' : '').')'; if ($this->DbType == 1) { - $SQL = 'INSERT INTO *PREFIX*ocdownloader_'.$this->Table.'("key", "val"' - .(!is_null($this->UID) ? ', "uid"' : '') . ') VALUES(?, ?' .(!is_null($this->UID) ? ', ?' : '').')'; + $SQL = 'INSERT INTO *PREFIX*ocdownloader_'.$this->Table.'(key, val' + .(!is_null($this->UID) ? ', uid' : '') . ') VALUES(?, ?' .(!is_null($this->UID) ? ', ?' : '').')'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/lib/tools.php b/controller/lib/tools.php index 4f0eaee9..82ed6f96 100644 --- a/controller/lib/tools.php +++ b/controller/lib/tools.php @@ -134,12 +134,12 @@ public static function getCounters($DbType, $UID) .'(SELECT COUNT(*) FROM `*PREFIX*ocdownloader_queue` WHERE `STATUS` = ? AND `UID` = ?) as `STOPPED`,' .'(SELECT COUNT(*) FROM `*PREFIX*ocdownloader_queue` WHERE `STATUS` = ? AND `UID` = ?) as `REMOVED`'; if ($DbType == 1) { - $SQL = 'SELECT(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE "STATUS" < ? AND "UID" = ?) as "ALL",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE "STATUS" = ? AND "UID" = ?) as "COMPLETES",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE "STATUS" = ? AND "UID" = ?) as "ACTIVES",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE "STATUS" = ? AND "UID" = ?) as "WAITINGS",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE "STATUS" = ? AND "UID" = ?) as "STOPPED",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE "STATUS" = ? AND "UID" = ?) as "REMOVED"'; + $SQL = 'SELECT(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status < ? AND uid = ?) as "ALL",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "COMPLETES",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "ACTIVES",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "WAITINGS",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "STOPPED",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "REMOVED"'; } $Query = \OC_DB::prepare($SQL); $Request = $Query->execute(array(5, $UID, 0, $UID, 1, $UID, 2, $UID, 3, $UID, 4, $UID)); diff --git a/controller/queue.php b/controller/queue.php index b51dcb4c..66c503a4 100644 --- a/controller/queue.php +++ b/controller/queue.php @@ -128,8 +128,8 @@ public function get() . $StatusReq . ' AND `IS_CLEANED` IN ' . $IsCleanedReq . ' ORDER BY `TIMESTAMP` ASC'; if ($this->DbType == 1) { - $SQL = 'SELECT * FROM *PREFIX*ocdownloader_queue WHERE "UID" = ? AND "STATUS" IN ' - . $StatusReq . ' AND "IS_CLEANED" IN ' . $IsCleanedReq . ' ORDER BY "TIMESTAMP" ASC'; + $SQL = 'SELECT * FROM *PREFIX*ocdownloader_queue WHERE uid = ? AND status IN ' + . $StatusReq . ' AND is_cleaned IN ' . $IsCleanedReq . ' ORDER BY timestamp ASC'; } $Query = \OC_DB::prepare($SQL); $Request = $Query->execute($Params); @@ -137,7 +137,8 @@ public function get() $Queue = []; $DownloadUpdated = false; while ($Row = $Request->fetchRow()) { - $Status =($this->WhichDownloader == 0 + $Row = array_change_key_case($Row, CASE_UPPER); + $Status =(!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ?Aria2::tellStatus($Row['GID']):CURL::tellStatus($Row['GID'])); $DLStatus = 5; // Error @@ -195,7 +196,7 @@ public function get() WHERE `UID` = ? AND `GID` = ?'; if ($this->$DbType == 1) { $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue - WHERE "UID" = ? AND "GID" = ?'; + WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -211,7 +212,7 @@ public function get() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if ($this->$DbType == 1) { $addSQL = 'INSERT INTO *PREFIX*ocdownloader_queue - ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") VALUES(?, ?, ?, ?, ?, ?)'; + (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; } $addQuery = \OC_DB::prepare($addSQL); $addQuery->execute(array( @@ -230,7 +231,7 @@ public function get() SET `STATUS` = ? WHERE `UID` = ? AND `GID` = ? AND `STATUS` != ?'; if ($this->DbType == 1) { $SQL = 'UPDATE *PREFIX*ocdownloader_queue - SET "STATUS" = ? WHERE "UID" = ? AND "GID" = ? AND "STATUS" != ?'; + SET status = ? WHERE uid = ? AND gid = ? AND status != ?'; } $Query = \OC_DB::prepare($SQL); @@ -335,7 +336,7 @@ public function pause() if (strcmp($Pause['result'], $_POST['GID']) == 0) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `STATUS` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET "STATUS" = ? WHERE "UID" = ? AND "GID" = ?'; + $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET status = ? WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -388,7 +389,7 @@ public function unPause() if (strcmp($UnPause['result'], $_POST['GID']) == 0) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `STATUS` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET "STATUS" = ? WHERE "UID" = ? AND "GID" = ?'; + $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET status = ? WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -433,7 +434,7 @@ public function hide() if (isset($_POST['GID']) && strlen(trim($_POST['GID'])) > 0) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `IS_CLEANED` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET "IS_CLEANED" = ? WHERE "UID" = ? AND "GID" = ?'; + $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET is_cleaned = ? WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -469,7 +470,7 @@ public function hideAll() foreach ($_POST['GIDS'] as $GID) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `IS_CLEANED` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET "IS_CLEANED" = ? WHERE "UID" = ? AND "GID" = ?'; + $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET is_cleaned = ? WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -537,7 +538,7 @@ public function remove() SET `STATUS` = ?, `IS_CLEANED` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { $SQL = 'UPDATE *PREFIX*ocdownloader_queue - SET "STATUS" = ?, "IS_CLEANED" = ? WHERE "UID" = ? AND "GID" = ?'; + SET status = ?, is_cleaned = ? WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -595,7 +596,7 @@ public function removeAll() SET `STATUS` = ?, `IS_CLEANED` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { $SQL = 'UPDATE *PREFIX*ocdownloader_queue - SET "STATUS" = ?, "IS_CLEANED" = ? WHERE "UID" = ? AND "GID" = ?'; + SET status = ?, is_cleaned = ? WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -655,7 +656,7 @@ public function completelyRemove() $SQL = 'DELETE FROM `*PREFIX*ocdownloader_queue` WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE "UID" = ? AND "GID" = ?'; + $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); @@ -703,7 +704,7 @@ public function completelyRemoveAll() $SQL = 'DELETE FROM `*PREFIX*ocdownloader_queue` WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE "UID" = ? AND "GID" = ?'; + $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE uid = ? AND gid = ?'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/ytdownloader.php b/controller/ytdownloader.php index f050f312..3c131d61 100644 --- a/controller/ytdownloader.php +++ b/controller/ytdownloader.php @@ -189,7 +189,7 @@ public function add() if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - ("UID", "GID", "FILENAME", "PROTOCOL", "STATUS", "TIMESTAMP") + (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; } From 2dd4515d0291f39c45311c591c262e385249c083 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 29 Dec 2020 15:31:42 -0300 Subject: [PATCH 2/5] Changes to prevent error --- controller/index.php | 2 +- controller/queue.php | 22 +++++++++++----------- controller/ytdownloader.php | 8 ++++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/controller/index.php b/controller/index.php index c2854ef5..ea1bd16c 100644 --- a/controller/index.php +++ b/controller/index.php @@ -49,7 +49,7 @@ public function __construct($AppName, IRequest $Request, $CurrentUID, IL10N $L10 $this->Settings = new Settings(); $this->Settings->setKey('WhichDownloader'); $this->WhichDownloader = $this->Settings->getValue(); - $this->WhichDownloader = is_null($this->WhichDownloader) ? 'ARIA2' : $this->WhichDownloader; + $this->WhichDownloader = !$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ? 'ARIA2' : $this->WhichDownloader; $this->Settings->setKey('AllowProtocolHTTP'); $this->AllowProtocolHTTP = $this->Settings->getValue(); diff --git a/controller/queue.php b/controller/queue.php index 66c503a4..15d7d5ef 100644 --- a/controller/queue.php +++ b/controller/queue.php @@ -322,7 +322,7 @@ public function pause() header( 'Content-Type: application/json; charset=utf-8'); try { - if ($this->WhichDownloader == 0) { + if (!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2') { if (isset($_POST['GID']) && strlen(trim($_POST['GID'])) > 0) { $Status = Aria2::tellStatus($_POST['GID']); @@ -375,7 +375,7 @@ public function unPause() header( 'Content-Type: application/json; charset=utf-8'); try { - if ($this->WhichDownloader == 0) { + if (!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2') { if (isset($_POST['GID']) && strlen(trim($_POST['GID'])) > 0) { $Status = Aria2::tellStatus($_POST['GID']); @@ -516,16 +516,16 @@ public function remove() try { if (isset($_POST['GID']) && strlen(trim($_POST['GID'])) > 0) { $Status =( - $this->WhichDownloader == 0 + !$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ?Aria2::tellStatus($_POST['GID']) :CURL::tellStatus($_POST['GID']) ); $Remove['result'] = $_POST['GID']; - if (!isset($Status['error']) && strcmp($Status['result']['status'], 'error') != 0 + if (!isset($Status['error']) && isset($Status['result']['status']) && strcmp($Status['result']['status'], 'error') != 0 && strcmp($Status['result']['status'], 'complete') != 0) { $Remove =( - $this->WhichDownloader == 0 + !$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ? Aria2::remove($_POST['GID']) :CURL::remove($Status['result']) ); @@ -583,12 +583,12 @@ public function removeAll() $GIDS = array(); foreach ($_POST['GIDS'] as $GID) { - $Status =($this->WhichDownloader == 0 ? Aria2::tellStatus($GID) : CURL::tellStatus($GID)); + $Status =(!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ? Aria2::tellStatus($GID) : CURL::tellStatus($GID)); $Remove = array('result' => $GID); if (!isset($Status['error']) && strcmp($Status['result']['status'], 'error') != 0 && strcmp($Status['result']['status'], 'complete') != 0) { - $Remove =($this->WhichDownloader == 0 ? Aria2::remove($GID) : CURL::remove($Status['result'])); + $Remove =(!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ? Aria2::remove($GID) : CURL::remove($Status['result'])); } if (!is_null($Remove) && strcmp($Remove['result'], $GID) == 0) { @@ -641,14 +641,14 @@ public function completelyRemove() try { if (isset($_POST['GID']) && strlen(trim($_POST['GID'])) > 0) { $Status =( - $this->WhichDownloader == 0 + !$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ?Aria2::tellStatus($_POST['GID']) :CURL::tellStatus($_POST['GID']) ); if (!isset($Status['error']) && strcmp($Status['result']['status'], 'removed') == 0) { $Remove =( - $this->WhichDownloader == 0 + !$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ? Aria2::removeDownloadResult($_POST['GID']) :CURL::removeDownloadResult($_POST['GID']) ); @@ -692,11 +692,11 @@ public function completelyRemoveAll() $GIDS = array(); foreach ($_POST['GIDS'] as $GID) { - $Status =($this->WhichDownloader == 0 ? Aria2::tellStatus($GID) : CURL::tellStatus($GID)); + $Status =(!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ? Aria2::tellStatus($GID) : CURL::tellStatus($GID)); if (!isset($Status['error']) && strcmp($Status['result']['status'], 'removed') == 0) { $Remove =( - $this->WhichDownloader == 0 + !$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ?Aria2::removeDownloadResult($GID) :CURL::removeDownloadResult($GID) ); diff --git a/controller/ytdownloader.php b/controller/ytdownloader.php index 3c131d61..f78872d4 100644 --- a/controller/ytdownloader.php +++ b/controller/ytdownloader.php @@ -178,7 +178,7 @@ public function add() $OPTIONS['max-download-limit'] = $this->MaxDownloadSpeed . 'K'; } - $AddURI =($this->WhichDownloader == 0 + $AddURI =(!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ?Aria2::addUri(array($DL['URL']), array('Params' => $OPTIONS)) :CURL::addUri($DL['URL'], $OPTIONS)); @@ -204,7 +204,11 @@ public function add() )); sleep(1); - $Status = Aria2::tellStatus($AddURI['result']); + if ($this->WhichDownloader == 'CURL') { + $Status = CURL::tellStatus($AddURI['result']); + } elseif(!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2') { + $Status = Aria2::tellStatus($AddURI['result']); + } $Progress = 0; if ($Status['result']['totalLength'] > 0) { From 269b5bc101483be9433967d9c0e00ea73ec19ea9 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 29 Dec 2020 15:32:16 -0300 Subject: [PATCH 3/5] Changes to prevent errors --- controller/queue.php | 11 +++----- controller/ytdownloader.php | 50 +++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/controller/queue.php b/controller/queue.php index 15d7d5ef..761a302a 100644 --- a/controller/queue.php +++ b/controller/queue.php @@ -135,7 +135,6 @@ public function get() $Request = $Query->execute($Params); $Queue = []; - $DownloadUpdated = false; while ($Row = $Request->fetchRow()) { $Row = array_change_key_case($Row, CASE_UPPER); $Status =(!$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' @@ -243,7 +242,8 @@ public function get() )); } - $DownloadUpdated = true; + // Start rescan on update + \OC\Files\Filesystem::touch($this->DownloadsFolder . $Row['FILENAME']); } } else { $Queue[] = array( @@ -278,11 +278,6 @@ public function get() } } - // Start rescan on update - if ($DownloadUpdated) { - \OC\Files\Filesystem::touch($this->DownloadsFolder . $Row['FILENAME']); - } - return new JSONResponse( array( 'ERROR' => false, @@ -646,7 +641,7 @@ public function completelyRemove() :CURL::tellStatus($_POST['GID']) ); - if (!isset($Status['error']) && strcmp($Status['result']['status'], 'removed') == 0) { + if (!isset($Status['error']) && isset($Status['result']['status']) && strcmp($Status['result']['status'], 'removed') == 0) { $Remove =( !$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ? Aria2::removeDownloadResult($_POST['GID']) diff --git a/controller/ytdownloader.php b/controller/ytdownloader.php index f78872d4..3ff73e32 100644 --- a/controller/ytdownloader.php +++ b/controller/ytdownloader.php @@ -211,33 +211,39 @@ public function add() } $Progress = 0; - if ($Status['result']['totalLength'] > 0) { + if (isset($Status['result']) && $Status['result']['totalLength'] > 0) { $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength']; } - $ProgressString = Tools::getProgressString( - $Status['result']['completedLength'], - $Status['result']['totalLength'], - $Progress - ); + if (isset($Status['result'])) { + $ProgressString = Tools::getProgressString( + $Status['result']['completedLength'], + $Status['result']['totalLength'], + $Progress + ); + } return new JSONResponse(array( - 'ERROR' => false, - 'MESSAGE' =>(string)$this->L10N->t('Download started'), - 'GID' => $AddURI['result'], - 'PROGRESSVAL' => round((($Progress) * 100), 2) . '%', - 'PROGRESS' => is_null($ProgressString) ?(string)$this->L10N->t('N/A') : $ProgressString, - 'STATUS' => isset($Status['result']['status']) - ?(string)$this->L10N->t(ucfirst($Status['result']['status'])) - :(string)$this->L10N->t('N/A'), - 'STATUSID' => Tools::getDownloadStatusID($Status['result']['status']), - 'SPEED' => isset($Status['result']['downloadSpeed']) - ?Tools::formatSizeUnits($Status['result']['downloadSpeed']) - .'/s' :(string)$this->L10N->t('N/A'), - 'FILENAME' =>$DL['FILENAME'], - 'FILENAME_SHORT' => Tools::getShortFilename($DL['FILENAME']), - 'PROTO' => $DL['TYPE'], - 'ISTORRENT' => false + 'ERROR' => false, + 'MESSAGE' => (string)$this->L10N->t('Download started'), + 'GID' => $AddURI['result'], + 'PROGRESSVAL' => round((($Progress) * 100), 2) . '%', + 'PROGRESS' => empty($ProgressString) + ? (string)$this->L10N->t('N/A') + : $ProgressString, + 'STATUS' => isset($Status['result']['status']) + ? (string)$this->L10N->t(ucfirst($Status['result']['status'])) + : (string)$this->L10N->t('N/A'), + 'STATUSID' => isset($Status['result']['status']) + ? Tools::getDownloadStatusID($Status['result']['status']) + : (string)$this->L10N->t('N/A'), + 'SPEED' => isset($Status['result']['downloadSpeed']) + ? Tools::formatSizeUnits($Status['result']['downloadSpeed']) . '/s' + : (string)$this->L10N->t('N/A'), + 'FILENAME' => $DL['FILENAME'], + 'FILENAME_SHORT' => Tools::getShortFilename($DL['FILENAME']), + 'PROTO' => $DL['TYPE'], + 'ISTORRENT' => false )); } else { return new JSONResponse(array( From 292ecc54d30e4f026864a7f4102782b67b0b0d80 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 29 Dec 2020 16:15:30 -0300 Subject: [PATCH 4/5] Maintain all columns in uppercase --- controller/btdownloader.php | 2 +- controller/ftpdownloader.php | 2 +- controller/httpdownloader.php | 2 +- controller/lib/api.php | 2 +- controller/lib/tools.php | 12 ++++++------ controller/queue.php | 26 +++++++++++++------------- controller/ytdownloader.php | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/controller/btdownloader.php b/controller/btdownloader.php index 162809d4..ab7eae9e 100644 --- a/controller/btdownloader.php +++ b/controller/btdownloader.php @@ -163,7 +163,7 @@ public function add() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; + (UID, GID, FILENAME, PROTOCOL, STATUS, TIMESTAMP) VALUES(?, ?, ?, ?, ?, ?)'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/ftpdownloader.php b/controller/ftpdownloader.php index e567c3ff..918e26cd 100644 --- a/controller/ftpdownloader.php +++ b/controller/ftpdownloader.php @@ -147,7 +147,7 @@ public function add() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; + (UID, GID, FILENAME, PROTOCOL, STATUS, TIMESTAMP) VALUES(?, ?, ?, ?, ?, ?)'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/httpdownloader.php b/controller/httpdownloader.php index 38f54c3a..72280826 100644 --- a/controller/httpdownloader.php +++ b/controller/httpdownloader.php @@ -149,7 +149,7 @@ public function add() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; + (UID, GID, FILENAME, PROTOCOL, STATUS, TIMESTAMP) VALUES(?, ?, ?, ?, ?, ?)'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/lib/api.php b/controller/lib/api.php index 02830d38..39e9eaeb 100644 --- a/controller/lib/api.php +++ b/controller/lib/api.php @@ -153,7 +153,7 @@ public static function add($URL) VALUES(?, ?, ?, ?, ?, ?, ?)'; if (self::$DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - (uid, gid, filename, protocol, is_cleaned, status, timestamp) + (UID, GID, FILENAME, PROTOCOL, IS_CLEANED, STATUS, TIMESTAMP) VALUES(?, ?, ?, ?, ?, ?, ?)'; } diff --git a/controller/lib/tools.php b/controller/lib/tools.php index 82ed6f96..41008c33 100644 --- a/controller/lib/tools.php +++ b/controller/lib/tools.php @@ -134,12 +134,12 @@ public static function getCounters($DbType, $UID) .'(SELECT COUNT(*) FROM `*PREFIX*ocdownloader_queue` WHERE `STATUS` = ? AND `UID` = ?) as `STOPPED`,' .'(SELECT COUNT(*) FROM `*PREFIX*ocdownloader_queue` WHERE `STATUS` = ? AND `UID` = ?) as `REMOVED`'; if ($DbType == 1) { - $SQL = 'SELECT(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status < ? AND uid = ?) as "ALL",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "COMPLETES",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "ACTIVES",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "WAITINGS",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "STOPPED",' - .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE status = ? AND uid = ?) as "REMOVED"'; + $SQL = 'SELECT(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE STATUS < ? AND UID = ?) as "ALL",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE STATUS = ? AND UID = ?) as "COMPLETES",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE STATUS = ? AND UID = ?) as "ACTIVES",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE STATUS = ? AND UID = ?) as "WAITINGS",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE STATUS = ? AND UID = ?) as "STOPPED",' + .'(SELECT COUNT(*) FROM *PREFIX*ocdownloader_queue WHERE STATUS = ? AND UID = ?) as "REMOVED"'; } $Query = \OC_DB::prepare($SQL); $Request = $Query->execute(array(5, $UID, 0, $UID, 1, $UID, 2, $UID, 3, $UID, 4, $UID)); diff --git a/controller/queue.php b/controller/queue.php index 761a302a..ef3eb58a 100644 --- a/controller/queue.php +++ b/controller/queue.php @@ -128,8 +128,8 @@ public function get() . $StatusReq . ' AND `IS_CLEANED` IN ' . $IsCleanedReq . ' ORDER BY `TIMESTAMP` ASC'; if ($this->DbType == 1) { - $SQL = 'SELECT * FROM *PREFIX*ocdownloader_queue WHERE uid = ? AND status IN ' - . $StatusReq . ' AND is_cleaned IN ' . $IsCleanedReq . ' ORDER BY timestamp ASC'; + $SQL = 'SELECT * FROM *PREFIX*ocdownloader_queue WHERE UID = ? AND STATUS IN ' + . $StatusReq . ' AND IS_CLEANED IN ' . $IsCleanedReq . ' ORDER BY TIMESTAMP ASC'; } $Query = \OC_DB::prepare($SQL); $Request = $Query->execute($Params); @@ -195,7 +195,7 @@ public function get() WHERE `UID` = ? AND `GID` = ?'; if ($this->$DbType == 1) { $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue - WHERE uid = ? AND gid = ?'; + WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); @@ -211,7 +211,7 @@ public function get() (`UID`, `GID`, `FILENAME`, `PROTOCOL`, `STATUS`, `TIMESTAMP`) VALUES(?, ?, ?, ?, ?, ?)'; if ($this->$DbType == 1) { $addSQL = 'INSERT INTO *PREFIX*ocdownloader_queue - (uid, gid, filename, protocol, status, timestamp) VALUES(?, ?, ?, ?, ?, ?)'; + (UID, GID, FILENAME, PROTOCOL, STATUS, TIMESTAMP) VALUES(?, ?, ?, ?, ?, ?)'; } $addQuery = \OC_DB::prepare($addSQL); $addQuery->execute(array( @@ -230,7 +230,7 @@ public function get() SET `STATUS` = ? WHERE `UID` = ? AND `GID` = ? AND `STATUS` != ?'; if ($this->DbType == 1) { $SQL = 'UPDATE *PREFIX*ocdownloader_queue - SET status = ? WHERE uid = ? AND gid = ? AND status != ?'; + SET STATUS = ? WHERE UID = ? AND GID = ? AND STATUS != ?'; } $Query = \OC_DB::prepare($SQL); @@ -331,7 +331,7 @@ public function pause() if (strcmp($Pause['result'], $_POST['GID']) == 0) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `STATUS` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET status = ? WHERE uid = ? AND gid = ?'; + $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET STATUS = ? WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); @@ -384,7 +384,7 @@ public function unPause() if (strcmp($UnPause['result'], $_POST['GID']) == 0) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `STATUS` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET status = ? WHERE uid = ? AND gid = ?'; + $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET STATUS = ? WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); @@ -429,7 +429,7 @@ public function hide() if (isset($_POST['GID']) && strlen(trim($_POST['GID'])) > 0) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `IS_CLEANED` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET is_cleaned = ? WHERE uid = ? AND gid = ?'; + $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET IS_CLEANED = ? WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); @@ -465,7 +465,7 @@ public function hideAll() foreach ($_POST['GIDS'] as $GID) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` SET `IS_CLEANED` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET is_cleaned = ? WHERE uid = ? AND gid = ?'; + $SQL = 'UPDATE *PREFIX*ocdownloader_queue SET IS_CLEANED = ? WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); @@ -533,7 +533,7 @@ public function remove() SET `STATUS` = ?, `IS_CLEANED` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { $SQL = 'UPDATE *PREFIX*ocdownloader_queue - SET status = ?, is_cleaned = ? WHERE uid = ? AND gid = ?'; + SET STATUS = ?, IS_CLEANED = ? WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); @@ -591,7 +591,7 @@ public function removeAll() SET `STATUS` = ?, `IS_CLEANED` = ? WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { $SQL = 'UPDATE *PREFIX*ocdownloader_queue - SET status = ?, is_cleaned = ? WHERE uid = ? AND gid = ?'; + SET STATUS = ?, IS_CLEANED = ? WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); @@ -651,7 +651,7 @@ public function completelyRemove() $SQL = 'DELETE FROM `*PREFIX*ocdownloader_queue` WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE uid = ? AND gid = ?'; + $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); @@ -699,7 +699,7 @@ public function completelyRemoveAll() $SQL = 'DELETE FROM `*PREFIX*ocdownloader_queue` WHERE `UID` = ? AND `GID` = ?'; if ($this->DbType == 1) { - $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE uid = ? AND gid = ?'; + $SQL = 'DELETE FROM *PREFIX*ocdownloader_queue WHERE UID = ? AND GID = ?'; } $Query = \OC_DB::prepare($SQL); diff --git a/controller/ytdownloader.php b/controller/ytdownloader.php index 3ff73e32..1c1fdb8f 100644 --- a/controller/ytdownloader.php +++ b/controller/ytdownloader.php @@ -189,7 +189,7 @@ public function add() if ($this->DbType == 1) { $SQL = 'INSERT INTO *PREFIX*ocdownloader_queue - (uid, gid, filename, protocol, status, timestamp) + (UID, GID, FILENAME, PROTOCOL, STATUS, TIMESTAMP) VALUES(?, ?, ?, ?, ?, ?)'; } From 0897fea2458712d11ed993ad575fa2f5a4f41c99 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 29 Dec 2020 16:47:51 -0300 Subject: [PATCH 5/5] Update index.php --- controller/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/index.php b/controller/index.php index ea1bd16c..69c06067 100644 --- a/controller/index.php +++ b/controller/index.php @@ -49,7 +49,7 @@ public function __construct($AppName, IRequest $Request, $CurrentUID, IL10N $L10 $this->Settings = new Settings(); $this->Settings->setKey('WhichDownloader'); $this->WhichDownloader = $this->Settings->getValue(); - $this->WhichDownloader = !$this->WhichDownloader || $this->WhichDownloader == 'AIRA2' ? 'ARIA2' : $this->WhichDownloader; + $this->WhichDownloader = !$this->WhichDownloader ? 'ARIA2' : $this->WhichDownloader; $this->Settings->setKey('AllowProtocolHTTP'); $this->AllowProtocolHTTP = $this->Settings->getValue();