/**
 * This method deletes the Transmission transfer with the matching hash, without removing the data
 *
 * @return void
 * TODO: test delete :)
 */
function deleteTransmissionTransfer($uid, $hash, $deleteData = false)
{
    require_once 'inc/classes/Transmission.class.php';
    $rpc = Transmission::getInstance();
    if (isValidTransmissionTransfer($uid, $hash)) {
        $transmissionId = getTransmissionTransferIdByHash($hash);
        $response = $rpc->remove($transmissionId, $deleteData);
        if ($response['result'] != "success") {
            rpc_error("Delete failed", "", "", $response['result']);
        }
    }
    deleteTransmissionTransferFromDB($uid, $hash);
}
/**
 * deleteDataTransfer
 *
 * @param $transfer
 */
function dispatcher_deleteDataTransfer($transfer)
{
    global $cfg;
    if ($cfg["transmission_rpc_enable"] && isHash($transfer)) {
        require_once 'inc/functions/functions.rpc.transmission.php';
        if (isValidTransmissionTransfer($cfg['uid'], $transfer)) {
            deleteTransmissionTransferWithData($cfg['uid'], $transfer);
            return;
        }
    }
    // valid
    if (tfb_isValidTransfer($transfer) !== true) {
        AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer);
        @error("Invalid Transfer", "", "", array($transfer));
    }
    // client
    $client = getTransferClient($transfer);
    // ch
    $ch = ClientHandler::getInstance($client);
    // permission
    dispatcher_checkTypePermission($transfer, $ch->type, "deleteWithData");
    // is transfer running ?
    $tRunningFlag = isTransferRunning($transfer);
    if ($tRunningFlag) {
        // stop first
        $ch->stop($transfer);
        if (count($ch->messages) > 0) {
            @error("There were Problems", "", "", $ch->messages);
        }
        // is transfer running ?
        $tRunningFlag = isTransferRunning($transfer);
    }
    // if it was running... hope the thing is down...
    // only continue if it is
    if ($tRunningFlag) {
        @error("Delete with Data failed, Transfer is running and stop failed", "", "", $ch->messages);
    } else {
        // transferData
        $msgsDelete = deleteTransferData($transfer);
        if (count($msgsDelete) > 0) {
            @error("There were Problems deleting Transfer-Data", "", "", $msgsDelete);
        }
        // transfer
        $ch->delete($transfer);
        if (count($ch->messages) > 0) {
            @error("There were Problems", "", "", $ch->messages);
        }
    }
}