|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Report; |
|
4
|
|
|
|
|
5
|
|
|
use Magento\Framework\App\Filesystem\DirectoryList; |
|
6
|
|
|
use Magento\Framework\Filesystem; |
|
7
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use Symfony\Component\Finder\Finder; |
|
11
|
|
|
|
|
12
|
|
|
class CountCommand extends AbstractMagentoCommand |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var DirectoryList |
|
16
|
|
|
*/ |
|
17
|
|
|
private $directoryList; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Filesystem |
|
21
|
|
|
*/ |
|
22
|
|
|
private $filesystem; |
|
23
|
|
|
|
|
24
|
|
|
protected function configure() |
|
25
|
|
|
{ |
|
26
|
|
|
$this |
|
27
|
|
|
->setName('dev:report:count') |
|
28
|
|
|
->setDescription('Get count of report files'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param DirectoryList $directoryList |
|
33
|
|
|
*/ |
|
34
|
|
|
public function inject( |
|
35
|
|
|
DirectoryList $directoryList, |
|
36
|
|
|
Filesystem $filesystem |
|
37
|
|
|
) { |
|
38
|
|
|
$this->directoryList = $directoryList; |
|
39
|
|
|
$this->filesystem = $filesystem; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param InputInterface $input |
|
44
|
|
|
* @param OutputInterface $output |
|
45
|
|
|
* |
|
46
|
|
|
* @return int|void |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->detectMagento($output); |
|
51
|
|
|
|
|
52
|
|
|
$directoryRead = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR); |
|
53
|
|
|
if (!$directoryRead->isDirectory('report')) { |
|
54
|
|
|
$count = 0; // currently we have no error report |
|
55
|
|
|
} else { |
|
56
|
|
|
$count = $this->getFileCount($directoryRead->getAbsolutePath('report')); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$output->writeln($count); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns the number of files in the directory. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $path Path to the directory |
|
66
|
|
|
* @return int |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function getFileCount($path) |
|
69
|
|
|
{ |
|
70
|
|
|
return Finder::create() |
|
71
|
|
|
->files() |
|
72
|
|
|
->depth(1) |
|
73
|
|
|
->ignoreUnreadableDirs(true) |
|
74
|
|
|
->in($path) |
|
75
|
|
|
->count(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|