Skip to content

Commit

Permalink
Merge commit 'refs/pull/487/head' of github.com:alchemy-fr/phraseanet…
Browse files Browse the repository at this point in the history
…-services into w2445
  • Loading branch information
nmaillat committed Nov 14, 2024
2 parents 9c56f7a + 3e024dd commit 99d3d5c
Show file tree
Hide file tree
Showing 26 changed files with 207 additions and 46 deletions.
2 changes: 1 addition & 1 deletion databox/api/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Alchemy\WorkflowBundle\AlchemyWorkflowBundle::class => ['all' => true],
Alchemy\ESBundle\AlchemyESBundle::class => ['all' => true],
Alchemy\MessengerBundle\AlchemyMessengerBundle::class => ['all' => true],
Sentry\SentryBundle\SentryBundle::class => ['prod' => true],
Sentry\SentryBundle\SentryBundle::class => ['all' => true],
Arthem\ObjectReferenceBundle\ArthemObjectReferenceBundle::class => ['all' => true],
Alchemy\RenditionFactoryBundle\AlchemyRenditionFactoryBundle::class => ['all' => true],
];
1 change: 1 addition & 0 deletions databox/api/config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ framework:
Alchemy\Workflow\Message\JobConsumer: p1
Alchemy\WebhookBundle\Consumer\WebhookTriggerMessage: p2
Alchemy\WebhookBundle\Consumer\WebhookEvent: p2
Alchemy\CoreBundle\Message\Debug\SentryDebug: p1

when@dev:
framework:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
use Alchemy\AdminBundle\Field\CodeField;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\JsonField;
use Alchemy\AdminBundle\Filter\AssociationIdentifierFilter;
use Alchemy\AdminBundle\Filter\ChildPropertyEntityFilter;
use App\Entity\Core\AssetRendition;
use App\Entity\Core\Workspace;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\DateTimeFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\NullFilter;

class AssetRenditionCrudController extends AbstractAdminCrudController
Expand Down Expand Up @@ -45,9 +49,18 @@ public function configureCrud(Crud $crud): Crud
public function configureFilters(Filters $filters): Filters
{
return $filters
->add(ChildPropertyEntityFilter::new('definition', 'workspace', 'Workspace'))
->add(ChildPropertyEntityFilter::new(
'definition',
'workspace',
Workspace::class,
'Workspace'
))
->add(EntityFilter::new('definition'))
->add(AssociationIdentifierFilter::new('asset'))
->add(NullFilter::new('file', 'Is Ready')->setChoiceLabels('Not ready', 'Ready'))
->add(DateTimeFilter::new('createdAt'))
->add(BooleanFilter::new('locked'))
->add(BooleanFilter::new('substituted'))
;
}

Expand Down
14 changes: 12 additions & 2 deletions databox/api/src/Controller/Admin/AttributeCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
use Alchemy\AdminBundle\Controller\AbstractAdminCrudController;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\JsonField;
use Alchemy\AdminBundle\Filter\AssociationIdentifierFilter;
use Alchemy\AdminBundle\Filter\ChildPropertyEntityFilter;
use App\Entity\Core\Attribute;
use App\Entity\Core\Workspace;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
Expand All @@ -19,6 +21,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\TextFilter;

class AttributeCrudController extends AbstractAdminCrudController
Expand All @@ -38,7 +41,14 @@ public function configureActions(Actions $actions): Actions
public function configureFilters(Filters $filters): Filters
{
return $filters
->add(ChildPropertyEntityFilter::new('definition', 'workspace', 'Workspace'))
->add(ChildPropertyEntityFilter::new(
'definition',
'workspace',
Workspace::class,
'Workspace'
))
->add(EntityFilter::new('definition'))
->add(AssociationIdentifierFilter::new('asset'))
->add(TextFilter::new('value'))
->add(TextFilter::new('locale'))
->add(BooleanFilter::new('locked'))
Expand All @@ -50,7 +60,7 @@ public function configureCrud(Crud $crud): Crud
return parent::configureCrud($crud)
->setEntityLabelInSingular('Attribute')
->setEntityLabelInPlural('Attribute')
->setSearchFields(['id', 'locale', 'position', 'translationId', 'translationOriginHash', 'value', 'origin', 'originVendor', 'originUserId', 'originVendorContext', 'coordinates', 'status', 'confidence'])
->setSearchFields(['id', 'locale', 'position', 'translationOriginHash', 'value', 'origin', 'originVendor', 'originUserId', 'originVendorContext', 'coordinates', 'status', 'confidence'])
->setPaginatorPageSize(20);
}

Expand Down
36 changes: 27 additions & 9 deletions databox/api/src/Doctrine/Delete/CollectionDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
use App\Entity\Core\Asset;
use App\Entity\Core\Collection;
use App\Entity\Core\CollectionAsset;
use App\Entity\Template\AssetDataTemplate;
use Doctrine\ORM\EntityManagerInterface;

final readonly class CollectionDelete
{
public function __construct(private EntityManagerInterface $em, private IndexCleaner $indexCleaner, private SoftDeleteToggler $softDeleteToggler)
{
public function __construct(
private EntityManagerInterface $em,
private IndexCleaner $indexCleaner,
private SoftDeleteToggler $softDeleteToggler,
) {
}

public function deleteCollection(string $collectionId, bool $isChildProcess = false): void
Expand Down Expand Up @@ -79,13 +83,6 @@ private function doDelete(string $collectionId): void
->getQuery()
->toIterable();

foreach ($assets as $a) {
$asset = $this->em->find(Asset::class, $a['id']);
$this->em->remove($asset);
$this->em->flush();
$this->em->clear();
}

$this->em->getRepository(CollectionAsset::class)
->createQueryBuilder('t')
->delete()
Expand All @@ -94,10 +91,31 @@ private function doDelete(string $collectionId): void
->getQuery()
->execute();

foreach ($assets as $a) {
$asset = $this->em->find(Asset::class, $a['id']);
$this->em->remove($asset);
$this->em->flush();
$this->em->clear();
}

$this->deleteDependencies(AssetDataTemplate::class, $collectionId);

$collection = $this->em->find(Collection::class, $collectionId);
if ($collection instanceof Collection) {
$this->em->remove($collection);
$this->em->flush();
}
}

private function deleteDependencies(string $entityClass, string $collectionId): void
{
$items = $this->em->getRepository($entityClass)->findBy([
'collection' => $collectionId,
]);
foreach ($items as $item) {
$this->em->remove($item);
}
$this->em->flush();
$this->em->clear();
}
}
12 changes: 9 additions & 3 deletions databox/api/src/Doctrine/Delete/WorkspaceDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
use App\Entity\Core\RenditionDefinition;
use App\Entity\Core\Tag;
use App\Entity\Core\Workspace;
use App\Entity\Template\AssetDataTemplate;
use Doctrine\ORM\EntityManagerInterface;

class WorkspaceDelete
final readonly class WorkspaceDelete
{
public function __construct(private readonly EntityManagerInterface $em, private readonly CollectionDelete $collectionDelete, private readonly IndexCleaner $indexCleaner, private readonly SoftDeleteToggler $softDeleteToggler)
{
public function __construct(
private EntityManagerInterface $em,
private CollectionDelete $collectionDelete,
private IndexCleaner $indexCleaner,
private SoftDeleteToggler $softDeleteToggler,
) {
}

public function deleteWorkspace(string $workspaceId): void
Expand Down Expand Up @@ -62,6 +67,7 @@ public function deleteWorkspace(string $workspaceId): void
$this->deleteDependencies(RenditionClass::class, $workspaceId);
$this->deleteDependencies(AttributeDefinition::class, $workspaceId);
$this->deleteDependencies(AttributeClass::class, $workspaceId);
$this->deleteDependencies(AssetDataTemplate::class, $workspaceId);

$files = $this->em->getRepository(File::class)
->createQueryBuilder('t')
Expand Down
2 changes: 1 addition & 1 deletion expose/api/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle::class => ['all' => true],
Alchemy\NotifyBundle\AlchemyNotifyBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Sentry\SentryBundle\SentryBundle::class => ['prod' => true],
Sentry\SentryBundle\SentryBundle::class => ['all' => true],
Alchemy\MessengerBundle\AlchemyMessengerBundle::class => ['all' => true],
];
3 changes: 3 additions & 0 deletions expose/api/config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ framework:
dsn: '%alchemy_messenger.amqp_transport_dsn%/p1'
options: '%alchemy_messenger.amqp_transport_options%'

routing:
Alchemy\CoreBundle\Message\Debug\SentryDebug: p1

when@dev:
framework:
messenger:
Expand Down
33 changes: 28 additions & 5 deletions lib/php/admin-bundle/Filter/ChildPropertyEntityFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterDataDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterDto;
use EasyCorp\Bundle\EasyAdminBundle\Filter\FilterTrait;
use EasyCorp\Bundle\EasyAdminBundle\Form\Filter\Type\EntityFilterType;
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\ComparisonType;
Expand All @@ -24,17 +25,25 @@ final class ChildPropertyEntityFilter implements FilterInterface
{
use FilterTrait;

public static function new(string $propertyName, string $childPropertyName, $label = null): self
private string $realPropertyName;
private string $subPropertyName;


public static function new(string $propertyName, string $childPropertyName, string $entityClass, $label = null): self
{
$label = null == $label ? $childPropertyName : $label;

return (new self())
->setFilterFqcn(__CLASS__)
->setProperty($propertyName)
->setRealPropertyName($propertyName)
->setSubPropertyName($childPropertyName)
->setProperty(sprintf('%s__%s', $propertyName, $childPropertyName))
->setLabel($label)
->setFormType(EntityFilterType::class)
->setFormTypeOption('translation_domain', 'EasyAdminBundle')
->setFormTypeOption('value_type_options.attr.data-child-property', $childPropertyName);
->setFormTypeOption('value_type_options.attr.data-child-property', $childPropertyName)
->setFormTypeOption('value_type_options.class', $entityClass)
;
}

/**
Expand All @@ -48,13 +57,13 @@ public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto,
$assocAlias = 'ea_'.$filterDataDto->getParameterName();
$childAssocAlias = 'ea_'.$filterDataDto->getParameter2Name();

$property = $filterDataDto->getProperty();
$property = $this->realPropertyName;
$comparison = $filterDataDto->getComparison();
$parameterName = $filterDataDto->getParameterName();
$value = $filterDataDto->getValue();
$isMultiple = $filterDataDto->getFormTypeOption('value_type_options.multiple');

$childPropertyName = $filterDataDto->getFormTypeOption('value_type_options.attr.data-child-property');
$childPropertyName = $this->subPropertyName;
$doctrineMetadata = $entityDto->getPropertyMetadata($property);
$entityManager = $queryBuilder->getEntityManager();
$propertyEntityFqcn = $doctrineMetadata->get('targetEntity');
Expand Down Expand Up @@ -155,4 +164,18 @@ private function processSingleParameterValue(QueryBuilder $queryBuilder, mixed $

return $parameterValue;
}

public function setRealPropertyName(string $realPropertyName): self
{
$this->realPropertyName = $realPropertyName;

return $this;
}

public function setSubPropertyName(string $subPropertyName): self
{
$this->subPropertyName = $subPropertyName;

return $this;
}
}
20 changes: 20 additions & 0 deletions lib/php/core-bundle/Controller/SentryTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Alchemy\CoreBundle\Controller;

use Alchemy\CoreBundle\Message\Debug\SentryDebug;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route;

#[Route(path: '/_health/sentry-test')]
Expand Down Expand Up @@ -40,4 +42,22 @@ public function testBoth(): never

throw new \RuntimeException('[BOTH] Exception');
}

#[Route(path: '/log-stack')]
public function logStack(): never
{
$this->logger->debug('This is a DEBUG log');
$this->logger->info('This is a INFO log');
$this->logger->error('This is a ERROR log');

throw new \RuntimeException('Stack');
}

#[Route(path: '/messenger')]
public function messenger(MessageBusInterface $bus): Response
{
$bus->dispatch(new SentryDebug(date(\DateTimeInterface::ATOM), ['extra' => 'data']));

return new Response('');
}
}
10 changes: 8 additions & 2 deletions lib/php/core-bundle/DependencyInjection/AlchemyCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ public function prepend(ContainerBuilder $container): void
],
]);
}

if (isset($bundles['SentryBundle'])) {
$container->prependExtensionConfig('sentry', [
$sentryConfig = [
'tracing' => [
'dbal' => [
'enabled' => false,
Expand Down Expand Up @@ -181,7 +182,12 @@ public function prepend(ContainerBuilder $container): void
NotAcceptableHttpException::class,
],
],
]);
];

if ($env !== 'prod') {
$sentryConfig['dsn'] = null;
}
$container->prependExtensionConfig('sentry', $sentryConfig);

if (isset($bundles['MonologBundle'])) {
$container->prependExtensionConfig('sentry', [
Expand Down
22 changes: 22 additions & 0 deletions lib/php/core-bundle/Message/Debug/SentryDebug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Alchemy\CoreBundle\Message\Debug;

final readonly class SentryDebug
{
public function __construct(
private string $id,
private array $extra = [],
) {
}

public function getId(): string
{
return $this->id;
}

public function getExtra(): array
{
return $this->extra;
}
}
14 changes: 14 additions & 0 deletions lib/php/core-bundle/Message/Debug/SentryDebugHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Alchemy\CoreBundle\Message\Debug;

use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class SentryDebugHandler
{
public function __invoke(SentryDebug $message): void
{
throw new \InvalidArgumentException(sprintf('Test error in messenger handler %s', $message->getId()));
}
}
1 change: 1 addition & 0 deletions lib/php/core-bundle/Resources/config/sentry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
autoconfigure: true

Alchemy\CoreBundle\Controller\SentryTestController: ~
Alchemy\CoreBundle\Message\Debug\SentryDebugHandler: ~

Sentry\Monolog\Handler:
arguments:
Expand Down
Loading

0 comments on commit 99d3d5c

Please sign in to comment.