diff --git a/src/bundle/DependencyInjection/EzSystemsEzSupportToolsExtension.php b/src/bundle/DependencyInjection/EzSystemsEzSupportToolsExtension.php index 4ded980f..b7ecb9f1 100644 --- a/src/bundle/DependencyInjection/EzSystemsEzSupportToolsExtension.php +++ b/src/bundle/DependencyInjection/EzSystemsEzSupportToolsExtension.php @@ -19,6 +19,8 @@ class EzSystemsEzSupportToolsExtension extends Extension implements PrependExtensionInterface { + public const METRICS_TAG = 'ibexa.system_info.metrics'; + public function getAlias() { return 'ezplatform_support_tools'; diff --git a/src/bundle/Resources/config/default_settings.yaml b/src/bundle/Resources/config/default_settings.yaml index 24e8e4d9..5b087c7a 100644 --- a/src/bundle/Resources/config/default_settings.yaml +++ b/src/bundle/Resources/config/default_settings.yaml @@ -11,9 +11,9 @@ parameters: match: SystemInfo\Identifier: 'composer' database: - template: '@@ezdesign/system_info/database.html.twig' + template: '@@ezdesign/system_info/repository.html.twig' match: - SystemInfo\Identifier: 'database' + SystemInfo\Identifier: 'repository' hardware: template: '@@ezdesign/system_info/hardware.html.twig' match: diff --git a/src/bundle/Resources/config/services.yaml b/src/bundle/Resources/config/services.yaml index 0ef79716..6269b4d8 100644 --- a/src/bundle/Resources/config/services.yaml +++ b/src/bundle/Resources/config/services.yaml @@ -10,7 +10,6 @@ parameters: support_tools.system_info.output_registry.class: EzSystems\EzSupportToolsBundle\SystemInfo\OutputFormatRegistry support_tools.system_info.ezc.wrapper.class: EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper support_tools.system_info.collector.composer.lock_file.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\JsonComposerLockSystemInfoCollector - support_tools.system_info.collector.database.doctrine.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\DoctrineDatabaseSystemInfoCollector support_tools.system_info.collector.system.ibexa.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\IbexaSystemInfoCollector support_tools.system_info.collector.hardware.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcHardwareSystemInfoCollector support_tools.system_info.collector.php.ezc.class: EzSystems\EzSupportToolsBundle\SystemInfo\Collector\EzcPhpSystemInfoCollector @@ -35,14 +34,12 @@ parameters: services: # EventSubscriber - EzSystems\EzSupportToolsBundle\EventSubscriber\AddXPoweredByHeader: arguments: ["%ezplatform_support_tools.system_info.powered_by.name%"] tags: - { name: kernel.event_subscriber } # Console - support_tools.command.dump_info: class: "%support_tools.command.dump_info.class%" arguments: @@ -62,7 +59,6 @@ services: lazy: true # SystemInfoCollectors - support_tools.system_info.collector.system.ibexa: class: '%support_tools.system_info.collector.system.ibexa.class%' arguments: @@ -80,13 +76,13 @@ services: tags: - { name: "support_tools.system_info.collector", identifier: "composer" } - support_tools.system_info.collector.database.doctrine: - class: "%support_tools.system_info.collector.database.doctrine.class%" - arguments: - - "@ezpublish.persistence.connection" + EzSystems\EzSupportToolsBundle\SystemInfo\Collector\RepositorySystemInfoCollector: lazy: true + autowire: true + arguments: + $db: '@ezpublish.persistence.connection' tags: - - { name: "support_tools.system_info.collector", identifier: "database" } + - { name: "support_tools.system_info.collector", identifier: "repository" } support_tools.system_info.collector.hardware.ezc: class: "%support_tools.system_info.collector.hardware.ezc.class%" @@ -111,8 +107,57 @@ services: - { name: "support_tools.system_info.collector", identifier: "symfony_kernel" } # SystemInfoOutputFormats - support_tools.system_info.output_format.json: class: "%support_tools.system_info.output_format.json.class%" tags: - { name: "support_tools.system_info.output_format", format: "json" } + + # Gateways + EzSystems\EzSupportTools\Storage\MetricsProvider: + alias: EzSystems\EzSupportTools\Storage\AggregateMetricsProvider + + EzSystems\EzSupportTools\Storage\AggregateMetricsProvider: + arguments: + $metrics: !tagged_locator + tag: !php/const \EzSystems\EzSupportToolsBundle\DependencyInjection\EzSystemsEzSupportToolsExtension::METRICS_TAG + index_by: identifier + + EzSystems\EzSupportTools\Storage\Metrics\RepositoryConnectionAwareMetrics: + abstract: true + arguments: + $connection: '@ezpublish.persistence.connection' + + EzSystems\EzSupportTools\Storage\Metrics\PublishedContentObjectsCountMetrics: + parent: EzSystems\EzSupportTools\Storage\Metrics\RepositoryConnectionAwareMetrics + tags: + - + name: !php/const \EzSystems\EzSupportToolsBundle\DependencyInjection\EzSystemsEzSupportToolsExtension::METRICS_TAG + identifier: published + + EzSystems\EzSupportTools\Storage\Metrics\UsersCountMetrics: + parent: EzSystems\EzSupportTools\Storage\Metrics\RepositoryConnectionAwareMetrics + tags: + - + name: !php/const \EzSystems\EzSupportToolsBundle\DependencyInjection\EzSystemsEzSupportToolsExtension::METRICS_TAG + identifier: users + + EzSystems\EzSupportTools\Storage\Metrics\DraftsCountMetrics: + parent: EzSystems\EzSupportTools\Storage\Metrics\RepositoryConnectionAwareMetrics + tags: + - + name: !php/const \EzSystems\EzSupportToolsBundle\DependencyInjection\EzSystemsEzSupportToolsExtension::METRICS_TAG + identifier: drafts + + EzSystems\EzSupportTools\Storage\Metrics\VersionsCountMetrics: + parent: EzSystems\EzSupportTools\Storage\Metrics\RepositoryConnectionAwareMetrics + tags: + - + name: !php/const \EzSystems\EzSupportToolsBundle\DependencyInjection\EzSystemsEzSupportToolsExtension::METRICS_TAG + identifier: versions + + EzSystems\EzSupportTools\Storage\Metrics\ContentTypesCountMetrics: + parent: EzSystems\EzSupportTools\Storage\Metrics\RepositoryConnectionAwareMetrics + tags: + - + name: !php/const \EzSystems\EzSupportToolsBundle\DependencyInjection\EzSystemsEzSupportToolsExtension::METRICS_TAG + identifier: content_types diff --git a/src/bundle/Resources/translations/systeminfo.en.xliff b/src/bundle/Resources/translations/systeminfo.en.xliff index cc0a0518..a6f04098 100644 --- a/src/bundle/Resources/translations/systeminfo.en.xliff +++ b/src/bundle/Resources/translations/systeminfo.en.xliff @@ -26,6 +26,36 @@ CPU key: cpu + + Repository + Repository + key: repository + + + Published content objects count + Published content objects count + key: repository.published_content_objects_count + + + Users count + Users count + key: repository.users_count + + + Drafts count + Drafts count + key: repository.drafts_count + + + Versions count + Versions count + key: repository.versions_count + + + Content Types count + Content Types count + key: repository.content_types_count + Database Database @@ -221,10 +251,10 @@ Composer key: tab.name.composer - - Database - Database - key: tab.name.database + + Repository + Repository + key: tab.name.repository Hardware diff --git a/src/bundle/Resources/views/themes/admin/system_info/database.html.twig b/src/bundle/Resources/views/themes/admin/system_info/database.html.twig deleted file mode 100644 index 8f86a925..00000000 --- a/src/bundle/Resources/views/themes/admin/system_info/database.html.twig +++ /dev/null @@ -1,29 +0,0 @@ -{% trans_default_domain "systeminfo" %} - - - -
-

{{ 'database'|trans|desc('Database') }}

-
- - - - - - - - - - - - - - - - - - - -
{{ 'database.type'|trans|desc('Type') }}{{ info.type }}
{{ 'database.name'|trans|desc('Name') }}{{ info.name }}
{{ 'database.host'|trans|desc('Host') }}{{ info.host }}
{{ 'database.username'|trans|desc('Username') }}{{ info.username }}
-
-
diff --git a/src/bundle/Resources/views/themes/admin/system_info/repository.html.twig b/src/bundle/Resources/views/themes/admin/system_info/repository.html.twig new file mode 100644 index 00000000..6975e0a0 --- /dev/null +++ b/src/bundle/Resources/views/themes/admin/system_info/repository.html.twig @@ -0,0 +1,60 @@ +{% trans_default_domain "systeminfo" %} + + + +
+

{{ 'repository'|trans|desc('Repository') }}

+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ {{ 'repository.published_content_objects_count'|trans|desc('Published content objects count') }} + {{ info.repositoryMetrics.publishedCount }}
{{ 'repository.users_count'|trans|desc('Users count') }}{{ info.repositoryMetrics.usersCount }}
{{ 'repository.drafts_count'|trans|desc('Drafts count') }}{{ info.repositoryMetrics.draftsCount }}
{{ 'repository.versions_count'|trans|desc('Versions count') }}{{ info.repositoryMetrics.versionsCount }}
{{ 'repository.content_types_count'|trans|desc('Content Types count') }}{{ info.repositoryMetrics.contentTypesCount }}
+
+
+
+

{{ 'database'|trans|desc('Database') }}

+
+ + + + + + + + + + + + + + + + + + + +
{{ 'repository.type'|trans|desc('Type') }}{{ info.type }}
{{ 'repository.name'|trans|desc('Name') }}{{ info.name }}
{{ 'repository.host'|trans|desc('Host') }}{{ info.host }}
{{ 'repository.username'|trans|desc('Username') }}{{ info.username }}
+
+
diff --git a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php index bbacb0d2..de09af2f 100644 --- a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php @@ -6,7 +6,7 @@ */ namespace EzSystems\EzSupportToolsBundle\SystemInfo\Collector; -use EzSystems\EzSupportToolsBundle\SystemInfo\Value; +use EzSystems\EzSupportToolsBundle\SystemInfo\Value\SymfonyKernelSystemInfo; use Symfony\Component\HttpKernel\Kernel; /** @@ -45,13 +45,13 @@ public function __construct(Kernel $kernel, array $bundles) /** * Collects information about the Symfony kernel. * - * @return Value\SymfonyKernelSystemInfo + * @return \EzSystems\EzSupportToolsBundle\SystemInfo\Value\SymfonyKernelSystemInfo */ - public function collect() + public function collect(): SymfonyKernelSystemInfo { ksort($this->bundles, SORT_FLAG_CASE | SORT_STRING); - return new Value\SymfonyKernelSystemInfo([ + return new SymfonyKernelSystemInfo([ 'environment' => $this->kernel->getEnvironment(), 'debugMode' => $this->kernel->isDebug(), 'version' => Kernel::VERSION, diff --git a/src/bundle/SystemInfo/Collector/DoctrineDatabaseSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/DoctrineDatabaseSystemInfoCollector.php deleted file mode 100644 index 46e27dbf..00000000 --- a/src/bundle/SystemInfo/Collector/DoctrineDatabaseSystemInfoCollector.php +++ /dev/null @@ -1,47 +0,0 @@ -connection = $db; - } - - /** - * Collects information about the database eZ Platform is using. - * - type - * - name - * - host - * - username. - * - * @return Value\DatabaseSystemInfo - */ - public function collect() - { - return new Value\DatabaseSystemInfo([ - 'type' => $this->connection->getDatabasePlatform()->getName(), - 'name' => $this->connection->getDatabase(), - 'host' => $this->connection->getHost(), - 'username' => $this->connection->getUsername(), - ]); - } -} diff --git a/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php index e8ac9d7f..7bfdf690 100644 --- a/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php @@ -7,7 +7,7 @@ namespace EzSystems\EzSupportToolsBundle\SystemInfo\Collector; use EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper; -use EzSystems\EzSupportToolsBundle\SystemInfo\Value; +use EzSystems\EzSupportToolsBundle\SystemInfo\Value\HardwareSystemInfo; /** * Collects hardware system information using zetacomponents/sysinfo. @@ -29,11 +29,11 @@ public function __construct(EzcSystemInfoWrapper $ezcSystemInfo) * - cpu information * - memory size. * - * @return Value\HardwareSystemInfo + * @return \EzSystems\EzSupportToolsBundle\SystemInfo\Value\HardwareSystemInfo */ - public function collect() + public function collect(): HardwareSystemInfo { - return new Value\HardwareSystemInfo([ + return new HardwareSystemInfo([ 'cpuType' => $this->ezcSystemInfo->cpuType, 'cpuSpeed' => $this->ezcSystemInfo->cpuSpeed, 'cpuCount' => $this->ezcSystemInfo->cpuCount, diff --git a/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php index 36624ed3..b0d7af9b 100644 --- a/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php @@ -7,7 +7,7 @@ namespace EzSystems\EzSupportToolsBundle\SystemInfo\Collector; use EzSystems\EzSupportToolsBundle\SystemInfo\EzcSystemInfoWrapper; -use EzSystems\EzSupportToolsBundle\SystemInfo\Value; +use EzSystems\EzSupportToolsBundle\SystemInfo\Value\PhpSystemInfo; /** * Collects PHP information using zetacomponents/sysinfo. @@ -29,9 +29,9 @@ public function __construct(EzcSystemInfoWrapper $ezcSystemInfo) * - php version * - php accelerator info. * - * @return Value\PhpSystemInfo + * @return \EzSystems\EzSupportToolsBundle\SystemInfo\Value\PhpSystemInfo */ - public function collect() + public function collect(): PhpSystemInfo { $properties = [ 'version' => PHP_VERSION, @@ -50,6 +50,6 @@ public function collect() ); } - return new Value\PhpSystemInfo($properties); + return new PhpSystemInfo($properties); } } diff --git a/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php index 4c421495..0c8efdc9 100644 --- a/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php @@ -7,7 +7,8 @@ namespace EzSystems\EzSupportToolsBundle\SystemInfo\Collector; use EzSystems\EzSupportToolsBundle\SystemInfo\Exception; -use EzSystems\EzSupportToolsBundle\SystemInfo\Value; +use EzSystems\EzSupportToolsBundle\SystemInfo\Value\ComposerSystemInfo; +use EzSystems\EzSupportToolsBundle\SystemInfo\Value\ComposerPackage; /** * Collects information about installed Composer packages, by reading json from composer.lock. @@ -38,7 +39,7 @@ class JsonComposerLockSystemInfoCollector implements SystemInfoCollector private $jsonFile; /** - * @var Value\ComposerSystemInfo The collected value, cached in case info is collected by other collectors. + * @var ComposerSystemInfo The collected value, cached in case info is collected by other collectors. */ private $value; @@ -53,9 +54,9 @@ public function __construct($lockFile, $jsonFile) * * @throws Exception\ComposerLockFileNotFoundException if the composer.lock file was not found. * - * @return Value\ComposerSystemInfo + * @return \EzSystems\EzSupportToolsBundle\SystemInfo\Value\ComposerSystemInfo */ - public function collect() + public function collect(): ComposerSystemInfo { if ($this->value) { return $this->value; @@ -72,7 +73,7 @@ public function collect() $lockData = json_decode(file_get_contents($this->lockFile), true); $jsonData = json_decode(file_get_contents($this->jsonFile), true); - return $this->value = new Value\ComposerSystemInfo([ + return $this->value = new ComposerSystemInfo([ 'packages' => $this->extractPackages($lockData), 'repositoryUrls' => $this->extractRepositoryUrls($jsonData), 'minimumStability' => isset($lockData['minimum-stability']) ? $lockData['minimum-stability'] : null, @@ -93,7 +94,7 @@ private function extractPackages(array $lockData): array } foreach ($lockData['packages'] as $packageData) { - $package = new Value\ComposerPackage([ + $package = new ComposerPackage([ 'name' => $packageData['name'], 'branch' => $packageData['version'], 'dateTime' => isset($packageData['time']) ? new \DateTime($packageData['time']) : null, @@ -154,9 +155,9 @@ private function extractRepositoryUrls(array $jsonData): array } /** - * @param Value\ComposerPackage $package + * @param ComposerPackage $package */ - private static function setNormalizedVersion(Value\ComposerPackage $package): void + private static function setNormalizedVersion(ComposerPackage $package): void { $version = $package->alias ? $package->alias : $package->branch; if ($version[0] === 'v') { diff --git a/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php b/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php new file mode 100644 index 00000000..1b5f7cde --- /dev/null +++ b/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php @@ -0,0 +1,70 @@ +connection = $db; + $this->metricsProvider = $metricsProvider; + } + + /** + * Collects information about the database Ibexa DXP is using. + * - type + * - name + * - host + * - username + * - repository metrics (containing count of content objects, users, drafts etc.). + * + * @return \EzSystems\EzSupportToolsBundle\SystemInfo\Value\RepositorySystemInfo + */ + public function collect(): RepositorySystemInfo + { + return new RepositorySystemInfo([ + 'type' => $this->connection->getDatabasePlatform()->getName(), + 'name' => $this->connection->getDatabase(), + 'host' => $this->connection->getHost(), + 'username' => $this->connection->getUsername(), + 'repositoryMetrics' => $this->populateRepositoryMetricsData(), + ]); + } + + private function populateRepositoryMetricsData(): RepositoryMetrics + { + return new RepositoryMetrics([ + 'publishedCount' => $this->metricsProvider->provideMetrics('published')->getValue(), + 'usersCount' => $this->metricsProvider->provideMetrics('users')->getValue(), + 'draftsCount' => $this->metricsProvider->provideMetrics('drafts')->getValue(), + 'versionsCount' => $this->metricsProvider->provideMetrics('versions')->getValue(), + 'contentTypesCount' => $this->metricsProvider->provideMetrics('content_types')->getValue(), + ]); + } +} diff --git a/src/bundle/SystemInfo/Exception/MetricsNotFoundException.php b/src/bundle/SystemInfo/Exception/MetricsNotFoundException.php new file mode 100644 index 00000000..68fa251d --- /dev/null +++ b/src/bundle/SystemInfo/Exception/MetricsNotFoundException.php @@ -0,0 +1,18 @@ +container->setParameter('kernel.project_dir', dirname(__DIR__) . '/var'); + } + + public function testLoadMetricsServices(): void + { + $services = [ + Metrics\PublishedContentObjectsCountMetrics::class => 'published', + Metrics\UsersCountMetrics::class => 'users', + Metrics\DraftsCountMetrics::class => 'drafts', + Metrics\VersionsCountMetrics::class => 'versions', + Metrics\ContentTypesCountMetrics::class => 'content_types', + ]; + + $this->load([]); + + $this->assertContainerBuilderHasAlias(MetricsProvider::class); + $this->assertContainerBuilderHasService(AggregateMetricsProvider::class); + + foreach ($services as $serviceId => $identifier) { + $this->assertContainerBuilderHasServiceDefinitionWithTag( + $serviceId, + EzSystemsEzSupportToolsExtension::METRICS_TAG, + ['identifier' => $identifier] + ); + } + } +} diff --git a/src/bundle/Tests/SystemInfo/Collector/DoctrineDatabaseSystemInfoCollectorTest.php b/src/bundle/Tests/SystemInfo/Collector/DoctrineDatabaseSystemInfoCollectorTest.php deleted file mode 100644 index 2de822cf..00000000 --- a/src/bundle/Tests/SystemInfo/Collector/DoctrineDatabaseSystemInfoCollectorTest.php +++ /dev/null @@ -1,81 +0,0 @@ -dbalConnectionMock = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); - $this->dbalPlatformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\MySqlPlatform')->getMock(); - - $this->databaseCollector = new DoctrineDatabaseSystemInfoCollector($this->dbalConnectionMock); - } - - /** - * @covers \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\DoctrineDatabaseSystemInfoCollector::collect() - */ - public function testCollect() - { - $expected = new DatabaseSystemInfo([ - 'type' => 'mysql', - 'name' => 'ezp_platform', - 'host' => 'localhost', - 'username' => 'ezp_user', - ]); - - $this->dbalConnectionMock - ->expects($this->once()) - ->method('getDatabasePlatform') - ->will($this->returnValue($this->dbalPlatformMock)); - - $this->dbalPlatformMock - ->expects($this->once()) - ->method('getName') - ->will($this->returnValue($expected->type)); - - $this->dbalConnectionMock - ->expects($this->once()) - ->method('getDatabase') - ->will($this->returnValue($expected->name)); - - $this->dbalConnectionMock - ->expects($this->once()) - ->method('getHost') - ->will($this->returnValue($expected->host)); - - $this->dbalConnectionMock - ->expects($this->once()) - ->method('getUsername') - ->will($this->returnValue($expected->username)); - - $value = $this->databaseCollector->collect(); - - self::assertInstanceOf('EzSystems\EzSupportToolsBundle\SystemInfo\Value\DatabaseSystemInfo', $value); - - self::assertEquals($expected, $value); - } -} diff --git a/src/bundle/Tests/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php b/src/bundle/Tests/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php new file mode 100644 index 00000000..d76c5c28 --- /dev/null +++ b/src/bundle/Tests/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php @@ -0,0 +1,136 @@ +dbalConnectionMock = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); + $this->dbalPlatformMock = $this->getMockBuilder(AbstractPlatform::class)->getMock(); + $this->metricsProviderMock = $this->createMock(MetricsProvider::class); + $this->metricsMock = $this->createMock(Metrics::class); + + $this->repositoryCollector = new RepositorySystemInfoCollector( + $this->dbalConnectionMock, + $this->metricsProviderMock + ); + } + + /** + * @covers \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\RepositorySystemInfoCollector::collect() + */ + public function testCollect() + { + $expected = new RepositorySystemInfo([ + 'type' => 'mysql', + 'name' => 'ezp_platform', + 'host' => 'localhost', + 'username' => 'ezp_user', + 'repositoryMetrics' => new RepositoryMetrics([ + 'publishedCount' => 10, + 'usersCount' => 5, + 'draftsCount' => 20, + 'versionsCount' => 32, + 'contentTypesCount' => 8, + ]), + ]); + + $this->dbalConnectionMock + ->expects($this->once()) + ->method('getDatabasePlatform') + ->will($this->returnValue($this->dbalPlatformMock)); + + $this->dbalPlatformMock + ->expects($this->once()) + ->method('getName') + ->will($this->returnValue($expected->type)); + + $this->dbalConnectionMock + ->expects($this->once()) + ->method('getDatabase') + ->will($this->returnValue($expected->name)); + + $this->dbalConnectionMock + ->expects($this->once()) + ->method('getHost') + ->will($this->returnValue($expected->host)); + + $this->dbalConnectionMock + ->expects($this->once()) + ->method('getUsername') + ->will($this->returnValue($expected->username)); + + $this->metricsProviderMock + ->expects($this->exactly(5)) + ->method('provideMetrics') + ->withConsecutive( + ['published'], + ['users'], + ['drafts'], + ['versions'], + ['content_types'] + ) + ->willReturnOnConsecutiveCalls( + $this->metricsMock, + $this->metricsMock, + $this->metricsMock, + $this->metricsMock, + $this->metricsMock, + ); + + $this->metricsMock + ->expects($this->exactly(5)) + ->method('getValue') + ->willReturnOnConsecutiveCalls( + $expected->repositoryMetrics->publishedCount, + $expected->repositoryMetrics->usersCount, + $expected->repositoryMetrics->draftsCount, + $expected->repositoryMetrics->versionsCount, + $expected->repositoryMetrics->contentTypesCount, + ); + + $value = $this->repositoryCollector->collect(); + + self::assertInstanceOf(RepositorySystemInfo::class, $value); + self::assertEquals($expected, $value); + } +} diff --git a/src/lib/Storage/AggregateMetricsProvider.php b/src/lib/Storage/AggregateMetricsProvider.php new file mode 100644 index 00000000..b7078b10 --- /dev/null +++ b/src/lib/Storage/AggregateMetricsProvider.php @@ -0,0 +1,39 @@ +metricsLocator = $metrics; + } + + /** + * @throws \EzSystems\EzSupportToolsBundle\SystemInfo\Exception\MetricsNotFoundException + */ + public function provideMetrics(string $identifier): Metrics + { + try { + return $this->metricsLocator->get($identifier); + } catch (ServiceNotFoundException $e) { + throw new MetricsNotFoundException($identifier, $e); + } + } +} diff --git a/src/lib/Storage/Metrics.php b/src/lib/Storage/Metrics.php new file mode 100644 index 00000000..8499a764 --- /dev/null +++ b/src/lib/Storage/Metrics.php @@ -0,0 +1,17 @@ +connection->createQueryBuilder(); + $queryBuilder + ->select($this->getCountExpression(self::ID_COLUMN)) + ->from(self::CONTENT_TYPE_TABLE) + ->where( + $queryBuilder->expr()->eq(self::VERSION_COLUMN, Type::STATUS_DEFINED) + ); + + return (int) $queryBuilder->execute()->fetchColumn(); + } +} diff --git a/src/lib/Storage/Metrics/DraftsCountMetrics.php b/src/lib/Storage/Metrics/DraftsCountMetrics.php new file mode 100644 index 00000000..d2911a21 --- /dev/null +++ b/src/lib/Storage/Metrics/DraftsCountMetrics.php @@ -0,0 +1,49 @@ +connection->createQueryBuilder(); + $expr = $queryBuilder->expr(); + + $queryBuilder + ->select($this->getCountExpression('v.id')) + ->from(self::CONTENTOBJECT_VERSION_TABLE, 'v') + ->innerJoin( + 'v', + self::CONTENTOBJECT_TABLE, + 'c', + $expr->and( + $expr->eq('c.id', 'v.contentobject_id'), + $expr->neq('c.status', ContentInfo::STATUS_TRASHED) + ) + ) + ->where( + $queryBuilder->expr()->eq('v.status', ':status') + ) + ->setParameter('status', ContentInfo::STATUS_DRAFT, ParameterType::INTEGER); + + return (int) $queryBuilder->execute()->fetchColumn(); + } +} diff --git a/src/lib/Storage/Metrics/PublishedContentObjectsCountMetrics.php b/src/lib/Storage/Metrics/PublishedContentObjectsCountMetrics.php new file mode 100644 index 00000000..0fc49630 --- /dev/null +++ b/src/lib/Storage/Metrics/PublishedContentObjectsCountMetrics.php @@ -0,0 +1,37 @@ +connection->createQueryBuilder(); + $queryBuilder + ->select($this->getCountExpression(self::ID_COLUMN)) + ->from(self::CONTENTOBJECT_TABLE) + ->where( + $queryBuilder->expr()->eq(self::STATUS_COLUMN, ContentInfo::STATUS_PUBLISHED) + ); + + return (int) $queryBuilder->execute()->fetchColumn(); + } +} diff --git a/src/lib/Storage/Metrics/RepositoryConnectionAwareMetrics.php b/src/lib/Storage/Metrics/RepositoryConnectionAwareMetrics.php new file mode 100644 index 00000000..bc566c48 --- /dev/null +++ b/src/lib/Storage/Metrics/RepositoryConnectionAwareMetrics.php @@ -0,0 +1,36 @@ +connection = $connection; + } + + /** + * @throws \Doctrine\DBAL\Exception + */ + protected function getCountExpression(string $columnName): string + { + return $this->connection->getDatabasePlatform()->getCountExpression($columnName); + } +} diff --git a/src/lib/Storage/Metrics/UsersCountMetrics.php b/src/lib/Storage/Metrics/UsersCountMetrics.php new file mode 100644 index 00000000..ffee8349 --- /dev/null +++ b/src/lib/Storage/Metrics/UsersCountMetrics.php @@ -0,0 +1,31 @@ +connection->createQueryBuilder(); + $queryBuilder + ->select($this->getCountExpression(self::CONTENTOBJECT_ID_COLUMN)) + ->from(self::USER_TABLE); + + return (int) $queryBuilder->execute()->fetchColumn(); + } +} diff --git a/src/lib/Storage/Metrics/VersionsCountMetrics.php b/src/lib/Storage/Metrics/VersionsCountMetrics.php new file mode 100644 index 00000000..39207dac --- /dev/null +++ b/src/lib/Storage/Metrics/VersionsCountMetrics.php @@ -0,0 +1,31 @@ +connection->createQueryBuilder(); + $queryBuilder + ->select($this->getCountExpression(self::ID_COLUMN)) + ->from(self::CONTENTOBJECT_VERSION_TABLE); + + return (int) $queryBuilder->execute()->fetchColumn(); + } +} diff --git a/src/lib/Storage/MetricsProvider.php b/src/lib/Storage/MetricsProvider.php new file mode 100644 index 00000000..b0703edd --- /dev/null +++ b/src/lib/Storage/MetricsProvider.php @@ -0,0 +1,17 @@ +