protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->getApplication()->getConfig(); $logger = $this->getApplication()->getLogger(); $client = $this->getApplication()->getClient(); $torrentList = $client->getTorrentData(); $obsoleteList = TorrentListUtils::getObsoleteTorrents($torrentList); if (!empty($obsoleteList)) { $output->writeln('<comment>Found obsolete torrents, remove it using transmission-cli torrent-remove-duplicates</comment>'); return 1; } try { $influxDbClient = $this->getApplication()->getInfluxDbClient($config->get('influxdb-host'), $config->get('influxdb-port'), $config->get('influxdb-user'), $config->get('influxdb-password'), $config->get('influxdb-database')); $points = []; $transmissionHost = $config->get('transmission-host'); foreach ($torrentList as $torrent) { $age = TorrentUtils::getTorrentAge($torrent); $torrentPoint = $influxDbClient->buildPoint($torrent, $transmissionHost); if ($age) { $points[] = $torrentPoint; } else { $logger->debug('Skip point: {point}', ['point' => $torrentPoint]); } } $this->dryRun($input, $output, function () use($influxDbClient, $points) { $influxDbClient->writePoints($points); }, 'dry-run, don\'t really send points'); } catch (\Exception $e) { $logger->critical($e->getMessage()); return 1; } return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->getApplication()->getConfig(); $client = $this->getApplication()->getClient(); $torrentList = $client->getTorrentData(); $obsoleteList = TorrentListUtils::getObsoleteTorrents($torrentList); if (empty($obsoleteList)) { $output->writeln('There are no obsolete torrents in Transmission.'); return 0; } $this->dryRun($input, $output, function () use($client, $obsoleteList, $config, $input, $output) { $influxDbClient = $this->getApplication()->getInfluxDbClient($config->get('influxdb-host'), $config->get('influxdb-port'), $config->get('influxdb-user'), $config->get('influxdb-password'), $config->get('influxdb-database')); $transmissionHost = $config->get('transmission-host'); $influxDbClient->sendTorrentPoints($obsoleteList, $transmissionHost); $client->removeTorrents($obsoleteList); $names = TorrentListUtils::getArrayField($obsoleteList, Torrent\Get::NAME); $output->writeln('Removed torrents:' . implode(', ', $names)); }, 'dry-run, don\'t really remove'); $output->writeln('Found and deleted ' . count($obsoleteList) . ' obsolete torrents from transmission:'); TorrentListUtils::printTorrentsTable($obsoleteList, $output); return 0; }
public function testGetObsoleteTorrents() { $obsolete = TorrentListUtils::getObsoleteTorrents($this->expectedTorrentList); $this->assertCount(1, $obsolete); $this->assertEquals(1, $obsolete[0]['id']); }