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; }