Skip to content

Commit

Permalink
Remove deserialization and entity manager merge
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jun 7, 2024
1 parent 2553ae8 commit 2b0e41e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 59 deletions.
52 changes: 42 additions & 10 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,36 @@ jobs:
matrix:
include:
- php-version: '7.2'
lint: false
dependency-versions: 'lowest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: disabled

- php-version: '7.4'
lint: true
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.0'
lint: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.1'
lint: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.2'
lint: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.3'
lint: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
Expand Down Expand Up @@ -93,10 +87,48 @@ jobs:
- name: Bootstrap test environment
run: composer bootstrap-test-environment

- name: Lint code
if: ${{ matrix.lint }}
run: composer lint

- name: Execute test cases
run: composer test
env: ${{ matrix.env }}

lint:
name: 'PHP Lint'
runs-on: ubuntu-latest

env:
DATABASE_URL: 'mysql://root:[email protected]/sulu_automation_test?serverVersion=5.7'

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5

steps:
- name: Checkout project
uses: actions/checkout@v2

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: 'mysql, gd'
tools: composer:v2

- name: Remove not required tooling
run: composer remove php-cs-fixer/shim "*phpstan*" --dev --no-interaction --no-update

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: highest
composer-options: highest

- name: Bootstrap test environment
run: composer bootstrap-test-environment

- name: Lint code
run: composer lint
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ Tests/Application/.env.test.local
# php-cs-fixer
.php-cs-fixer.cache
php-cs-fixer

.env.local
.env.*.local
63 changes: 17 additions & 46 deletions Controller/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TaskController extends AbstractRestController implements ClassResourceInte
protected $entityManager;

/**
* @var SerializerInterface
* @var SerializerInterface|null
*/
protected $serializer;

Expand All @@ -112,7 +112,7 @@ public function __construct(
RestHelperInterface $doctrineRestHelper,
TaskManagerInterface $taskManager,
EntityManagerInterface $entityManager,
SerializerInterface $serializer,
?SerializerInterface $serializer,
FieldDescriptorFactoryInterface $fieldDescriptorFactory,
AutomationTaskRepositoryInterface $automationTaskRepository
) {
Expand Down Expand Up @@ -298,27 +298,14 @@ public function getCountAction(Request $request): Response
*/
public function postAction(Request $request): Response
{
$data = \array_merge(
[
'scheme' => $request->getScheme(),
'host' => $request->getHost(),
'entityId' => $request->get('entityId'),
'entityClass' => $request->get('entityClass'),
'locale' => $request->get('locale'),
],
\array_filter($request->request->all())
);

$context = DeserializationContext::create();
$context->setGroups(['api']);

/** @var TaskInterface $task */
$task = $this->serializer->deserialize(
(string) \json_encode($data),
Task::class,
'json',
$context
);
$task = new Task();
$task->setScheme($request->getScheme());
$task->setHost($request->getHost());
$task->setEntityId((string) $request->query->get('entityId'));
$task->setEntityClass((string) $request->query->get('entityClass'));
$task->setLocale($this->getLocale($request));
$task->setHandlerClass((string) $request->request->get('handlerClass'));
$task->setSchedule(new \DateTime((string) $request->request->get('schedule')));

$this->taskManager->create($task);

Expand All @@ -332,32 +319,16 @@ public function postAction(Request $request): Response
*/
public function putAction(string $id, Request $request): Response
{
$data = \array_merge(
[
'id' => $id,
'scheme' => $request->getScheme(),
'host' => $request->getHost(),
'entityId' => $request->get('entityId'),
'entityClass' => $request->get('entityClass'),
'locale' => $request->get('locale'),
],
\array_filter($request->request->all())
);

$context = DeserializationContext::create();
$context->setGroups(['api']);

/** @var TaskInterface $task */
$task = $this->serializer->deserialize(
(string) \json_encode($data),
Task::class,
'json',
$context
);
/** @var Task $task */
$task = $this->taskManager->findById($id);
$task->setScheme($request->getScheme());
$task->setHost($request->getHost());
$task->setLocale($this->getLocale($request));
$task->setHandlerClass((string) $request->request->get('handlerClass'));
$task->setSchedule(new \DateTime((string) $request->request->get('schedule')));

$task = $this->taskManager->update($task);

$this->entityManager->merge($task);
$this->entityManager->flush();

return $this->handleView($this->view($task));
Expand Down
2 changes: 2 additions & 0 deletions Entity/DoctrineTaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

/**
* Task-Repository implementation for doctrine.
*
* @extends EntityRepository<TaskInterface>
*/
class DoctrineTaskRepository extends EntityRepository implements TaskRepositoryInterface
{
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<argument type="service" id="sulu_core.doctrine_rest_helper"/>
<argument type="service" id="sulu_automation.tasks.manager"/>
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="jms_serializer"/>
<argument>null</argument>
<argument type="service" id="sulu_core.list_builder.field_descriptor_factory"/>
<argument type="service" id="sulu.repository.task"/>

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"symfony/http-kernel": "^4.3 || ^5.0 || ^6.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17 || ^3.0",
"handcraftedinthealps/zendsearch": "^2.0",
"jackalope/jackalope-doctrine-dbal": "^1.3.0",
"jangregor/phpstan-prophecy": "^1.0",
"php-cs-fixer/shim": "^3.0",
"phpspec/prophecy": "^1.8",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-doctrine": "^1.0",
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ parameters:
console_application_loader: Tests/phpstan/console-application.php
doctrine:
objectManagerLoader: Tests/phpstan/object-manager.php
checkGenericClassInNonGenericObjectType: false

0 comments on commit 2b0e41e

Please sign in to comment.