public static function ResetAria2($DbType) { $SQL = 'SELECT * FROM `*PREFIX*ocdownloader_queue`'; if ($DbType == 1) { $SQL = 'SELECT * FROM *PREFIX*ocdownloader_queue'; } $Query = \OCP\DB::prepare($SQL); $Request = $Query->execute(); while ($Row = $Request->fetchRow()) { $Status = Aria2::TellStatus($GID); if (!isset($Status['error']) && strcmp($Status['result']['status'], 'error') != 0 && strcmp($Status['result']['status'], 'complete') != 0) { Aria2::Remove($GID); } } $Purge = Aria2::PurgeDownloadResult(); if (isset($Purge['result']) && strcmp($Purge['result'], 'OK') == 0) { $SQL = 'TRUNCATE TABLE `*PREFIX*ocdownloader_queue`'; if ($DbType == 1) { $SQL = 'TRUNCATE TABLE *PREFIX*ocdownloader_queue'; } $Query = \OCP\DB::prepare($SQL); $Request = $Query->execute(); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function RemoveAll() { \OCP\JSON::setContentTypeHeader('application/json'); try { if (isset($_POST['GIDS']) && count($_POST['GIDS']) > 0) { $GIDS = array(); foreach ($_POST['GIDS'] as $GID) { $Status = $this->WhichDownloader == 0 ? 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']); } if (!is_null($Remove) && strcmp($Remove['result'], $GID) == 0) { $SQL = 'UPDATE `*PREFIX*ocdownloader_queue` 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" = ?'; } $Query = \OCP\DB::prepare($SQL); $Result = $Query->execute(array(4, 1, $this->CurrentUID, $GID)); $GIDS[] = $GID; } } return new JSONResponse(array('ERROR' => false, 'MESSAGE' => (string) $this->L10N->t('All downloads have been removed'), 'GIDS' => $GIDS)); } else { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => (string) $this->L10N->t('No GIDS in the download queue'))); } } catch (Exception $E) { return new JSONResponse(array('ERROR' => true, 'MESSAGE' => $E->getMessage())); } }