Skip to content

Commit

Permalink
refactor: make ready for Pimcore 11
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongerig committed May 6, 2024
1 parent 2f06730 commit fb1d33a
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 72 deletions.
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
}
],
"require": {
"php": ">=8.0",
"laminas/laminas-diagnostics": "^1.24",
"pimcore/pimcore": "^10.4",
"spatie/ssl-certificate": "^2.4"
"php": ">=8.1",
"laminas/laminas-diagnostics": "^1.25",
"pimcore/pimcore": "^11.2",
"spatie/ssl-certificate": "^2.6",
"symfony/http-client": "^6.4"
},
"require-dev": {
"deployer/deployer": "^7.1",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-symfony": "^1.2",
"deployer/deployer": "^7.4",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-symfony": "^1.3",
"roave/security-advisories": "dev-latest",
"symplify/easy-coding-standard": "^11.2"
"symplify/easy-coding-standard": "^12.1"
},
"autoload": {
"psr-4": {
Expand All @@ -41,7 +42,7 @@
]
},
"branch-alias": {
"dev-main": "2.0-dev"
"dev-main": "3.0-dev"
}
}
}
17 changes: 11 additions & 6 deletions docs/00-installation-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
### Install with Composer

```
composer require instride/pimcore-monitor:^2.0
composer require instride/pimcore-monitor:^3.0
```

### Enabled the Bundle
### Loading the Bundle

You can enable the Bundle within the Pimcore Back-End or via CLI command.
Register the bundle in your `config/bundles.php` file to enable it.

```
php bin/console pimcore:bundle:enable PimcoreMonitorBundle
```php
<?php

return [
// ...
Instride\Bundle\PimcoreMonitorBundle\PimcoreMonitorBundle::class => ['all' => true],
];
```

### Report Configuration
Expand All @@ -23,7 +28,7 @@ pimcore_monitor:
report:

# API key for health report endpoint.
api_key: '<YOUR_RANDOM_BEARER_TOKEN>'
api_key: '<YOUR_RANDOM_BEARER_TOKEN>'

# Default health report API endpoint to send data to.
default_endpoint: 'https://health.example.com/report'
Expand Down
3 changes: 2 additions & 1 deletion docs/03-defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pimcore_monitor:
https_connection:
enabled: true
skip: false
host: null
mysql_version:
enabled: true
skip: false
Expand All @@ -43,7 +44,7 @@ pimcore_monitor:
php_version:
enabled: true
skip: false
version: '8.0'
version: '8.1'
operator: '>='
pimcore_areabricks:
enabled: true
Expand Down
14 changes: 10 additions & 4 deletions src/PimcoreMonitorBundle/Check/DatabaseSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Instride\Bundle\PimcoreMonitorBundle\Check;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Laminas\Diagnostics\Result\Failure;
use Laminas\Diagnostics\Result\ResultInterface;
use Laminas\Diagnostics\Result\Skip;
Expand Down Expand Up @@ -79,11 +80,16 @@ public function getLabel(): string
private function getDatabaseSize(): int
{
$query = "SELECT SUM(data_length + index_length) AS size
FROM information_schema.TABLES
GROUP BY table_schema";
$size = $this->connection->fetchAll($query);
FROM information_schema.TABLES
GROUP BY table_schema";

if (\is_array($size) && isset($size[0]['size'])) {
try {
$size = $this->connection->fetchAllAssociative($query);
} catch (Exception) {
return 0;
}

if (isset($size[0]['size'])) {
return (int) $size[0]['size'];
}

Expand Down
14 changes: 9 additions & 5 deletions src/PimcoreMonitorBundle/Check/DatabaseTableSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Instride\Bundle\PimcoreMonitorBundle\Check;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Laminas\Diagnostics\Result\Failure;
use Laminas\Diagnostics\Result\ResultInterface;
use Laminas\Diagnostics\Result\Skip;
Expand Down Expand Up @@ -106,10 +107,13 @@ private function getDatabaseTableSizes(): ?array
{
$query = "SELECT TABLE_NAME AS `table`,
(DATA_LENGTH + INDEX_LENGTH) AS `size`
FROM information_schema.TABLES
ORDER BY
(DATA_LENGTH + INDEX_LENGTH)
DESC;";
return $this->connection->fetchAll($query);
FROM information_schema.TABLES
ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC;";

try {
return $this->connection->fetchAllAssociative($query);
} catch (Exception) {
return null;
}
}
}
2 changes: 1 addition & 1 deletion src/PimcoreMonitorBundle/Check/HttpsConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function check(): ResultInterface

$host = $this->systemConfig['general']['domain'] ?? null;

if (null === $host) {
if (empty($host)) {
return new Warning('HTTPS encryption could not be checked');
}

Expand Down
2 changes: 1 addition & 1 deletion src/PimcoreMonitorBundle/Check/PimcoreAreabricks.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function check(): ResultInterface
'identifier' => $brickId,
'name' => $brick->getName(),
'description' => $brick->getDescription(),
'is_enabled' => $this->areabrickManager->isEnabled($brickId),
'is_enabled' => true, // always enabled, see https://github.com/pimcore/pimcore/pull/13393
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/PimcoreMonitorBundle/Check/PimcoreBundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function check(): ResultInterface
'identifier' => $this->pimcoreBundleManager->getBundleIdentifier($bundle),
'name' => $bundle->getNiceName(),
'version' => $bundle->getVersion(),
'is_enabled' => $this->pimcoreBundleManager->isEnabled($bundle),
'is_enabled' => true, // always enabled, see https://github.com/pimcore/pimcore/pull/13393
'is_installed' => $this->pimcoreBundleManager->isInstalled($bundle),
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/PimcoreMonitorBundle/Check/PimcoreElementCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ protected function getTableRowCount(string $tableName, string $idColumn): int
->from($tableName, 't');

try {
$count = $qb->execute()->fetchOne();
} catch (DBALException | DBALDriverException) {
$count = $qb->executeQuery()->fetchOne();
} catch (DBALException) {
$count = 0;
}

Expand Down
13 changes: 5 additions & 8 deletions src/PimcoreMonitorBundle/Command/HealthReportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$instanceId = $this->getInstanceId();
$hostDomain = $this->systemConfig['general']['domain'];
$hostDomain = $this->systemConfig['general']['domain'] ?? null;

if (null === $instanceId) {
$output->writeln('<comment>Please define the secret parameter.</comment>');
Expand Down Expand Up @@ -106,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$response = $this->httpClient->request('PUT', $input->getOption('endpoint'), [
'auth_bearer' => $this->apiKey,
'json' => [
'instance_id'=> $instanceId,
'instance_id' => $instanceId,
'checks' => $checkReporter->getResults(),
'metadata' => [
'host_domain' => $hostDomain,
Expand All @@ -120,15 +120,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
ClientExceptionInterface |
DecodingExceptionInterface |
RedirectionExceptionInterface |
ServerExceptionInterface $e
ServerExceptionInterface $exception
) {
$jsonResponse = \json_decode($response->getContent(false), true);

$output->writeln(
\sprintf(
'<error>Sending the data to the endpoint failed!</error> – %s – %s',
($jsonResponse) ? $jsonResponse['message'] : 'no json response',
$e->getMessage()
'<error>Sending the data to the endpoint failed!</error> – %s',
$exception->getMessage()
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@

namespace Instride\Bundle\PimcoreMonitorBundle\Controller\Admin;

use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Pimcore\Controller\UserAwareController;
use Pimcore\Logger;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Instride\Bundle\PimcoreMonitorBundle\Manager\RunnerManager;
use Instride\Bundle\PimcoreMonitorBundle\Reporter\ArrayReporter;

class HealthCheckController extends AdminController
class HealthCheckController extends UserAwareController
{
public function health(RunnerManager $runnerManager): JsonResponse
{
$adminUser = $this->getAdminUser();
$pimcoreUser = $this->getPimcoreUser();

// Check rights
if (!$adminUser || !$adminUser->isAdmin()) {
if (!$pimcoreUser || !$pimcoreUser->isAdmin()) {
Logger::error(
'User {user} attempted to access the system health report results, but has no permission to do so.',
['user' => $adminUser->getName()]
['user' => $pimcoreUser->getName()]
);

throw $this->createAccessDeniedHttpException();
Expand All @@ -53,13 +53,13 @@ public function health(RunnerManager $runnerManager): JsonResponse

public function status(RunnerManager $runnerManager): Response
{
$adminUser = $this->getAdminUser();
$pimcoreUser = $this->getPimcoreUser();

// Check rights
if (!$adminUser || !$adminUser->isAdmin()) {
if (!$pimcoreUser || !$pimcoreUser->isAdmin()) {
Logger::error(
'User {user} attempted to access the system health status page, but has no permission to do so.',
['user' => $adminUser->getName()]
['user' => $pimcoreUser->getName()]
);

throw $this->createAccessDeniedHttpException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private function buildChecksNode(): NodeDefinition
->end()
->scalarNode('version')
->info('The expected version.')
->defaultValue('8.0')
->defaultValue('8.1')
->isRequired()
->end()
->scalarNode('operator')
Expand Down
5 changes: 4 additions & 1 deletion src/PimcoreMonitorBundle/PimcoreMonitorBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
namespace Instride\Bundle\PimcoreMonitorBundle;

use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\PimcoreBundleAdminClassicInterface;
use Pimcore\Extension\Bundle\Traits\BundleAdminClassicTrait;
use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Instride\Bundle\PimcoreMonitorBundle\Check\CheckInterface;
use Instride\Bundle\PimcoreMonitorBundle\DependencyInjection\Compiler\CheckTagCompilerPass;

class PimcoreMonitorBundle extends AbstractPimcoreBundle
class PimcoreMonitorBundle extends AbstractPimcoreBundle implements PimcoreBundleAdminClassicInterface
{
use BundleAdminClassicTrait;
use PackageVersionTrait;

/**
Expand Down
10 changes: 6 additions & 4 deletions src/PimcoreMonitorBundle/Reporter/ArrayReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

namespace Instride\Bundle\PimcoreMonitorBundle\Reporter;

use Instride\Bundle\PimcoreMonitorBundle\Check\CheckInterface;
use Laminas\Diagnostics\Check\CheckInterface as BaseCheckInterface;
use Laminas\Diagnostics\Result\Collection as ResultsCollection;
use Laminas\Diagnostics\Result\ResultInterface;
use Laminas\Diagnostics\Result\SkipInterface;
use Laminas\Diagnostics\Result\SuccessInterface;
use Laminas\Diagnostics\Result\WarningInterface;
use Laminas\Diagnostics\Runner\Reporter\ReporterInterface;
use Pimcore\Tool\Requirements\Check;
use Instride\Bundle\PimcoreMonitorBundle\Check\CheckInterface;

class ArrayReporter implements ReporterInterface
{
Expand Down Expand Up @@ -71,8 +70,11 @@ public function onBeforeRun(BaseCheckInterface|CheckInterface $check, $checkAlia
return \in_array($checkAlias, $this->includeChecks, true);
}

public function onAfterRun(BaseCheckInterface|CheckInterface $check, ResultInterface $result, $checkAlias = null)
{
public function onAfterRun(
BaseCheckInterface|CheckInterface $check,
ResultInterface $result,
$checkAlias = null
): void {
if (!$check instanceof CheckInterface) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/PimcoreMonitorBundle/Resources/config/pimcore/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pimcore_admin:
admin_csp_header:
additional_urls:
style-src:
- 'https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css'
- 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css'
- 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css'
- 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css'
font-src:
- 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/fonts/bootstrap-icons.woff'
- 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/fonts/bootstrap-icons.woff2'
- 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/fonts/bootstrap-icons.woff'
- 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/fonts/bootstrap-icons.woff2'
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ services:
# Runner Manager
Instride\Bundle\PimcoreMonitorBundle\Manager\RunnerManager:
arguments:
- '@Symfony\Component\DependencyInjection\ContainerInterface'
- '@service_container'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.pimcore_monitor_nav_icon_health_status {
background: url(../img/monitor.svg) center center no-repeat !important;
background: url('../img/monitor.svg') center center no-repeat !important;
}
10 changes: 2 additions & 8 deletions src/PimcoreMonitorBundle/Resources/public/pimcore/js/startup.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
pimcore.registerNS('pimcore.plugin.PimcoreMonitorBundle');

pimcore.plugin.PimcoreMonitor = Class.create(pimcore.plugin.admin, {
getClassName: function () {
return 'pimcore.plugin.PimcoreMonitorBundle';
},

pimcore.plugin.PimcoreMonitor = Class.create({
initialize: function () {
pimcore.plugin.broker.registerPlugin(this);
document.addEventListener(pimcore.events.pimcoreReady, this.pimcoreReady.bind(this));
},

pimcoreReady: function () {
Expand Down
Loading

0 comments on commit fb1d33a

Please sign in to comment.