Example #1
0
        // Update per torrent stats
        $sql = 'UPDATE user_torrents SET uploaded = uploaded + :uploadDiff, downloaded = downloaded + :downloadDiff WHERE torrent_id = :torrent_id AND user_id = :user_id';
        $stmt = $this->dbh->prepare($sql);
        $stmt->bindParam(':uploadDiff', $this->request->getUploaded());
        $stmt->bindValue(':downloadDiff', $this->gold ? 0 : $downloadDiff);
        $stmt->bindParam(':torrent_id', $this->torrent_id);
        $stmt->bindParam(':user_id', $this->user_id);
        if (!$stmt->execute()) {
            throw new Exception('DB error.');
        }
        // Update overall user stats
        $sql = 'UPDATE users SET uploaded = uploaded + :uploadDiff, downloaded = downloaded + :downloadDiff WHERE id = :id';
        $stmt = $this->dbh->prepare($sql);
        $stmt->bindParam(':uploadDiff', $this->request->getUploaded());
        $stmt->bindValue(':downloadDiff', $this->gold ? 0 : $downloadDiff);
        $stmt->bindParam(':id', $this->user_id);
        if (!$stmt->execute()) {
            throw new Exception('DB error.');
        }
    }
}
try {
    $request = new Request();
    $announcer = new Announcer($request);
    $announcer->processRequest();
    $announcer->sendResponse();
} catch (ExceptiĐšon $e) {
    $response = new Response();
    $response->setFailureReason($e->getMessage());
    $response->send();
}