public static function retrieveByParameters($params)
 {
     $c = new Criteria();
     $c->add(TorrentPeer::INFO_HASH, $params['info_hash']);
     $c->add(ClientPeer::PEER_ID, Client::safe_set($params['peer_id']));
     if (isset($params['key'])) {
         $c->add(ClientPeer::CLIENT_KEY, Client::safe_set($params['key']));
     } else {
         $c->add(ClientPeer::CLIENT_KEY, null, Criteria::ISNULL);
     }
     if (isset($params['tracker id'])) {
         $c->add(ClientPeer::TRACKER_ID, Client::safe_set($params['tracker id']));
     }
     $c->addJoin(TorrentPeer::ID, ClientPeer::TORRENT_ID);
     $client = self::doSelectOne($c);
     if (!$client) {
         $criteria = new Criteria();
         $criteria->add(TorrentPeer::INFO_HASH, $params['info_hash']);
         $torrent = TorrentPeer::doSelectOne($criteria);
         if ($torrent == null) {
             throw new limeException('missing-torrent', 'Torrent not found');
         }
         $client = new Client();
         $client->setTorrent($torrent);
         $client->setTrackerId(sha1(uniqid(), true));
     }
     return $client;
 }
 public function executeDelete($request)
 {
     $this->forward404Unless($request->getMethod() == sfRequest::POST);
     $id = $request->getParameter('id');
     $torrent = TorrentPeer::retrieveByPK($id);
     $this->forward404Unless($torrent);
     //$this->getUser()->setFlash('notice','Deleted torrent '.$torrent->getFile());
     $torrent->delete();
     $this->redirect('episode/edit?id=' . $torrent->getEpisodeId());
 }