Skip to content

Commit b21627d

Browse files
authored
Merge pull request #49 from itk-dev/feature/detection_result_cleanup
Feature/detection result cleanup
2 parents 8c46cd1 + 15118d6 commit b21627d

40 files changed

Lines changed: 300 additions & 66 deletions

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ OIDC_CLI_LOGIN_ROUTE=OIDC_CLI_LOGIN_ROUTE_TEST
6060
VAULT_URL=https://vault.itkdev.dk
6161
VAULT_ROLE_ID="CHANGE_ME_IN_LOCAL_ENV"
6262
VAULT_SECRET_ID="CHANGE_ME_IN_LOCAL_ENV"
63+
64+
# The number of old results for each server/result-type combination
65+
APP_KEEP_RESULTS=5

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- Upgrade to: Symfony 7.2, Doctrine ORM 3.x / DBAL 4.x, Api-platform 4.0, PhpUnit 11 with dependencies
1111
- Switch to PHPStan
12+
- Added cleanup for detection results
13+
- Refactor rootDir normalization to ensure values are always normalized, fix type errors,
14+
- Fix various values not being set
1215

1316
## [1.7.0] - 2024-10-14
1417

config/services.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ services:
2727
App\Handler\DetectionResultHandlerInterface:
2828
tags: [ app.handler.detection_result_handler ]
2929

30-
App\MessageHandler\ProcessDetectionResultHandler:
31-
arguments:
32-
$resultHandlers: !tagged_iterator app.handler.detection_result_handler
33-
3430
App\EventListener\RemovedRelationsListener:
3531
tags:
3632
-
3733
name: 'doctrine.event_listener'
3834
event: 'postFlush'
3935

40-
36+
App\MessageHandler\ProcessDetectionResultHandler:
37+
arguments:
38+
$resultHandlers: !tagged_iterator app.handler.detection_result_handler
39+
$keepResults: '%env(int:APP_KEEP_RESULTS)%'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20250123132456 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('ALTER TABLE server ADD last_contact_at DATETIME NULL');
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->addSql('ALTER TABLE server DROP last_contact_at');
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20250205115916 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('ALTER TABLE package ADD suggests VARCHAR(255) DEFAULT NULL');
24+
$this->addSql('UPDATE detection_result SET root_dir = REPLACE(root_dir, \'/public\', \'\') WHERE root_dir LIKE \'%/public\'');
25+
}
26+
27+
public function down(Schema $schema): void
28+
{
29+
// this down() migration is auto-generated, please modify it to your needs
30+
$this->addSql('ALTER TABLE package DROP suggests');
31+
}
32+
}

src/Command/ReplayDetectionResultsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
117117

118118
$count = $this->entityManager->getRepository(DetectionResult::class)->count($criteria);
119119

120-
$this->entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
120+
$this->entityManager->getConnection()->getConfiguration()->setMiddlewares([new \Doctrine\DBAL\Logging\Middleware(new \Psr\Log\NullLogger())]);
121121
$iterable = $queryBuilder->getQuery()->toIterable();
122122

123123
$limit = intval($input->getOption('limit'));

src/Controller/Admin/ServerCrudController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
2424
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
2525
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
26+
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
2627
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
2728
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
2829
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
@@ -91,6 +92,7 @@ public function configureFields(string $pageName): iterable
9192
yield TextField::new('serviceDeskTicket')->setColumns(12)->hideOnIndex();
9293
yield TextareaField::new('note')->hideOnIndex()->setColumns(6);
9394
yield TextareaField::new('usedFor')->hideOnIndex()->setColumns(6);
95+
yield DateTimeField::new('lastContactAt');
9496
}
9597

9698
#[\Override]

src/Controller/Admin/SiteCrudController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Controller\Admin;
66

7+
use App\Admin\Field\AdvisoryCountField;
78
use App\Admin\Field\ConfigFilePathField;
89
use App\Admin\Field\DomainField;
910
use App\Admin\Field\RootDirField;
@@ -58,6 +59,7 @@ public function configureActions(Actions $actions): Actions
5859
public function configureFields(string $pageName): iterable
5960
{
6061
yield DomainField::new('primaryDomain')->setColumns(12);
62+
yield AdvisoryCountField::new('advisoryCount')->setLabel('Adv.');
6163
yield AssociationField::new('domains')->hideOnIndex();
6264
yield SiteTypeField::new('type')->setLabel('Stack');
6365
yield ConfigFilePathField::new('configFilePath')->setColumns(12)->hideOnIndex();

src/Entity/AbstractBaseEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#[ORM\MappedSuperclass]
1313
#[ORM\HasLifecycleCallbacks]
14-
abstract class AbstractBaseEntity
14+
abstract class AbstractBaseEntity implements \Stringable
1515
{
1616
#[ApiProperty(identifier: true)]
1717
#[ORM\Id]

src/Entity/AbstractHandlerResult.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace App\Entity;
66

7-
use App\Utils\RootDirNormalizer;
87
use Doctrine\ORM\Mapping as ORM;
98
use Symfony\Component\Serializer\Annotation\Groups;
109
use Symfony\Component\Serializer\Annotation\SerializedName;
@@ -32,7 +31,7 @@ public function getRootDir(): string
3231

3332
public function setRootDir(string $rootDir): self
3433
{
35-
$this->rootDir = RootDirNormalizer::normalize($rootDir);
34+
$this->rootDir = $rootDir;
3635

3736
return $this;
3837
}

0 commit comments

Comments
 (0)