1 | <?php |
||
8 | class SevenzCommand extends ExtractCommand |
||
9 | { |
||
10 | |||
11 | 22 | protected function configure() |
|
12 | { |
||
13 | 22 | parent::configure(); |
|
14 | |||
15 | 22 | $this->setName('7z'); |
|
16 | 22 | } |
|
17 | |||
18 | 19 | protected function isSuccessfullFinished($output) |
|
19 | { |
||
20 | 19 | return strpos($output, 'Everything is Ok') !== false; |
|
21 | } |
||
22 | |||
23 | 19 | protected function getExtractCommand($password, AbstractAdapter $source, AbstractAdapter $destination) |
|
24 | { |
||
25 | 19 | $command = new Command('7z'); |
|
26 | // Extract |
||
27 | 19 | $command->addArgument('x', false); |
|
28 | // Set all to yes |
||
29 | 19 | $command->addArgument('-y', false); |
|
30 | // Password |
||
31 | 19 | $command->addArgument('-p' . $password); |
|
32 | // Input files |
||
33 | 19 | $command->addArgument($source->applyPathPrefix('*.' . $this->getFileExtension() . '*')); |
|
34 | // Output |
||
35 | 19 | $command->addArgument('-o' . $destination->getPathPrefix()); |
|
36 | |||
37 | 19 | return $command; |
|
38 | } |
||
39 | |||
40 | 8 | protected function getFilesToDelete(AbstractAdapter $source) |
|
41 | { |
||
42 | 8 | $filesToDelete = []; |
|
43 | 8 | foreach ($source->listContents() as $file) { |
|
44 | // Multipart archives do have the naming pattern test.7z.001 |
||
45 | 8 | if (!Util::endsWith($file['path'], '.' . $this->getFileExtension()) && strpos($file['path'], '.7z.') === false) { |
|
46 | 4 | continue; |
|
47 | } |
||
48 | |||
49 | 8 | $filesToDelete[] = $file['path']; |
|
50 | } |
||
51 | 8 | return $filesToDelete; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Returns the file extension this command is processing. |
||
56 | * Subclasses can override as the 7z command can handle multiple file |
||
57 | * formats, eg. zip files. |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 10 | protected function getFileExtension() |
|
65 | } |
||
66 |