diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8fc7537 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +language: php +php: + - 7.1 + - 7.2 + +env: + global: + - APP_NAME=ocdownloader + - PHP_COVERAGE=FALSE + matrix: + - DB=sqlite SERVER=nextcloud/travis_ci/master SERVER_BRANCH=master + - DB=mysql SERVER=nextcloud/travis_ci/master SERVER_BRANCH=master PHP_COVERAGE=TRUE + - DB=pgsql SERVER=nextcloud/travis_ci/master SERVER_BRANCH=master + +matrix: + fast_finish: true + +# branches: +# only: +# - master + #- /^stable\d+(\.\d+)?$/ + +before_install: + - wget https://raw.githubusercontent.com/$SERVER/before_install.sh + - . ./before_install.sh "$APP_NAME" "$SERVER_BRANCH" "$DB" + - cd ../core || cd ../server + - php occ app:enable $APP_NAME + +before_script: + # Test lint + - cd apps/$APP_NAME + - find . -name \*.php -exec php -l "{}" \; + +script: + - echo hello test diff --git a/appinfo/info.xml b/appinfo/info.xml index 86fe89d..fec4f9b 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -17,7 +17,7 @@ https://raw.githubusercontent.com/e-alfred/ocdownloader/master/appinfo/Screenshot.jpg https://github.com/e-alfred/ - + curl ocDownloader diff --git a/appinfo/routes.php b/appinfo/routes.php index e9588f9..f31169e 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -64,7 +64,7 @@ 'ocs' => [ //API ['name' => 'Api#Handler', 'url' => '/api/handler', 'verb' => 'POST'], - ['name' => 'Api#Add', 'url' => '/api/add', 'verb' => 'POST'] + ['name' => 'Api#Add', 'url' => '/api/add', 'verb' => 'POST'], ['name' => 'Api#getQueue', 'url' => '/api/queue', 'verb' => 'POST'], ['name' => 'Api#getCount', 'url' => '/api/queue/count', 'verb' => 'POST'] ] diff --git a/controller/lib/api.php b/controller/lib/api.php index ab9af96..01934e6 100644 --- a/controller/lib/api.php +++ b/controller/lib/api.php @@ -39,6 +39,7 @@ class API public static function add($URL) { + trigger_error('Deprecated: '.__CLASS__.'::'.__FUNCTION__, E_NOTICE); try { self::load(); @@ -134,39 +135,20 @@ public static function add($URL) public static function checkAddonVersion($Version) { - $AppVersion = \OC::$server->getConfig()->getAppValue('ocdownloader', 'installed_version'); + trigger_error('Deprecated: '.__CLASS__.'::'.__FUNCTION__, E_NOTICE); + $AppVersion = \OC::$server->getConfig()->getAppValue('ocdownloader', 'installed_version'); return array('RESULT' => version_compare($Version, $AppVersion, '<=')); } public static function getQueue() { - self::load(); - - try { - $Params = array(self::$CurrentUID); - $StatusReq = '(?, ?, ?, ?, ?)'; - $Params[] = 0; - $Params[] = 1; - $Params[] = 2; - $Params[] = 3; - $Params[] = 4; - $IsCleanedReq = '(?, ?)'; - $Params[] = 0; - $Params[] = 1; - - $SQL = 'SELECT * FROM `*PREFIX*ocdownloader_queue` - WHERE `UID` = ? AND `STATUS` IN '.$StatusReq.' AND `IS_CLEANED` IN '.$IsCleanedReq - .' 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'; - } - } + trigger_error('Deprecated: '.__CLASS__.'::'.__FUNCTION__, E_NOTICE); + } public static function Handler ($URI) { + trigger_error('Deprecated: '.__CLASS__.'::'.__FUNCTION__, E_NOTICE); try { self::Load (); @@ -268,235 +250,6 @@ public static function Handler ($URI) } } - public static function CheckAddonVersion ($Version) - { - $AppVersion = Config::getAppValue ('ocdownloader', 'installed_version'); - return Array ('RESULT' => version_compare ($Version, $AppVersion, '<=')); - } - - public static function GetQueue () - { - self::Load (); - - try - { - $Params = Array (self::$CurrentUID); - $StatusReq = '(?, ?, ?, ?, ?)'; - $Params[] = 0; $Params[] = 1; $Params[] = 2; $Params[] = 3; $Params[] = 4; - $IsCleanedReq = '(?, ?)'; - $Params[] = 0; $Params[] = 1; - - $SQL = 'SELECT * FROM `*PREFIX*ocdownloader_queue` WHERE `UID` = ? AND `STATUS` IN ' . $StatusReq . ' AND `IS_CLEANED` IN ' . $IsCleanedReq . ' 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'; - } - $Query = \OCP\DB::prepare ($SQL); - $Request = $Query->execute ($Params); - - $Queue = []; - - while ($Row = $Request->fetchRow ()) - { - $Status = (self::$WhichDownloader == 0 ? Aria2::TellStatus ($Row['GID']) : CURL::TellStatus ($Row['GID'])); - $DLStatus = 5; // Error - - if (!is_null ($Status)) - { - if (!isset ($Status['error'])) - { - $Progress = 0; - if ($Status['result']['totalLength'] > 0) - { - $Progress = $Status['result']['completedLength'] / $Status['result']['totalLength']; - } - - $DLStatus = Tools::GetDownloadStatusID ($Status['result']['status']); - $ProgressString = Tools::GetProgressString ($Status['result']['completedLength'], $Status['result']['totalLength'], $Progress); - - $Queue[] = Array ( - 'GID' => $Row['GID'], - 'PROGRESSVAL' => round((($Progress) * 100), 2), - 'PROGRESS' => Array ( - 'Message' => null, - 'ProgressString' => is_null ($ProgressString) ? 'N_A' : $ProgressString, - 'NumSeeders' => isset ($Status['result']['bittorrent']) && $Progress < 1 ? $Status['result']['numSeeders'] : null, - 'UploadLength' => isset ($Status['result']['bittorrent']) && $Progress == 1 ? Tools::FormatSizeUnits ($Status['result']['uploadLength']) : null, - 'Ratio' => isset ($Status['result']['bittorrent']) ? round (($Status['result']['uploadLength'] / $Status['result']['completedLength']), 2) : null - ), - 'STATUS' => Array ( - 'Value' => isset ($Status['result']['status']) ? ($Row['STATUS'] == 4 ? 'Removed' : ucfirst ($Status['result']['status'])) : 'N_A', - 'Seeding' => isset ($Status['result']['bittorrent']) && $Progress == 1 && $DLStatus != 3 ? true : false - ), - 'STATUSID' => $Row['STATUS'] == 4 ? 4 : $DLStatus, - 'SPEED' => isset ($Status['result']['downloadSpeed']) ? ($Progress == 1 ? (isset ($Status['result']['bittorrent']) ? ($Status['result']['uploadSpeed'] == 0 ? '--' : Tools::FormatSizeUnits ($Status['result']['uploadSpeed']) . '/s') : '--') : ($DLStatus == 4 ? '--' : Tools::FormatSizeUnits ($Status['result']['downloadSpeed']) . '/s')) : 'N_A', - 'FILENAME' => $Row['FILENAME'], - 'PROTO' => $Row['PROTOCOL'], - 'ISTORRENT' => isset ($Status['result']['bittorrent']), - ); - - if ($Row['STATUS'] != $DLStatus) - { - $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` 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" != ?'; - } - - $Query = \OCP\DB::prepare ($SQL); - $Result = $Query->execute (Array ( - $DLStatus, - self::$CurrentUID, - $Row['GID'], - 4 - )); - } - } - else - { - $Queue[] = Array ( - 'GID' => $Row['GID'], - 'PROGRESSVAL' => 0, - 'PROGRESS' => Array ( - 'Message' => 'ErrorGIDnotfound', - 'ProgressString' => null, - 'NumSeeders' => null, - 'UploadLength' => null, - 'Ratio' => null - ), - 'STATUS' => Array( - 'Value' => 'N_A', - 'Seeding' => null - ), - 'STATUSID' => $DLStatus, - 'SPEED' => 'N_A', - 'FILENAME' => $Row['FILENAME'], - 'PROTO' => $Row['PROTOCOL'], - 'ISTORRENT' => isset ($Status['result']['bittorrent']) - ); - } - } - - $DLStatus = Tools::getDownloadStatusID($Status['result']['status']); - $ProgressString = Tools::getProgressString( - $Status['result']['completedLength'], - $Status['result']['totalLength'], - $Progress - ); - - $Queue[] = array( - 'GID' => $Row['GID'], - 'PROGRESSVAL' => round((($Progress) * 100), 2), - 'PROGRESS' => array( - 'Message' => null, - 'ProgressString' => is_null($ProgressString)?'N_A':$ProgressString, - 'NumSeeders' => isset($Status['result']['bittorrent']) && $Progress < 1?$Status['result']['numSeeders']:null, - 'UploadLength' => isset($Status['result']['bittorrent']) && $Progress == 1?Tools::formatSizeUnits($Status['result']['uploadLength']):null, - 'Ratio' => isset($Status['result']['bittorrent'])?round(($Status['result']['uploadLength'] / $Status['result']['completedLength']), 2):null - ), - 'STATUS' => array( - 'Value' => isset($Status['result']['status']) ?($Row['STATUS'] == 4?'Removed':ucfirst($Status['result']['status'])):'N_A', - 'Seeding' => isset($Status['result']['bittorrent']) && $Progress == 1 && $DLStatus != 3?true:false - ), - 'STATUSID' => $Row['STATUS'] == 4?4:$DLStatus, - 'SPEED' => isset($Status['result']['downloadSpeed']) - ?($Progress == 1 - ?(isset($Status['result']['bittorrent']) - ?($Status['result']['uploadSpeed'] == 0 - ?'--' - :Tools::formatSizeUnits($Status['result']['uploadSpeed']).'/s') - :'--') - :($DLStatus == 4 - ?'--' - :Tools::formatSizeUnits($Status['result']['downloadSpeed']).'/s')) - :'N_A', - 'FILENAME' => $Row['FILENAME'], - 'PROTO' => $Row['PROTOCOL'], - 'ISTORRENT' => isset($Status['result']['bittorrent']), - ); - - if ($Row['STATUS'] != $DLStatus) { - $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` - 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" != ?'; - } - - $DownloadUpdated = true; - - $Query = \OC_DB::prepare($SQL); - $Result = $Query->execute(array( - $DLStatus, - self::$CurrentUID, - $Row['GID'], - 4 - )); - } - } else { - $Queue[] = array( - 'GID' => $Row['GID'], - 'PROGRESSVAL' => 0, - 'PROGRESS' => array( - 'Message' => 'ErrorGIDnotfound', - 'ProgressString' => null, - 'NumSeeders' => null, - 'UploadLength' => null, - 'Ratio' => null - ), - 'STATUS' => array( - 'Value' => 'N_A', - 'Seeding' => null - ), - 'STATUSID' => $DLStatus, - 'SPEED' => 'N_A', - 'FILENAME' => $Row['FILENAME'], - 'PROTO' => $Row['PROTOCOL'], - 'ISTORRENT' => isset($Status['result']['bittorrent']) - ); - } - } else { - $Queue[] = array( - 'GID' => $Row['GID'], - 'PROGRESSVAL' => 0, - 'PROGRESS' => array( - 'Message' => self::$WhichDownloader == 0 - ?'ReturnedstatusisnullIsAria2crunningasadaemon' - :'Unabletofinddownloadstatusfile', - 'ProgressString' => null, - 'NumSeeders' => null, - 'UploadLength' => null, - 'Ratio' => null - ), - 'STATUS' => array( - 'Value' => 'N_A', - 'Seeding' => null - ), - 'STATUSID' => $DLStatus, - 'SPEED' => 'N_A', - 'FILENAME' => $Row['FILENAME'], - 'PROTO' => $Row['PROTOCOL'], - 'ISTORRENT' => isset($Status['result']['bittorrent']) - ); - } - } - - // Start rescan on update - if ($DownloadUpdated) { - \OC\Files\Filesystem::touch(self::$AbsoluteDownloadsFolder . $DL['FILENAME']); - } - - return array( - 'ERROR' => false, - 'MESSAGE' => null, - 'QUEUE' => $Queue, - 'COUNTER' => Tools::getCounters(self::$DbType, self::$CurrentUID) - ); - } catch (Exception $E) { - return array('ERROR' => true, 'MESSAGE' => $E->getMessage(), 'QUEUE' => null, 'COUNTER' => null); - } - } - /********** PRIVATE STATIC METHODS **********/ private static function load() { diff --git a/lib/Backend/IBackendDownloader.php b/lib/Backend/IBackendDownloader.php index 3a80343..e85c669 100644 --- a/lib/Backend/IBackendDownloader.php +++ b/lib/Backend/IBackendDownloader.php @@ -139,11 +139,7 @@ public function add($URI, $OPTIONS) { return $DL; - } - - - } - catch (Exception $E) + } catch (Exception $E) { throw new BackendException('Unabletolaunchthedownload'); }