1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Cecil/Cecil package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Cecil\Command; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
14
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
class Clean extends Command |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
protected function configure() |
24
|
|
|
{ |
25
|
|
|
$this |
26
|
|
|
->setName('clean') |
27
|
|
|
->setDescription('Remove the output directory') |
28
|
|
|
->setDefinition( |
29
|
|
|
new InputDefinition([ |
30
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'), |
31
|
|
|
]) |
32
|
|
|
) |
33
|
|
|
->setHelp('Remove the output directory and temporary files.'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
|
|
$doSomething = false; |
42
|
|
|
|
43
|
|
|
// delete output dir |
44
|
|
|
$outputDir = (string) $this->getBuilder($output)->getConfig()->get('output.dir'); |
45
|
|
|
if ($this->fs->exists($this->getPath().'/'.self::TMP_DIR.'/output')) { |
46
|
|
|
$outputDir = file_get_contents($this->getPath().'/'.self::TMP_DIR.'/output'); |
47
|
|
|
} |
48
|
|
|
if ($this->fs->exists($this->getPath().'/'.$outputDir)) { |
49
|
|
|
$this->fs->remove($this->getPath().'/'.$outputDir); |
50
|
|
|
$output->writeln('Output directory removed.'); |
51
|
|
|
$output->writeln( |
52
|
|
|
sprintf('-> %s', $this->getPath().'/'.$outputDir), |
53
|
|
|
OutputInterface::VERBOSITY_VERBOSE |
54
|
|
|
); |
55
|
|
|
$doSomething = true; |
56
|
|
|
} |
57
|
|
|
// delete local server temp files |
58
|
|
|
if ($this->fs->exists($this->getPath().'/'.self::TMP_DIR)) { |
59
|
|
|
$this->fs->remove($this->getPath().'/'.self::TMP_DIR); |
60
|
|
|
$output->writeln('Temporary directory deleted.'); |
61
|
|
|
$output->writeln( |
62
|
|
|
sprintf('-> %s', $this->getPath().'/'.self::TMP_DIR), |
63
|
|
|
OutputInterface::VERBOSITY_VERBOSE |
64
|
|
|
); |
65
|
|
|
$doSomething = true; |
66
|
|
|
} |
67
|
|
|
// delete cache directory |
68
|
|
|
if ($this->fs->exists($this->builder->getConfig()->getCachePath())) { |
69
|
|
|
$this->fs->remove($this->builder->getConfig()->getCachePath()); |
70
|
|
|
$output->writeln('Cache directory deleted.'); |
71
|
|
|
$output->writeln( |
72
|
|
|
sprintf('-> %s', $this->builder->getConfig()->getCachePath()), |
73
|
|
|
OutputInterface::VERBOSITY_VERBOSE |
74
|
|
|
); |
75
|
|
|
$doSomething = true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if ($doSomething === false) { |
79
|
|
|
$output->writeln('Nothing to do.'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return 0; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|