public function testSortRowsByColumnNumber() { $data = TorrentListUtils::buildTableData($this->expectedTorrentList); $rows = $data['rows']; $sortedRows = TableUtils::sortRowsByColumnNumber($rows, 2); $sortedIds = TorrentListUtils::getArrayField($sortedRows, 1); $this->assertEquals([1, 2, 3, 4], $sortedIds); $sortedRows = TableUtils::sortRowsByColumnNumber($rows, -2); $sortedIds = TorrentListUtils::getArrayField($sortedRows, 1); $this->assertEquals([4, 3, 2, 1], $sortedIds); }
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; }
protected function execute(InputInterface $input, OutputInterface $output) { $client = $this->getApplication()->getClient(); $config = $this->getApplication()->getConfig(); $torrentIds = $input->getArgument('torrent-ids'); $torrentList = $client->getTorrentData($torrentIds); $notExistsIds = array_diff($torrentIds, TorrentListUtils::getArrayField($torrentList, Torrent\Get::ID)); if (count($notExistsIds)) { foreach ($notExistsIds as $notExistsId) { $output->writeln($notExistsId . ' not exists'); } return 1; } $output->writeln('Torrents for remove:'); TorrentListUtils::printTorrentsTable($torrentList, $output); if (!$input->getOption('yes')) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('Continue with this action? ', false); if (!$helper->ask($input, $output, $question)) { $output->writeln('Aborting.'); return 1; } } $this->dryRun($input, $output, function () use($config, $torrentList, $client, $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($torrentList, $transmissionHost); $deleteLocalData = !$input->getOption('soft'); $client->removeTorrents($torrentList, $deleteLocalData); $output->writeln('Torrents removed.'); if (!$deleteLocalData) { $output->writeln('Data don\'t removed.'); } }, 'dry-run, don\'t really remove torrents'); return 0; }
private function removeTorrents(InputInterface $input, OutputInterface $output, array $rows) { $torrentIds = TorrentListUtils::getArrayField($rows, 1); $command = $this->getApplication()->find('torrent-remove'); $arguments = array('command' => 'torrent-remove', 'torrent-ids' => $torrentIds, '--dry-run' => $input->getOption('dry-run'), '--yes' => $input->getOption('yes'), '--soft' => $input->getOption('soft')); $removeInput = new ArrayInput($arguments); return $command->run($removeInput, $output); }
public function testGetTorrentsField() { $torrentField = TorrentListUtils::getArrayField($this->expectedTorrentList, Torrent\Get::NAME); $this->assertEquals(['name.ext', 'name.ext', 'name2.ext', 'name.ext'], $torrentField); }