Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush changes to database in TaskController::putAction #56

Merged
merged 1 commit into from
May 31, 2021
Merged
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 Controller/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function getCountAction(Request $request): Response
{
$entityClass = (string) $request->query->get('entityClass');
$entityId = (string) $request->query->get('entityId');
$locale = $request->query->get('locale');
$locale = $request->query->has('locale') ? (string) $request->query->get('locale') : null;

return $this->handleView($this->view([
'count' => $this->automationTaskRepository->countFutureTasks($entityClass, $entityId, $locale),
Expand Down Expand Up @@ -354,6 +354,7 @@ public function putAction(string $id, Request $request): Response
$task->setSchedule($dateTime);
$task = $this->taskManager->update($task);

$this->entityManager->merge($task);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this but seems currently the only solution and TargetGroup was handled the same way.

$this->entityManager->flush();

return $this->handleView($this->view($task));
Expand Down
13 changes: 0 additions & 13 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@
<tag name="kernel.event_subscriber"/>
</service>

<!-- FIXME hack to enable doctrine object constructor -->
<!--
could be fixed in serializer by changing JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass:49
from "->replaceArgument(0, new Reference($previousId[$service]))"
to "->replaceArgument(1, new Reference($previousId[$service]))"
-->
<service id="jms_serializer.object_constructor" alias="sulu_automation.object_constructor" public="false"/>
<service id="sulu_automation.object_constructor" class="JMS\Serializer\Construction\DoctrineObjectConstructor"
public="false">
<argument type="service" id="doctrine"/>
<argument type="service" id="jms_serializer.unserialize_object_constructor"/>
</service>

<service id="sulu_content.automation.publish_handler"
class="Sulu\Bundle\AutomationBundle\Handler\DocumentPublishHandler">
<argument type="service" id="sulu_document_manager.document_manager"/>
Expand Down
14 changes: 14 additions & 0 deletions Tests/Functional/Controller/TaskControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,15 @@ public function testPost(
$this->assertArrayHasKey('id', $responseData);
$this->assertEquals($handlerClass, $responseData['handlerClass']);
$this->assertEquals($date->format('Y-m-d\TH:i:s'), $responseData['schedule']);
$this->assertNotNull($responseData['taskId']);
$this->assertEquals($locale, $responseData['locale']);

$taskManager = $this->getContainer()->get('sulu_automation.tasks.manager');
$task = $taskManager->findById($responseData['id']);
$this->assertEquals($handlerClass, $task->getHandlerClass());
$this->assertEqualsWithDelta($date, $task->getSchedule(), 1);
$this->assertNotNull($task->getTaskId());

return $responseData;
}

Expand Down Expand Up @@ -325,7 +332,14 @@ public function testPut(
$this->assertEquals($postData['id'], $responseData['id']);
$this->assertEquals($handlerClass, $responseData['handlerClass']);
$this->assertEquals($date->format('Y-m-d\TH:i:s'), $responseData['schedule']);
$this->assertNotNull($responseData['taskId']);
$this->assertEquals(FirstHandler::TITLE, $responseData['taskName']);

$taskManager = $this->getContainer()->get('sulu_automation.tasks.manager');
$task = $taskManager->findById($postData['id']);
$this->assertEquals($handlerClass, $task->getHandlerClass());
$this->assertEqualsWithDelta($date, $task->getSchedule(), 1);
$this->assertNotNull($task->getTaskId());
}

public function testGet()
Expand Down