Skip to content

Commit

Permalink
Merge pull request #1 from castorinop/CI
Browse files Browse the repository at this point in the history
check syntax and test if app can be enabled
  • Loading branch information
castorinop authored Apr 6, 2019
2 parents 8ce7284 + 207595f commit 62a0cee
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 260 deletions.
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<screenshot>https://raw.githubusercontent.com/e-alfred/ocdownloader/master/appinfo/Screenshot.jpg</screenshot>
<repository>https://github.com/e-alfred/</repository>
<dependencies>
<nextcloud min-version="14" max-version="15" />
<nextcloud min-version="14" max-version="16" />
<lib>curl</lib>
</dependencies>
<namespace>ocDownloader</namespace>
Expand Down
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
]
Expand Down
259 changes: 6 additions & 253 deletions controller/lib/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class API

public static function add($URL)
{
trigger_error('Deprecated: '.__CLASS__.'::'.__FUNCTION__, E_NOTICE);
try {
self::load();

Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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()
{
Expand Down
6 changes: 1 addition & 5 deletions lib/Backend/IBackendDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ public function add($URI, $OPTIONS) {


return $DL;
}


}
catch (Exception $E)
} catch (Exception $E)
{
throw new BackendException('Unabletolaunchthedownload');
}
Expand Down

0 comments on commit 62a0cee

Please sign in to comment.