Skip to content

Commit

Permalink
Merge branch 'master' into PS_557-metadata-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jygaulier authored Jun 7, 2023
2 parents 9643278 + c4ff3fb commit 6fa157b
Show file tree
Hide file tree
Showing 36 changed files with 90 additions and 78 deletions.
22 changes: 14 additions & 8 deletions databox/api/src/Attribute/BatchAttributeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct(
private readonly Security $security,
private readonly PostFlushStack $postFlushStack,
private readonly AttributeManager $attributeManager,
private readonly DeferredIndexListener $deferredIndexListener,
) {
}

Expand Down Expand Up @@ -110,7 +111,8 @@ public function handleBatch(
string $workspaceId,
array $assetsId,
AssetAttributeBatchUpdateInput $input,
?RemoteUser $user
?RemoteUser $user,
bool $dispatchUpdateEvent = false,
): void {
if (empty($assetsId)) {
return;
Expand All @@ -119,7 +121,7 @@ public function handleBatch(
DeferredIndexListener::disable();

try {
$this->em->wrapInTransaction(function () use ($user, $input, $assetsId, $workspaceId): void {
$this->em->wrapInTransaction(function () use ($user, $input, $assetsId, $workspaceId, $dispatchUpdateEvent): void {
$changedAttributeDefinitions = [];

foreach ($input->actions as $i => $action) {
Expand Down Expand Up @@ -263,12 +265,16 @@ public function handleBatch(

$attributes = array_keys($changedAttributeDefinitions);
foreach ($assetsId as $assetId) {
// Force assets to be re-indexed here
$this->postFlushStack->addEvent(AttributeChangedEventHandler::createEvent(
$attributes,
$assetId,
$user?->getId(),
));
// Force assets to be re-indexed
$this->deferredIndexListener->scheduleForUpdate($this->em->getReference(Asset::class, $assetId));

if ($dispatchUpdateEvent) {
$this->postFlushStack->addEvent(AttributeChangedEventHandler::createEvent(
$attributes,
$assetId,
$user?->getId(),
));
}
}

$this->em->flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Consumer\Handler\Asset;

use Alchemy\Workflow\WorkflowOrchestrator;
use App\Elasticsearch\Listener\DeferredIndexListener;
use App\Entity\Core\Asset;
use App\Entity\Workflow\WorkflowState;
use App\Workflow\Event\AttributeUpdateWorkflowEvent;
Expand All @@ -19,7 +18,6 @@ final class AttributeChangedEventHandler extends AbstractEntityManagerHandler

public function __construct(
private readonly WorkflowOrchestrator $workflowOrchestrator,
private readonly DeferredIndexListener $deferredIndexListener,
) {
}

Expand All @@ -34,8 +32,6 @@ public function handle(EventMessage $message): void
throw new ObjectNotFoundForHandlerException(Asset::class, $id, self::class);
}

$this->deferredIndexListener->scheduleForUpdate($asset);

$attributes = $payload['attributes'] ?? [];
$this->workflowOrchestrator->dispatchEvent(AttributeUpdateWorkflowEvent::createEvent(
$attributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __invoke(string $id, Asset $data, Request $request)
[$data->getId()],
$data->attributeActions,
$this->getStrictUser(),
true,
);

return $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function __invoke(Attribute $data, Request $request)
$workspaceId,
$input->assets,
$input,
$this->getStrictUser()
$this->getStrictUser(),
true,
);
}

Expand Down
1 change: 1 addition & 0 deletions expose/api/config/packages/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ framework:
# For instance, basic validation constraints will be inferred from Doctrine's metadata.
#auto_mapping:
# App\Entity\: []
enable_annotations: true
30 changes: 30 additions & 0 deletions expose/api/src/Entity/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use Ramsey\Uuid\Uuid;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

/**
* @ORM\Entity()
Expand Down Expand Up @@ -853,4 +855,32 @@ public function __sleep()
{
return [];
}

/**
* @Assert\Callback
*/
public function validateNoParentRecursion(ExecutionContextInterface $context, $payload): void
{
if ($this->hasRecursiveParent()) {
$context
->buildViolation('Publication has circular parenthood')
->atPath('parent')
->addViolation();
}
}

private function hasRecursiveParent(): bool
{
$parents = [];
$p = $this;
while ($p) {
if (isset($parents[$p->getId()])) {
return true;
}
$parents[$p->getId()] = true;
$p = $p->getParent();
}

return false;
}
}
2 changes: 1 addition & 1 deletion infra/docker/php-fpm-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ENV APP_ENV=prod \
PHP_MEMORY_LIMIT=132M \
APCU_VERSION=5.1.22 \
AMQP_VERSION=1.11.0 \
XDEBUG_VERSION=3.1.5 \
XDEBUG_VERSION=3.2.1 \
REDIS_VERSION=5.3.7

RUN set -eux; \
Expand Down
3 changes: 1 addition & 2 deletions lib/php/workflow/src/Command/DumpWorkflowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class DumpWorkflowCommand extends Command
public function __construct(
StateRepositoryInterface $stateRepository,
WorkflowRepositoryInterface $workflowRepository
)
{
) {
parent::__construct();
$this->stateRepository = $stateRepository;
$this->workflowRepository = $workflowRepository;
Expand Down
4 changes: 1 addition & 3 deletions lib/php/workflow/src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

class RunCommand extends Command
{

private WorkflowOrchestrator $orchestrator;

public function __construct(
WorkflowOrchestrator $orchestrator
)
{
) {
parent::__construct();
$this->orchestrator = $orchestrator;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/php/workflow/src/Consumer/JobConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

class JobConsumer implements EventMessageHandlerInterface
{
const EVENT = 'alchemy_workflow_job_run';
public const EVENT = 'alchemy_workflow_job_run';

private PlanExecutor $planExecutor;
private WorkflowOrchestrator $orchestrator;

public function __construct(
PlanExecutor $planExecutor,
WorkflowOrchestrator $orchestrator
)
{
) {
$this->planExecutor = $planExecutor;
$this->orchestrator = $orchestrator;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/php/workflow/src/Date/MicroDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(string $datetime = null, ?int $microseconds = null)
$dateTime = $dateTime->setTime((int) $dateTime->format('G'), (int) $dateTime->format('i'), (int) $dateTime->format('s'), 0);
} else {
$dateTime = (new \DateTimeImmutable('now', new \DateTimeZone('UTC')))
->setTime(0,0,0,0)
->setTime(0, 0, 0, 0)
->setTimestamp((int) ($ts ?? time()));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/php/workflow/src/Doctrine/Entity/WorkflowState.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Alchemy\Workflow\State\Inputs;
use Alchemy\Workflow\State\StateUtil;
use Alchemy\Workflow\State\WorkflowState as ModelWorkflowState;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
use Alchemy\Workflow\State\WorkflowState as ModelWorkflowState;

class WorkflowState
{
Expand Down
4 changes: 2 additions & 2 deletions lib/php/workflow/src/Dumper/ConsoleWorkflowDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function dumpWorkflow(WorkflowState $state, Plan $plan, OutputInterface $
$jobState = $state->getJobState($jobId);

$table->addRow([
$runIndex === 0 ? $stageIndex + 1 : '',
$stepIndex === 0 ? $jobId : '',
0 === $runIndex ? $stageIndex + 1 : '',
0 === $stepIndex ? $jobId : '',
$step->getName(),
$jobState && $jobState->getStatus() ? self::STATUSES[$jobState->getStatus()] : '-',
]);
Expand Down
1 change: 0 additions & 1 deletion lib/php/workflow/src/Dumper/JsonWorkflowDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public function dumpWorkflow(WorkflowState $state, Plan $plan, OutputInterface $
];
}


$output->write(json_encode($out));
}
}
1 change: 0 additions & 1 deletion lib/php/workflow/src/Executor/Adapter/BashExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Alchemy\Workflow\Executor\ExecutorInterface;
use Alchemy\Workflow\Executor\RunContext;
use Alchemy\Workflow\Model\Step;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

Expand Down
1 change: 0 additions & 1 deletion lib/php/workflow/src/Executor/Adapter/PhpExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Alchemy\Workflow\Executor\ExecutorInterface;
use Alchemy\Workflow\Executor\RunContext;
use Alchemy\Workflow\Model\Step;
use Symfony\Component\Process\PhpProcess;

class PhpExecutor implements ExecutorInterface
Expand Down
10 changes: 4 additions & 6 deletions lib/php/workflow/src/Executor/Expression/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public function evaluateJobExpression(
string $expression,
JobExecutionContext $context,
?RunContext $runContext = null
): mixed
{
): mixed {
$count = preg_match_all(self::DYNAMIC_PATTERN, $expression, $matches);

if (0 === $count) {
Expand Down Expand Up @@ -49,15 +48,15 @@ protected function registerFunctions()
if (!$date instanceof \DateTime) {
throw new \RuntimeException('date_modify() expects parameter 1 to be a Date');
}

return $date->modify($modify);
});
}

private function evaluateDynamicExpression(
mixed $expression,
array $variables
): mixed
{
): mixed {
if (!is_string($expression)) {
return $expression;
}
Expand Down Expand Up @@ -106,8 +105,7 @@ public function evaluateRun(string $run, JobExecutionContext $context, RunContex
private function createJobVariables(
JobExecutionContext $context,
?RunContext $runContext = null
): array
{
): array {
$workflowState = $context->getWorkflowState();
$jobState = $context->getJobState();
$inputs = $runContext?->getInputs() ?? $workflowState->getEvent()?->getInputs() ?? new Inputs();
Expand Down
4 changes: 1 addition & 3 deletions lib/php/workflow/src/Executor/JobContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Alchemy\Workflow\Executor;

use Alchemy\Workflow\State\Inputs;
use Alchemy\Workflow\State\Outputs;
use Symfony\Component\Console\Output\OutputInterface;

class JobContext
Expand All @@ -14,8 +13,7 @@ public function __construct(
private readonly OutputInterface $output,
private readonly Inputs $inputs,
private readonly EnvContainer $envs,
)
{
) {
}

public function getInputs(): Inputs
Expand Down
3 changes: 1 addition & 2 deletions lib/php/workflow/src/Executor/JobExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public function __construct(
private readonly OutputInterface $output,
private readonly EnvContainer $envs,
private Inputs $inputs,
)
{
) {
}

public function getOutput(): OutputInterface
Expand Down
2 changes: 1 addition & 1 deletion lib/php/workflow/src/Executor/JobExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
) {
$this->logger = $logger ?? new NullLogger();
$this->output = $output ?? new NullOutput();
$this->envs = $envs ?? new EnvContainer();;
$this->envs = $envs ?? new EnvContainer();
}

private function shouldBeSkipped(JobExecutionContext $context, Job $job): bool
Expand Down
3 changes: 1 addition & 2 deletions lib/php/workflow/src/Executor/PlanExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public function __construct(
private WorkflowRepositoryInterface $workflowRepository,
private JobExecutor $jobExecutor,
private StateRepositoryInterface $stateRepository,
)
{
) {
}

public function executePlan(string $workflowId, string $jobId): void
Expand Down
3 changes: 1 addition & 2 deletions lib/php/workflow/src/Executor/RunContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public function __construct(
Inputs $inputs,
EnvContainer $envs,
private readonly Outputs $outputs,
)
{
) {
parent::__construct($output, $inputs, $envs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class ChainedWorkflowRepository implements WorkflowRepositoryInterface
*/
public function __construct(
array $repositories,
)
{
) {
$this->repositories = $repositories;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Alchemy\Workflow\State\WorkflowState;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Throwable;

class DoctrineStateRepository implements LockAwareStateRepositoryInterface
{
Expand All @@ -25,8 +23,7 @@ public function __construct(
EntityManagerInterface $em,
string $workflowStateEntity = null,
string $jobStateEntity = null,
)
{
) {
$this->em = $em;
$this->workflowStateEntity = $workflowStateEntity ?? WorkflowStateEntity::class;
$this->jobStateEntity = $jobStateEntity ?? JobStateEntity::class;
Expand All @@ -36,7 +33,7 @@ public function getWorkflowState(string $id): WorkflowState
{
$entity = $this->em->getRepository($this->workflowStateEntity)->find($id);
if (!$entity instanceof WorkflowStateEntity) {
throw new InvalidArgumentException(sprintf('Workflow state "%s" does not exist', $id));
throw new \InvalidArgumentException(sprintf('Workflow state "%s" does not exist', $id));
}

$state = $entity->getWorkflowState();
Expand Down Expand Up @@ -98,7 +95,7 @@ public function acquireJobLock(string $workflowId, string $jobId): void
if ($entity instanceof JobStateEntity) {
$this->jobs[$workflowId][$jobId] = $entity;
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->em->rollback();
throw $e;
}
Expand Down
Loading

0 comments on commit 6fa157b

Please sign in to comment.