5 * Contains \Drupal\Console\Command\Site\StatisticsCommand.
8 namespace Drupal\Console\Command\Site;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
14 use Drupal\Console\Core\Style\DrupalStyle;
15 use Drupal\Console\Utils\DrupalApi;
16 use Drupal\Core\Entity\Query\QueryFactory;
17 use Drupal\Console\Extension\Manager;
18 use Drupal\Core\Extension\ModuleHandlerInterface;
21 * Class StatisticsCommand
23 * @package Drupal\Console\Command\Site
25 class StatisticsCommand extends Command
27 use ContainerAwareCommandTrait;
37 protected $entityQuery;
42 protected $extensionManager;
45 * @var ModuleHandlerInterface
47 protected $moduleHandler;
50 * StatisticsCommand constructor.
52 * @param DrupalApi $drupalApi
53 * @param QueryFactory $entityQuery;
54 * @param Manager $extensionManager
55 * @param ModuleHandlerInterface $moduleHandler
57 public function __construct(
59 QueryFactory $entityQuery,
60 Manager $extensionManager,
61 ModuleHandlerInterface $moduleHandler
63 $this->drupalApi = $drupalApi;
64 $this->entityQuery = $entityQuery;
65 $this->extensionManager = $extensionManager;
66 $this->moduleHandler = $moduleHandler;
67 parent::__construct();
73 public function configure()
76 ->setName('site:statistics')
77 ->setDescription($this->trans('commands.site.statistics.description'))
78 ->setHelp($this->trans('commands.site.statistics.help'));
85 protected function execute(InputInterface $input, OutputInterface $output)
87 $io = new DrupalStyle($input, $output);
89 $bundles = $this->drupalApi->getBundles();
90 foreach ($bundles as $bundleType => $bundleName) {
92 $this->trans('commands.site.statistics.messages.node-type'),
95 $statistics[$key] = $this->getNodeTypeCount($bundleType);
97 $statistics[$this->trans('commands.site.statistics.messages.comments')] = $this->getCommentCount();
98 $statistics[$this->trans('commands.site.statistics.messages.vocabulary')] = $this->getTaxonomyVocabularyCount();
99 $statistics[$this->trans('commands.site.statistics.messages.taxonomy-terms')] = $this->getTaxonomyTermCount();
100 $statistics[$this->trans('commands.site.statistics.messages.files')] = $this->getFileCount();
101 $statistics[$this->trans('commands.site.statistics.messages.users')] = $this->getUserCount();
102 $statistics[$this->trans('commands.site.statistics.messages.views')] = $this->getViewCount();
103 $statistics[$this->trans('commands.site.statistics.messages.modules-enabled')] = $this->getModuleCount(true);
104 $statistics[$this->trans('commands.site.statistics.messages.modules-disabled')] = $this->getModuleCount(false);
105 $statistics[$this->trans('commands.site.statistics.messages.themes-enabled')] = $this->getThemeCount(true);
106 $statistics[$this->trans('commands.site.statistics.messages.themes-disabled')] = $this->getThemeCount(false);
108 $this->statisticsList($io, $statistics);
116 private function getNodeTypeCount($nodeType)
118 $nodesPerType = $this->entityQuery->get('node')->condition('type', $nodeType)->count();
119 $nodes = $nodesPerType->execute();
127 private function getCommentCount()
129 if (!$this->moduleHandler->moduleExists('comment')) {
133 $entityQuery = $this->entityQuery->get('comment')->count();
134 $comments = $entityQuery->execute();
142 private function getTaxonomyVocabularyCount()
144 $entityQuery = $this->entityQuery->get('taxonomy_vocabulary')->count();
145 $vocabularies = $entityQuery->execute();
147 return $vocabularies;
153 private function getTaxonomyTermCount()
155 $entityQuery = $this->entityQuery->get('taxonomy_term')->count();
156 $terms = $entityQuery->execute();
164 private function getFileCount()
166 $entityQuery = $this->entityQuery->get('file')->count();
167 $files = $entityQuery->execute();
175 private function getUserCount()
177 $entityQuery = $this->entityQuery->get('user')->count();
178 $users = $entityQuery->execute();
184 * @param bool|TRUE $status
187 private function getModuleCount($status = true)
190 return count($this->extensionManager->discoverModules()->showCore()->showNoCore()->showInstalled()->getList());
193 return count($this->extensionManager->discoverModules()->showCore()->showNoCore()->showUninstalled()->getList());
197 * @param bool|TRUE $status
200 private function getThemeCount($status = true)
203 return count($this->extensionManager->discoverThemes()->showCore()->showNoCore()->showInstalled()->getList());
206 return count($this->extensionManager->discoverThemes()->showCore()->showNoCore()->showUninstalled()->getList());
212 private function getViewCount($status = true, $tag = 'default')
214 $entityQuery = $this->entityQuery->get('view')->condition('tag', 'default', '<>')->count();
215 $views = $entityQuery->execute();
221 * @param DrupalStyle $io
222 * @param mixed $statistics
224 private function statisticsList(DrupalStyle $io, $statistics)
227 $this->trans('commands.site.statistics.messages.stat-name'),
228 $this->trans('commands.site.statistics.messages.stat-quantity'),
232 foreach ($statistics as $type => $amount) {
239 $io->table($tableHeader, $tableRows);