diff --git a/composer.json b/composer.json index 2b2a7bd9..c355791d 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "symfony/process": "^v4.2", "symfony/serializer": "^4.2", "doctrine/doctrine-bundle": "^1.10", - "doctrine/orm": "^2.6" + "doctrine/orm": "^2.6", + "dunglas/doctrine-json-odm": "^0.1.3" }, "require-dev": { "phpunit/phpunit": "^7.4", diff --git a/src/Command/ExecuteTaskCommand.php b/src/Command/ExecuteTaskCommand.php index 4fd312f0..e0303c25 100644 --- a/src/Command/ExecuteTaskCommand.php +++ b/src/Command/ExecuteTaskCommand.php @@ -105,10 +105,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $path = new Path(); $path->add(null, null, [$workflow->getDefinition()->getInitialPlace()]); - $metaData = json_decode($task->getMetaData()); - try { - foreach ($generator->getAvailableTransitions($workflow, $subject, $metaData) as $transitionName) { + foreach ($generator->getAvailableTransitions($workflow, $subject, $task->getMetaData()) as $transitionName) { try { if (!$generator->applyTransition($workflow, $subject, $transitionName)) { throw new Exception(sprintf('Generator %s generated transition %s that can not be applied', $task->getGenerator(), $transitionName)); diff --git a/src/Entity/Task.php b/src/Entity/Task.php index afe193c7..29d338c3 100644 --- a/src/Entity/Task.php +++ b/src/Entity/Task.php @@ -75,11 +75,9 @@ class Task private $takeScreenshots = false; /** - * @ORM\Column(type="text") - * @Assert\NotBlank - * @MbtAssert\Json + * @ORM\Column(type="json_document", options={"jsonb": true}, nullable=true) */ - private $metaData = '{}'; + private $metaData; /** * @var \DateTime @@ -215,7 +213,7 @@ public function getTakeScreenshots() return $this->takeScreenshots; } - public function setMetaData(string $metaData) + public function setMetaData($metaData) { $this->metaData = $metaData; } diff --git a/src/Validator/Constraints/Json.php b/src/Validator/Constraints/Json.php deleted file mode 100644 index c59ce592..00000000 --- a/src/Validator/Constraints/Json.php +++ /dev/null @@ -1,13 +0,0 @@ -context->buildViolation($constraint->message) - ->setParameter('{{ string }}', $this->formatValue($value)) - ->addViolation(); - } - } -} diff --git a/tests/Message/ReplayTaskMessageTest.php b/tests/Message/ReplayTaskMessageTest.php index a9a35547..db4bcbab 100644 --- a/tests/Message/ReplayTaskMessageTest.php +++ b/tests/Message/ReplayTaskMessageTest.php @@ -63,7 +63,7 @@ public function testConsumeMessage(string $model, string $generator, string $red $task->setTitle('Test regression task'); $task->setModel($model); $task->setGenerator($generator); - $task->setMetaData(json_encode(['bugId' => $bug->getId()])); + $task->setMetaData((object) ['bugId' => $bug->getId()]); $task->setReducer($reducer); $task->setTakeScreenshots(false); $entityManager->persist($task); diff --git a/tests/app/src/AppKernel.php b/tests/app/src/AppKernel.php index d9558f89..f9b29250 100644 --- a/tests/app/src/AppKernel.php +++ b/tests/app/src/AppKernel.php @@ -3,6 +3,7 @@ namespace App; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use Dunglas\DoctrineJsonOdm\Bundle\DunglasDoctrineJsonOdmBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\MakerBundle\MakerBundle; use Symfony\Bundle\MonologBundle\MonologBundle; @@ -23,6 +24,7 @@ public function registerBundles() new DoctrineBundle(), new MonologBundle(), new MakerBundle(), + new DunglasDoctrineJsonOdmBundle(), new TienvxMbtBundle(), );