diff --git a/src/Bundle/ChillMainBundle/ChillMainBundle.php b/src/Bundle/ChillMainBundle/ChillMainBundle.php index 9e276311d..8e115fa4f 100644 --- a/src/Bundle/ChillMainBundle/ChillMainBundle.php +++ b/src/Bundle/ChillMainBundle/ChillMainBundle.php @@ -30,6 +30,7 @@ use Chill\MainBundle\Search\SearchApiInterface; use Chill\MainBundle\Security\ProvideRoleInterface; use Chill\MainBundle\Security\Resolver\CenterResolverInterface; use Chill\MainBundle\Security\Resolver\ScopeResolverInterface; +use Chill\MainBundle\Service\EntityInfo\ViewEntityInfoProviderInterface; use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface; use Chill\MainBundle\Templating\UI\NotificationCounterInterface; use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface; @@ -62,6 +63,8 @@ class ChillMainBundle extends Bundle ->addTag('chill_main.workflow_handler'); $container->registerForAutoconfiguration(CronJobInterface::class) ->addTag('chill_main.cron_job'); + $container->registerForAutoconfiguration(ViewEntityInfoProviderInterface::class) + ->addTag('chill_main.entity_info_provider'); $container->addCompilerPass(new SearchableServicesCompilerPass()); $container->addCompilerPass(new ConfigConsistencyCompilerPass()); diff --git a/src/Bundle/ChillMainBundle/Command/SynchronizeEntityInfoViewsCommand.php b/src/Bundle/ChillMainBundle/Command/SynchronizeEntityInfoViewsCommand.php new file mode 100644 index 000000000..c3dc8a87c --- /dev/null +++ b/src/Bundle/ChillMainBundle/Command/SynchronizeEntityInfoViewsCommand.php @@ -0,0 +1,40 @@ +setDescription('Update or create sql views which provide info for various entities'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $this->viewEntityInfoManager->synchronizeOnDB(); + + return 0; + } + +} diff --git a/src/Bundle/ChillMainBundle/Service/EntityInfo/ViewEntityInfoManager.php b/src/Bundle/ChillMainBundle/Service/EntityInfo/ViewEntityInfoManager.php new file mode 100644 index 000000000..6b7b81224 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Service/EntityInfo/ViewEntityInfoManager.php @@ -0,0 +1,48 @@ +connection->transactional(function (Connection $conn): void { + foreach ($this->vienEntityInfoProviders as $viewProvider) { + foreach ($this->createOrReplaceViewSQL($viewProvider, $viewProvider->getViewName()) as $sql) { + $conn->executeQuery($sql); + } + } + }); + } + + /** + * @return array + */ + private function createOrReplaceViewSQL(ViewEntityInfoProviderInterface $viewProvider, string $viewName): array + { + return [ + "DROP VIEW IF EXISTS {$viewName}", + sprintf("CREATE VIEW {$viewName} AS %s", $viewProvider->getViewQuery()) + ]; + } +} diff --git a/src/Bundle/ChillMainBundle/Service/EntityInfo/ViewEntityInfoProviderInterface.php b/src/Bundle/ChillMainBundle/Service/EntityInfo/ViewEntityInfoProviderInterface.php new file mode 100644 index 000000000..392c0f82c --- /dev/null +++ b/src/Bundle/ChillMainBundle/Service/EntityInfo/ViewEntityInfoProviderInterface.php @@ -0,0 +1,19 @@ +addWidgetFactory(new PersonListWidgetFactory()); $container->addCompilerPass(new AccompanyingPeriodTimelineCompilerPass()); + $container->registerForAutoconfiguration(AccompanyingPeriodInfoUnionQueryPartInterface::class) + ->addTag('chill_person.accompanying_period_info_part'); } } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodInfo.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodInfo.php new file mode 100644 index 000000000..795247eda --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodInfo.php @@ -0,0 +1,79 @@ + $query->getAccompanyingPeriodIdColumn(), + '{related_entity_column_id}' => $query->getRelatedEntityColumn(), + '{related_entity_id_column_id}' => $query->getRelatedEntityIdColumn(), + '{user_id}' => $query->getUserIdColumn(), + '{datetime}' => $query->getDateTimeColumn(), + '{discriminator}' => $query->getDiscriminator(), + '{metadata}' => $query->getMetadataColumn(), + '{from_statement}' => $query->getFromStatement(), + '{where_statement}' => '' === $query->getWhereClause() ? '' : 'WHERE '.$query->getWhereClause(), + ] + ); + } +} diff --git a/src/Bundle/ChillPersonBundle/Service/EntityInfo/AccompanyingPeriodInfoQueryPart/AccompanyingPeriodWorkEndQueryPartForAccompanyingPeriodInfo.php b/src/Bundle/ChillPersonBundle/Service/EntityInfo/AccompanyingPeriodInfoQueryPart/AccompanyingPeriodWorkEndQueryPartForAccompanyingPeriodInfo.php new file mode 100644 index 000000000..8ba9b9640 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Service/EntityInfo/AccompanyingPeriodInfoQueryPart/AccompanyingPeriodWorkEndQueryPartForAccompanyingPeriodInfo.php @@ -0,0 +1,64 @@ + $this->builder->buildQuery($part), + iterator_to_array($this->unions) + ) + ); + } + + public function getViewName(): string + { + return 'view_chill_person_accompanying_period_info'; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services.yaml b/src/Bundle/ChillPersonBundle/config/services.yaml index f989b5dda..45548d843 100644 --- a/src/Bundle/ChillPersonBundle/config/services.yaml +++ b/src/Bundle/ChillPersonBundle/config/services.yaml @@ -98,3 +98,7 @@ services: autowire: true autoconfigure: true resource: '../Workflow/' + + Chill\PersonBundle\Service\EntityInfo\AccompanyingPeriodViewEntityInfoProvider: + arguments: + $unions: !tagged_iterator chill_person.accompanying_period_info_part