Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/Message/CacheMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CacheMessage

private UuidInterface $objectEntityId;

public function __construct(UuidInterface $actionId)
public function __construct(UuidInterface $actionId, private readonly string $application)
{
$this->objectEntityId = $actionId;

Expand All @@ -26,4 +26,10 @@ public function getObjectEntityId(): UuidInterface
return $this->objectEntityId;

}//end getObjectEntityId()

public function getApplication(): ?string
{
return $this->application;

}//end getApplication()
}//end class
8 changes: 7 additions & 1 deletion src/Message/ValueMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ValueMessage
*
* @param UuidInterface $valueId The id of the value to check./
*/
public function __construct(UuidInterface $valueId, ?UuidInterface $userId)
public function __construct(UuidInterface $valueId, ?UuidInterface $userId, private readonly string $application)
{
$this->valueId = $valueId;
$this->userId = $userId;
Expand Down Expand Up @@ -57,4 +57,10 @@ public function getUserId(): ?UuidInterface
return $this->userId;

}//end getUserId()

public function getApplication(): string
{
return $this->application;

}//end getApplication()
}//end class
4 changes: 4 additions & 0 deletions src/MessageHandler/CacheMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

private EntityManagerInterface $entityManager;

public function __construct(CacheService $cacheService, ObjectEntityRepository $repository, EntityManagerInterface $entityManager)

Check warning on line 30 in src/MessageHandler/CacheMessageHandler.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 134 characters

Check warning on line 30 in src/MessageHandler/CacheMessageHandler.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 134 characters
{
$this->cacheService = $cacheService;
$this->repository = $repository;
Expand All @@ -48,6 +48,10 @@
{
$object = $this->repository->find($message->getObjectEntityId());

if ($message->getApplication() !== null) {
$this->session->set('application', $message->getApplication());
}

try {
if ($object instanceof ObjectEntity) {
$this->cacheService->cacheObject($object);
Expand Down
4 changes: 4 additions & 0 deletions src/MessageHandler/ValueMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public function __invoke(ValueMessage $message): void
$this->session->set('valueMessageUserId', $message->getUserId()->toString());
}

if ($message->getApplication() !== null) {
$this->session->set('application', $message->getApplication());
}

try {
if ($value instanceof Value === true) {
$this->valueService->connectSubObjects($value);
Expand Down
2 changes: 2 additions & 0 deletions src/Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ private function removeDataFromCache(Collection $collection, string $type, array
$filter['_self.schema.id']['$in'][] = $schemaRef;
}

$filter['_limit'] = $collection->count($filter);

$objects = $collection->find($filter, [])->toArray();
} else {
$objects = $collection->find()->toArray();
Expand Down
10 changes: 9 additions & 1 deletion src/Service/ObjectEntityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\ObjectEntity;
use App\Entity\Organization;
use App\Entity\User;
use App\Service\ApplicationService;
use Doctrine\ORM\EntityManagerInterface;
use Ramsey\Uuid\Uuid;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
Expand Down Expand Up @@ -63,7 +64,8 @@ class ObjectEntityService
public function __construct(
EntityManagerInterface $entityManager,
Security $security,
SessionInterface $session
SessionInterface $session,
private readonly ApplicationService $applicationService
) {
$this->entityManager = $entityManager;
$this->security = $security;
Expand Down Expand Up @@ -145,6 +147,8 @@ private function setOwner(ObjectEntity $object, ?User $user): ObjectEntity
return $object;
}

$application = $this->applicationService->getApplication();

// Find the correct owner to set.
if ($user !== null) {
$owner = $user->getId()->toString();
Expand Down Expand Up @@ -175,9 +179,13 @@ private function setOrganization(ObjectEntity $object, ?User $user): ObjectEntit
return $object;
}

$application = $this->applicationService->getApplication();

// Find the correct Organization to set.
if ($user !== null && $user->getOrganization() !== null) {
$organization = $user->getOrganization();
} else if ($application !== null) {
$organization = $application->getOrganization();
} else {
// Default to the Default Organization.
$organization = $this->entityManager->getRepository('App:Organization')->findOneBy(['reference' => $this::DEFAULTS['organization']]);
Expand Down
2 changes: 1 addition & 1 deletion src/Subscriber/ActionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function handleAction(Action $action, ActionEvent $event): ActionEvent
} else {
$data = $event->getData();
unset($data['httpRequest']);
$this->messageBus->dispatch(new ActionMessage($action->getId(), $data, $currentCronJobThrow));
$this->messageBus->dispatch(new ActionMessage($action->getId(), $data, $currentCronJobThrow, $this->session->get('application')));
}

$this->handleActionIoFinish($action, $currentCronJobThrow);
Expand Down
20 changes: 17 additions & 3 deletions src/Subscriber/ObjectUriSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace CommonGateway\CoreBundle\Subscriber;

use App\Entity\ObjectEntity;
use App\Exception\GatewayException;
use App\Service\ApplicationService;
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;
Expand Down Expand Up @@ -40,7 +42,8 @@ class ObjectUriSubscriber implements EventSubscriberInterface
*/
public function __construct(
ParameterBagInterface $parameterBag,
SessionInterface $session
SessionInterface $session,
private ApplicationService $applicationService
) {
$this->parameterBag = $parameterBag;
$this->session = $session;
Expand Down Expand Up @@ -80,8 +83,19 @@ public function postPersist(LifecycleEventArgs $args): void
$object = $args->getObject();
// if this subscriber only applies to certain entity types,
if ($object instanceof ObjectEntity) {
if ($object->getUri() === null || str_contains($object->getUri(), $object->getSelf()) === false) {
$object->setUri(rtrim($this->parameterBag->get('app_url'), '/').$object->getSelf());
try {
$application = $this->applicationService->getApplication();
if ($object->getUri() === null
|| str_contains($object->getUri(), $object->getSelf()) === false
) {
$object->setUri('https://'.$application->getDomains()[0].$object->getSelf());
}
} catch (GatewayException $exception) {
if ($object->getUri() === null
|| str_contains($object->getUri(), $object->getSelf()) === false
) {
$object->setUri(rtrim($this->parameterBag->get('app_url'), '/').$object->getSelf());
}
}

return;
Expand Down
2 changes: 1 addition & 1 deletion src/Subscriber/ValueSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function postUpdate(LifecycleEventArgs $value): void
$userId = Uuid::fromString($this->session->get('user'));
}

$this->messageBus->dispatch(new ValueMessage($value->getObject()->getId(), $userId));
$this->messageBus->dispatch(new ValueMessage($value->getObject()->getId(), $userId, $this->session->get('application')));
} catch (\Exception $exception) {
$this->logger->error("Error when trying to create a ValueMessage for Value {$value->getObject()->getId()}: ".$exception->getMessage());
}
Expand Down
Loading