Skip to content
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/autocomment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ jobs:
Please make sure you have followed our contributing guidelines. We will review it as soon as possible. In the meanwhile make sure your PR checks the following boxes
- [ ] Is based on an issue
- [ ] Has been locally tested
- [ ] Has been tested with the admin UI
- [ ] Has been tested with the admin ui
- [ ] Has been documented
- [ ] Has been discussed with the development team in an open channel
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
git config user.name "GitHub Actions"
git config user.email ""
git add docs/classes
git commit -m "Update phpdoc" || echo "No changes to commit"
git commit -m "Update phpdoc-md" || echo "No changes to commit"
git push
35 changes: 21 additions & 14 deletions Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Psr\Log\LoggerInterface;

/**
* Service to call external sources.
Expand All @@ -37,6 +38,7 @@ class CacheService
private SymfonyStyle $io;
private ParameterBagInterface $parameters;
private SerializerInterface $serializer;
private LoggerInterface $logger;

/**
* @param AuthenticationService $authenticationService
Expand Down Expand Up @@ -88,6 +90,8 @@ public function cleanup()
$filter = [];
$objects = $collection->find($filter)->toArray();
(isset($this->io) ? $this->io->writeln('Found '.count($objects).'') : '');

//$this->logger->info("Ran cache cleanup");
}

/**
Expand All @@ -107,6 +111,7 @@ public function warmup()
if (!isset($this->client)) {
(isset($this->io) ? $this->io->writeln('No cache client found, halting warmup') : '');

//$this->info->logger("Ran cache Warmup");
return Command::SUCCESS;
}

Expand Down Expand Up @@ -163,6 +168,7 @@ public function warmup()
(isset($this->io) ? $this->io->writeln(['Removing deleted objects', '============']) : '');
$this->removeDataFromCache($this->client->objects->json, 'App:ObjectEntity');

//$this->logger->info("Ran cache Warmup");
return Command::SUCCESS;
}

Expand Down Expand Up @@ -200,11 +206,6 @@ private function ioCatchException(Exception $exception)
*/
public function cacheObject(ObjectEntity $objectEntity): ObjectEntity
{
// For when we can't generate a schema for an ObjectEntity (for example setting an id on ObjectEntity created with testData)
if (!$objectEntity->getEntity()) {
return $objectEntity;
}

// Backwards compatablity
if (!isset($this->client)) {
return $objectEntity;
Expand Down Expand Up @@ -243,6 +244,8 @@ public function cacheObject(ObjectEntity $objectEntity): ObjectEntity
(isset($this->io) ? $this->io->writeln('Wrote object '.$objectEntity->getId()->toString().' of type '.$objectEntity->getEntity()->getName().' to cache') : '');
}


//$this->logger->debug("Cached object");
return $objectEntity;
}

Expand All @@ -264,6 +267,7 @@ public function removeObject(ObjectEntity $object): void
$collection = $this->client->objects->json;

$collection->findOneAndDelete(['_id'=>$id]);
//$this->logger->debug("Delete object");
}

/**
Expand Down Expand Up @@ -292,6 +296,7 @@ public function getObject(string $id)
return $this->cacheObject($object)->toArray(['embedded' => true]);
}

//$this->logger->debug("Retrieved object from cache");
return false;
}

Expand Down Expand Up @@ -366,6 +371,8 @@ public function searchObjects(string $search = null, array $filter = [], array $
$total = $collection->count($filter);

// Make sure to add the pagination properties in response

//$this->logger->debug("Searched cache for objects");
return $this->handleResultPagination($completeFilter, $results, $total);
}

Expand Down Expand Up @@ -753,27 +760,27 @@ public function cacheEndpoint(Endpoint $endpoint): Endpoint
}

if (isset($this->io)) {
$this->io->writeln('Start caching endpoint '.$endpoint->getId()->toString().' with name: '.$endpoint->getName());
$this->io->writeln('Start caching object '.$endpoint->getId()->toString());
}
$updatedEndpoint = $this->entityManager->getRepository('App:Endpoint')->find($endpoint->getId());
if ($updatedEndpoint instanceof Endpoint) {
$endpoint = $updatedEndpoint;
$updatedEntity = $this->entityManager->getRepository('App:Endpoint')->find($endpoint->getId());
if ($updatedEntity instanceof Endpoint) {
$entity = $updatedEntity;
} elseif (isset($this->io)) {
$this->io->writeln('Could not find an Endpoint with id: '.$endpoint->getId()->toString());
$this->io->writeln('Could not find an Endpoint with id: '.$objectEntity->getId()->toString());
}

$collection = $this->client->endpoints->json;

$endpointArray = $this->serializer->normalize($endpoint);
$entityArray = $this->serializer->normalize($entity);

if ($collection->findOneAndReplace(
['id' => $endpoint->getId()->toString()],
$endpointArray,
$entityArray,
['upsert'=>true]
)) {
(isset($this->io) ? $this->io->writeln('Updated endpoint '.$endpoint->getId()->toString().' to cache') : '');
(isset($this->io) ? $this->io->writeln('Updated object '.$endpoint->getId()->toString().' of type Endpoint to cache') : '');
} else {
(isset($this->io) ? $this->io->writeln('Wrote object '.$endpoint->getId()->toString().' to cache') : '');
(isset($this->io) ? $this->io->writeln('Wrote object '.$endpoint->getId()->toString().' of type Endpoint to cache') : '');
}

return $endpoint;
Expand Down
63 changes: 49 additions & 14 deletions Service/InstallationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Psr\Log\LoggerInterface;

class InstallationService
{
Expand Down Expand Up @@ -296,21 +297,11 @@ public function handleData($file)
if (array_key_exists('_id', $object) && $objectEntity = $this->em->getRepository('App:ObjectEntity')->findOneBy(['id' => $object['_id']])) {
$this->io->writeln(['', 'Object '.$object['_id'].' already exists, so updating']);
} elseif (array_key_exists('_id', $object)) {
$this->io->writeln('Set id to '.$object['_id']);

// Nice doctrine setId shizzle
$objectEntity = new ObjectEntity();
$this->em->persist($objectEntity);
$objectEntity->setId($object['_id']);
$this->em->persist($objectEntity);
$this->em->flush();
$this->em->refresh($objectEntity);

$objectEntity = $this->em->getRepository('App:ObjectEntity')->findOneBy(['id' => $object['_id']]);

$objectEntity->setEntity($entity);

$this->io->writeln('Set external id to '.$object['_id']);
$objectEntity = new ObjectEntity($entity);
$this->io->writeln('Creating new object with existing id '.$objectEntity->getId());

$objectEntity->setExternalId($object['_id']);
} else {
$objectEntity = new ObjectEntity($entity);
$this->io->writeln(['', 'Creating new object']);
Expand Down Expand Up @@ -349,4 +340,48 @@ public function handleInstaller($file)

return $installationService->install();
}

/**
* Handles forced id's on object entities
*
* @param ObjectEntity $objectEntity
* @return ObjectEntity
*/
private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity{
// Save the values
$values = $object->getObjectValues()->toArray();
$object->clearAllValues();

// We have an object entity with a fixed id that isn't in the database, so we need to act
if($objectEntity->getId() && !$this->em->contains($objectEntity)){
// Sve the id
$id = $objectEntity->getId();
// Create the entity
$this->em->persist($objectEntity);
$this->em->flush();
$this->em->refresh($objectEntity);
// Reset the id
$objectEntity->setId($id);
$this->em->persist($objectEntity);
$this->em->flush();
$objectEntity = $this->entityManager->getRepository('App:ObjectEntity')->findOneBy(['id' => $id]);
}

// Loop trough the values
foreach ($values as $objectValue){
// If the value itsself is an object it might also contain fixed id's
foreach ($objectValue->getObjects() as $subobject){
$subobject = $this->saveOnFixedId($subobject);
}

$objectEntity->addObjectValue($objectValue);
}

$this->em->persist($objectEntity);
$this->em->flush();

return $objectEntity;
}


}
Loading