|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Popstas\Transmission\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Martial\Transmission\API\Argument\Torrent; |
|
6
|
|
|
use Popstas\Transmission\Console\Helpers\TorrentUtils; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
12
|
|
|
|
|
13
|
|
|
class TorrentRemove extends Command |
|
14
|
|
|
{ |
|
15
|
|
View Code Duplication |
protected function configure() |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
parent::configure(); |
|
18
|
|
|
$this |
|
19
|
|
|
->setName('torrent-remove') |
|
20
|
|
|
->setAliases(['tr']) |
|
21
|
|
|
->setDescription('Remove torrents') |
|
22
|
|
|
->addArgument('torrent-ids', InputArgument::IS_ARRAY, 'List of torrent ids for remove') |
|
23
|
|
|
->addOption('soft', null, InputOption::VALUE_NONE, 'Remove only from Transmission, not delete data') |
|
24
|
|
|
->addOption('yes', 'y', InputOption::VALUE_NONE, 'Don\'t ask confirmation') |
|
25
|
|
|
->setHelp(<<<EOT |
|
26
|
|
|
The <info>torrent-remove</info> removes torrents torrents. |
|
27
|
|
|
EOT |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
|
|
$client = $this->getApplication()->getClient(); |
|
34
|
|
|
$torrentIds = $input->getArgument('torrent-ids'); |
|
35
|
|
|
$torrentList = $client->getTorrentData($torrentIds); |
|
36
|
|
|
$notExistsIds = array_diff($torrentIds, TorrentUtils::getTorrentsField($torrentList, Torrent\Get::ID)); |
|
37
|
|
|
|
|
38
|
|
|
if (count($notExistsIds)) { |
|
39
|
|
|
foreach ($notExistsIds as $notExistsId) { |
|
40
|
|
|
$output->writeln($notExistsId . ' not exists'); |
|
41
|
|
|
} |
|
42
|
|
|
return 1; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$output->writeln('Torrents for remove:'); |
|
46
|
|
|
TorrentUtils::printTorrentsTable($torrentList, $output); |
|
47
|
|
|
|
|
48
|
|
|
if (!$input->getOption('yes')) { |
|
49
|
|
|
$helper = $this->getHelper('question'); |
|
50
|
|
|
$question = new ConfirmationQuestion('Continue with this action? ', false); |
|
51
|
|
|
if (!$helper->ask($input, $output, $question)) { |
|
52
|
|
|
$output->writeln('Aborting.'); |
|
53
|
|
|
return 1; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$deleteLocalData = !$input->getOption('soft'); |
|
58
|
|
|
$client->removeTorrents($torrentList, $deleteLocalData); |
|
59
|
|
|
|
|
60
|
|
|
$output->writeln('Torrents removed.'); |
|
61
|
|
|
if (!$deleteLocalData) { |
|
62
|
|
|
$output->writeln('Data don\'t removed.'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return 0; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.