Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 3 additions & 70 deletions module/Report/src/Listener/DatabaseUpdateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,10 @@
use Database\Model\SubDecision as DatabaseSubDecisionModel;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Report\Model\SubDecision as SubDecisionModel;
use Report\Model\SubDecision\Abrogation as ReportAbrogationModel;
use Report\Model\SubDecision\Board\Discharge as ReportBoardDischargeModel;
use Report\Model\SubDecision\Board\Installation as ReportBoardInstallationModel;
use Report\Model\SubDecision\Board\Release as ReportBoardReleaseModel;
use Report\Model\SubDecision\Discharge as ReportDischargeModel;
use Report\Model\SubDecision\Foundation as ReportFoundationModel;
use Report\Model\SubDecision\Installation as ReportInstallationModel;
use Report\Model\SubDecision\Key\Granting as ReportKeyGrantingModel;
use Report\Model\SubDecision\Key\Withdrawal as ReportKeyWithdrawalModel;
use Report\Service\Board as BoardService;
use Report\Service\Keyholder as KeyholderService;
use Report\Service\Meeting as MeetingService;
use Report\Service\Member as MemberService;
use Report\Service\Misc as MiscService;
use Report\Service\Organ as OrganService;
use Report\Service\SubDecision as SubDecisionService;

/**
* Doctrine event listener intended to automatically update reportdb.
Expand All @@ -38,12 +26,10 @@
protected static bool $isflushing = false;

public function __construct(
private readonly BoardService $boardService,
private readonly KeyholderService $keyholderService,
private readonly MeetingService $meetingService,
private readonly MemberService $memberService,
private readonly MiscService $miscService,
private readonly OrganService $organService,
private readonly SubDecisionService $subDecisionService,
private readonly EntityManager $emReport,
) {
}
Expand Down Expand Up @@ -87,9 +73,7 @@

case $entity instanceof DatabaseSubDecisionModel:
$subdecision = $this->meetingService->generateSubDecision($entity);
$this->processBoardMemberUpdates($subdecision);
$this->processKeyholderUpdates($subdecision);
$this->processOrganUpdates($subdecision);
$this->subDecisionService->generateRelated($subdecision);
$this->emReport->persist($subdecision);
break;

Expand All @@ -102,7 +86,7 @@
$this->miscService->deleteListMembership($entity);
} else {
$this->miscService->generateListMembership($entity);
}

Check failure on line 89 in module/Report/src/Listener/DatabaseUpdateListener.php

View workflow job for this annotation

GitHub Actions / Psalm

NoValue

module/Report/src/Listener/DatabaseUpdateListener.php:89:17: NoValue: All possible types for this assignment were invalidated - This may be dead code (see https://psalm.dev/179)

break;

Expand All @@ -116,55 +100,4 @@
$em->flush();
});
}

public function processOrganUpdates(SubDecisionModel $entity): void
{
switch (true) {
case $entity instanceof ReportFoundationModel:
$this->organService->generateFoundation($entity);
break;

case $entity instanceof ReportAbrogationModel:
$this->organService->generateAbrogation($entity);
break;

case $entity instanceof ReportInstallationModel:
$this->organService->generateInstallation($entity);
break;

case $entity instanceof ReportDischargeModel:
$this->organService->generateDischarge($entity);
break;
}
}

public function processKeyholderUpdates(SubDecisionModel $entity): void
{
switch (true) {
case $entity instanceof ReportKeyGrantingModel:
$this->keyholderService->generateGranting($entity);
break;

case $entity instanceof ReportKeyWithdrawalModel:
$this->keyholderService->generateWithdrawal($entity);
break;
}
}

public function processBoardMemberUpdates(SubDecisionModel $entity): void
{
switch (true) {
case $entity instanceof ReportBoardInstallationModel:
$this->boardService->generateInstallation($entity);
break;

case $entity instanceof ReportBoardReleaseModel:
$this->boardService->generateRelease($entity);
break;

case $entity instanceof ReportBoardDischargeModel:
$this->boardService->generateDischarge($entity);
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;
use Report\Listener\DatabaseUpdateListener;
use Report\Service\Board as BoardService;
use Report\Service\Keyholder as KeyholderService;
use Report\Service\Meeting as MeetingService;
use Report\Service\Member as MemberService;
use Report\Service\Misc as MiscService;
use Report\Service\Organ as OrganService;
use Report\Service\SubDecision as SubDecisionService;

class DatabaseUpdateListenerFactory implements FactoryInterface
{
Expand All @@ -25,28 +23,22 @@ public function __invoke(
$requestedName,
?array $options = null,
): DatabaseUpdateListener {
/** @var BoardService $boardService */
$boardService = $container->get(BoardService::class);
/** @var KeyholderService $keyholderService */
$keyholderService = $container->get(KeyholderService::class);
/** @var MeetingService $meetingService */
$meetingService = $container->get(MeetingService::class);
/** @var MemberService $memberService */
$memberService = $container->get(MemberService::class);
/** @var MiscService $miscService */
$miscService = $container->get(MiscService::class);
/** @var OrganService $organService */
$organService = $container->get(OrganService::class);
/** @var SubDecisionService $subDecisionService */
$subDecisionService = $container->get(SubDecisionService::class);
/** @var EntityManager $emReport */
$emReport = $container->get('doctrine.entitymanager.orm_report');

return new DatabaseUpdateListener(
$boardService,
$keyholderService,
$meetingService,
$memberService,
$miscService,
$organService,
$subDecisionService,
$emReport,
);
}
Expand Down
1 change: 1 addition & 0 deletions module/Report/src/Model/Meeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enumType: MeetingTypes::class,
#[OneToMany(
targetEntity: Decision::class,
mappedBy: 'meeting',
cascade: ['persist', 'remove'],
)]
private Collection $decisions;

Expand Down
6 changes: 0 additions & 6 deletions module/Report/src/Model/Organ.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,37 +126,31 @@ enumType: OrganTypes::class,
name: 'organ_id',
referencedColumnName: 'id',
nullable: false,
onDelete: 'CASCADE',
)]
#[InverseJoinColumn(
name: 'meeting_type',
referencedColumnName: 'meeting_type',
nullable: false,
onDelete: 'CASCADE',
)]
#[InverseJoinColumn(
name: 'meeting_number',
referencedColumnName: 'meeting_number',
nullable: false,
onDelete: 'CASCADE',
)]
#[InverseJoinColumn(
name: 'decision_point',
referencedColumnName: 'decision_point',
nullable: false,
onDelete: 'CASCADE',
)]
#[InverseJoinColumn(
name: 'decision_number',
referencedColumnName: 'decision_number',
nullable: false,
onDelete: 'CASCADE',
)]
#[InverseJoinColumn(
name: 'subdecision_sequence',
referencedColumnName: 'sequence',
nullable: false,
onDelete: 'CASCADE',
)]
private Collection $subdecisions;

Expand Down
3 changes: 3 additions & 0 deletions module/Report/src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
use Report\Service\Factory\MemberFactory as MemberServiceFactory;
use Report\Service\Factory\MiscFactory as MiscServiceFactory;
use Report\Service\Factory\OrganFactory as OrganServiceFactory;
use Report\Service\Factory\SubDecisionFactory as SubDecisionServiceFactory;
use Report\Service\Keyholder as KeyholderService;
use Report\Service\Meeting as MeetingService;
use Report\Service\Member as MemberService;
use Report\Service\Misc as MiscService;
use Report\Service\Organ as OrganService;
use Report\Service\SubDecision as SubDecisionService;

class Module
{
Expand Down Expand Up @@ -53,6 +55,7 @@ public function getServiceConfig(): array
MemberMapper::class => MemberMapperFactory::class,
MiscService::class => MiscServiceFactory::class,
OrganService::class => OrganServiceFactory::class,
SubDecisionService::class => SubDecisionServiceFactory::class,
DatabaseDeletionListener::class => DatabaseDeletionListenerFactory::class,
DatabaseUpdateListener::class => DatabaseUpdateListenerFactory::class,
],
Expand Down
3 changes: 3 additions & 0 deletions module/Report/src/Service/Factory/MeetingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;
use Report\Service\Meeting as MeetingService;
use Report\Service\SubDecision as SubDecisionService;

class MeetingFactory implements FactoryInterface
{
Expand All @@ -23,6 +24,7 @@ public function __invoke(
): MeetingService {
$translator = $container->get(MvcTranslator::class);
$meetingMapper = $container->get(MeetingMapper::class);
$subDecisionService = $container->get(SubDecisionService::class);
/** @var EntityManager $emReport */
$emReport = $container->get('doctrine.entitymanager.orm_report');
/** @var array $config */
Expand All @@ -32,6 +34,7 @@ public function __invoke(
return new MeetingService(
$translator,
$meetingMapper,
$subDecisionService,
$emReport,
$config,
$mailTransport,
Expand Down
41 changes: 41 additions & 0 deletions module/Report/src/Service/Factory/SubDecisionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Report\Service\Factory;

use Doctrine\ORM\EntityManager;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;
use Report\Service\Board as BoardService;
use Report\Service\Keyholder as KeyholderService;
use Report\Service\Organ as OrganService;
use Report\Service\SubDecision as SubDecisionService;

class SubDecisionFactory implements FactoryInterface
{
/**
* @param string $requestedName
*/
public function __invoke(
ContainerInterface $container,
$requestedName,
?array $options = null,
): SubDecisionService {
/** @var BoardService $boardService */
$boardService = $container->get(BoardService::class);
/** @var KeyholderService $keyholderService */
$keyholderService = $container->get(KeyholderService::class);
/** @var OrganService $organService */
$organService = $container->get(OrganService::class);
/** @var EntityManager $emReport */
$emReport = $container->get('doctrine.entitymanager.orm_report');

return new SubDecisionService(
$emReport,
$boardService,
$keyholderService,
$organService,
);
}
}
Loading
Loading