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
14 changes: 14 additions & 0 deletions Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\ORM\NonUniqueResultException;
use Exception;
use MongoDB\Client;
use Monolog\Logger;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Cache\Adapter\AdapterInterface as CacheInterface;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -37,6 +38,7 @@ class CacheService
private SymfonyStyle $io;
private ParameterBagInterface $parameters;
private SerializerInterface $serializer;
private Logger $logger;

/**
* @param AuthenticationService $authenticationService
Expand All @@ -56,6 +58,7 @@ public function __construct(
if ($this->parameters->get('cache_url', false)) {
$this->client = new Client($this->parameters->get('cache_url'));
}
$this->logger = New Logger('cache');
}

/**
Expand Down Expand Up @@ -239,8 +242,12 @@ public function cacheObject(ObjectEntity $objectEntity): ObjectEntity
['upsert'=>true]
)) {
(isset($this->io) ? $this->io->writeln('Updated object '.$objectEntity->getId()->toString().' of type '.$objectEntity->getEntity()->getName().' to cache') : '');

$this->logger->debug("updated object to cache");
} else {
(isset($this->io) ? $this->io->writeln('Wrote object '.$objectEntity->getId()->toString().' of type '.$objectEntity->getEntity()->getName().' to cache') : '');

$this->logger->debug("Added object to cache");
}

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

$collection->findOneAndDelete(['_id'=>$id]);

$this->logger->debug("Removed object from cache");
}

/**
Expand All @@ -284,11 +293,13 @@ public function getObject(string $id)

// Check if object is in the cache ????
if ($object = $collection->findOne(['_id'=>$id])) {
$this->logger->debug("Retrieved cached object from cache");
return $object;
}

// Fall back tot the entity manager
if ($object = $this->entityManager->getRepository('App:ObjectEntity')->findOneBy(['id'=>$id])) {
$this->logger->debug("Retrieved uncached object from cache");
return $this->cacheObject($object)->toArray(['embedded' => true]);
}

Expand Down Expand Up @@ -365,6 +376,9 @@ public function searchObjects(string $search = null, array $filter = [], array $
$results = $collection->find($filter, ['limit' => $limit, 'skip' => $start, 'sort' => $order])->toArray();
$total = $collection->count($filter);


$this->logger->debug("Searched cache for objects");

// Make sure to add the pagination properties in response
return $this->handleResultPagination($completeFilter, $results, $total);
}
Expand Down
5 changes: 4 additions & 1 deletion Service/CallService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Psr7\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder:
use Monolog\Logger;

/**
* Service to call external sources.
Expand All @@ -32,6 +33,7 @@ class CallService
private Client $client;
private EntityManagerInterface $entityManager;
private FileService $fileService;
private Logger $logger;

/**
* @param AuthenticationService $authenticationService
Expand All @@ -44,6 +46,7 @@ public function __construct(AuthenticationService $authenticationService, Entity
$this->client = new Client([]);
$this->entityManager = $entityManager;
$this->fileService = $fileService;
$this->logger = New Logger('call');
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Service/ComposerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Monolog\Logger;

class ComposerService
{

private Logger $logger;

public function __construct(){

$this->logger = New Logger('installation');
}

private function arrayEnum(array $array, array $enum): bool
{
// Lets see if the values in the array arry pressent in the enum
Expand Down
44 changes: 33 additions & 11 deletions Service/InstallationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Monolog\Logger;

class InstallationService
{
private ComposerService $composerService;
private EntityManagerInterface $em;
private SymfonyStyle $io;
private $container;
private Logger $logger;

public function __construct(
ComposerService $composerService,
Expand All @@ -28,6 +30,8 @@ public function __construct(
$this->em = $em;
$this->container = $kernel->getContainer();
$this->collection = null;
$this->logger = New Logger('installation');

}

/**
Expand Down Expand Up @@ -59,7 +63,10 @@ public function composerupdate(): int
]);
}

$this->logger->debug("Running plugin installer");

foreach ($plugins as $plugin) {

$this->install($plugin['name']);
}

Expand All @@ -84,6 +91,9 @@ public function install(string $bundle, bool $noSchema = false): int
]);
}


$this->logger->debug('Trying to install: '.$bundle);

$packages = $this->composerService->getAll();

$found = array_filter($packages, function ($v, $k) use ($bundle) {
Expand Down Expand Up @@ -123,13 +133,16 @@ public function install(string $bundle, bool $noSchema = false): int
// We want each plugin to also be a collection (if it contains schema's that is)
if (count($schemas) > 0) {
if (!$this->collection = $this->em->getRepository('App:CollectionEntity')->findOneBy(['plugin' => $package['name']])) {

$this->logger->debug('Created a collection for plugin '.$bundle);
$this->io->writeln(['Created a collection for this plugin', '']);
$this->collection = new CollectionEntity();
$this->collection->setName($package['name']);
$this->collection->setPlugin($package['name']);
isset($package['description']) && $this->collection->setDescription($package['description']);
} else {
$this->io->writeln(['Found a collection for this plugin', '']);
$this->logger->debug('Found a collection for plugin '.$bundle);
}
}

Expand All @@ -145,6 +158,7 @@ public function install(string $bundle, bool $noSchema = false): int
//$progressBar->finish();
} else {
$this->io->writeln('No schema folder found');
$this->logger->debug('No schema folder found for plugin '.$bundle);
}

// Handling the data
Expand All @@ -163,6 +177,7 @@ public function install(string $bundle, bool $noSchema = false): int

// We need to clear the finder
} else {
$this->logger->debug('No data folder found for plugin '.$bundle);
$this->io->writeln('No data folder found');
}

Expand All @@ -179,10 +194,12 @@ public function install(string $bundle, bool $noSchema = false): int
$this->handleInstaller($installer);
}
} else {
$this->logger->debug('No Installation folder found for plugin '.$bundle);
$this->io->writeln('No Installation folder found');
}

$this->io->success('All Done');
$this->logger->debug('All Done installing plugin '.$bundle);

return Command::SUCCESS;
}
Expand Down Expand Up @@ -335,18 +352,17 @@ public function handleInstaller($file)
}

/**
* Handles forced id's on object entities.
* Handles forced id's on object entities
*
* @param ObjectEntity $objectEntity
*
* @return ObjectEntity
*/
private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity
{
private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity{
// This savetey dosn't make sense but we need it
if (!$objectEntity->getEntity()) {
$this->io->writeln(['', 'Object can\'t be persisted due to missing schema']);
if(!$objectEntity->getEntity()){

$this->logger->error('Object can\'t be persisted due to missing schema');
$this->io->writeln(['', 'Object can\'t be persisted due to missing schema']);
return $objectEntity;
}

Expand All @@ -355,7 +371,8 @@ private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity
$objectEntity->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)) {
if($objectEntity->getId() && !$this->em->contains($objectEntity)){

$this->io->writeln(['', 'Creating new object ('.$objectEntity->getEntity()->getName().') on a fixed id ('.$objectEntity->getId().')']);

// Sve the id
Expand All @@ -369,29 +386,34 @@ private function saveOnFixedId(ObjectEntity $objectEntity): ObjectEntity
$this->em->persist($objectEntity);
$this->em->flush();
$objectEntity = $this->em->getRepository('App:ObjectEntity')->findOneBy(['id' => $id]);
} else {
}
else{
$this->io->writeln(['', 'Creating new object ('.$objectEntity->getEntity()->getName().') on a generated id']);
}

// Loop trough the values
foreach ($values as $objectValue) {
foreach ($values as $objectValue){
$objectEntity->addObjectValue($objectValue);
// If the value itsself is an object it might also contain fixed id's
foreach ($objectValue->getObjects() as $subobject) {
foreach ($objectValue->getObjects() as $subobject){
$this->io->writeln(['', 'Found sub object ('.$subobject->getEntity()->getName().')']);
$subobject = $this->saveOnFixedId($subobject);

// This savetey dosn't make sense but we need it
if (!$subobject->getEntity()) {
if(!$subobject->getEntity()){
// todo: Throw error
$objectEntity->removeObjectValue($objectValue);
}
}

}

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

return $objectEntity;
}



}
4 changes: 3 additions & 1 deletion Service/RequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\SerializerInterface;
use Monolog\Logger;

/**
* Handles incomming request from endpoints or controllers that relate to the gateways object structure (eav).
Expand All @@ -36,11 +37,11 @@ class RequestService
// todo: we might want to move or rewrite code instead of using these services here:
private ResponseService $responseService;
private ObjectEntityService $objectEntityService;
private LogService $logService;
private CallService $callService;
private Security $security;
private EventDispatcherInterface $eventDispatcher;
private SerializerInterface $serializer;
private Logger $logger;

/**
* @param EntityManagerInterface $entityManager
Expand Down Expand Up @@ -73,6 +74,7 @@ public function __construct(
$this->security = $security;
$this->eventDispatcher = $eventDispatcher;
$this->serializer = $serializer;
$this->logger = New Logger('request');
}

/**
Expand Down