diff --git a/CHANGELOG.md b/CHANGELOG.md index cd58faa..2a52cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ See [keep a changelog] for information about writing changes to this log. ## [Unreleased] +* [PR-39](https://github.com/itk-dev/sysstatus/pull/39) + Prevented duplicating inactive reports and systems * [PR-38](https://github.com/itk-dev/sysstatus/pull/38) * Update importers * Add example data diff --git a/README.md b/README.md index 5ded34d..1e5ae98 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Make sure you have a set of JSON files for testing import Commands. ### Start Docker containers ```shell -docker compose up -d +docker compose up --detach docker compose exec phpfpm composer install docker compose exec phpfpm bin/console doctrine:migrations:migrate --no-interaction ``` @@ -37,7 +37,7 @@ docker compose exec phpfpm bin/console doctrine:migrations:migrate --no-interact ### Create a super admin user ```sh -docker compose exec phpfpm bin/console SuperUser +docker compose exec phpfpm bin/console app:user:create admin@example.com --password password --role=ROLE_SUPER_ADMIN ``` ### Access the site @@ -88,7 +88,7 @@ flowchart TD Theme[Theme] ThemeCategory[ThemeCategory] User[User] - + fos_user_user_group{{JoinTable: fos_user_user_group }} group_system_themes{{JoinTable: group_system_themes }} group_report_themes{{JoinTable: group_report_themes }} @@ -111,7 +111,7 @@ flowchart TD System --- |ManyToMany| SelServiceAFI Theme --- |ManyToOne| ThemeCategory - + Answers --- |ManyToOne| Question Question -- JoinCollum Answers and Question --o Answers diff --git a/Taskfile.yml b/Taskfile.yml index 73241e7..85ce32a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,7 +5,7 @@ dotenv: ['.env.local', '.env'] vars: # https://taskfile.dev/reference/templating/ - BASE_URL: '{{.TASK_BASE_URL | default .COMPOSE_SERVER_DOMAIN | default .COMPOSE_DOMAIN | default "https://hoeringsportal.local.itkdev.dk"}}' + BASE_URL: '{{.TASK_BASE_URL | default .COMPOSE_SERVER_DOMAIN | default .COMPOSE_DOMAIN | default "https://itstyr.local.itkdev.dk"}}' DOCKER_COMPOSE: '{{.TASK_DOCKER_COMPOSE | default "docker compose"}}' tasks: diff --git a/src/Service/BaseImporter.php b/src/Service/BaseImporter.php index 5759b15..0331f89 100644 --- a/src/Service/BaseImporter.php +++ b/src/Service/BaseImporter.php @@ -6,6 +6,7 @@ use App\Repository\ReportRepository; use App\Repository\SystemRepository; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; abstract class BaseImporter implements ImportInterface @@ -22,6 +23,16 @@ public function __construct( $this->url = $this->params->get('system_url') ?? ''; } + public function import(string $src, ?ProgressBar $progressBar = null): void + { + // We need to be able to find all entities during import. + $this->entityManager->getFilters()->disable('entity_active'); + + $this->doImport($src, $progressBar); + } + + abstract protected function doImport(string $src, ?ProgressBar $progressBar): void; + protected function sanitizeText(string $str): ?string { $str = strip_tags($str, '



  • '); @@ -63,9 +74,9 @@ protected function convertLink(?object $obj): ?string /** * @throws \Exception */ - protected function convertDate(string $date): \DateTime + protected function convertDate(string $date): ?\DateTimeInterface { - return new \DateTime($date); + return empty($date) ? null : new \DateTimeImmutable($date); } /** @@ -76,7 +87,7 @@ protected function convertDate(string $date): \DateTime protected function convertSystemOwner(array $systemOwner): string { if (empty($systemOwner)) { - return ''; + return ''; } return $systemOwner[0]->LookupValue ?? ''; diff --git a/src/Service/ReportImporter.php b/src/Service/ReportImporter.php index 8ca502d..5796d6c 100644 --- a/src/Service/ReportImporter.php +++ b/src/Service/ReportImporter.php @@ -7,7 +7,7 @@ class ReportImporter extends BaseImporter { - public function import(string $src, ?ProgressBar $progressBar = null): void + public function doImport(string $src, ?ProgressBar $progressBar = null): void { $json = file_get_contents($src); $entries = json_decode($json); diff --git a/src/Service/SystemImporter.php b/src/Service/SystemImporter.php index adb1d0e..2ee68fb 100644 --- a/src/Service/SystemImporter.php +++ b/src/Service/SystemImporter.php @@ -24,7 +24,7 @@ public function __construct( parent::__construct($reportRepository, $systemRepository, $groupRepository, $entityManager, $params); } - public function import(string $src, ?ProgressBar $progressBar = null): void + public function doImport(string $src, ?ProgressBar $progressBar = null): void { $json = file_get_contents($src); $entries = json_decode($json);