/** @function TorrentGen() Inserts the new torrent or updates if it already exists. * @return $Torrent returns the torrent. */ private function TorrentGen() { $Torrent = current($this->getClass('TorrentManager')->find(array('hash' => bin2hex($_REQUEST['info_hash'])))); if (!$Torrent || !$Torrent->isValid()) { $Torrent = new Torrent(array('hash' => bin2hex($_REQUEST['info_hash']))); } else { $Torrent->set('hash', bin2hex($_REQUEST['info_hash'])); } $Torrent->save(); return $Torrent; }