Skip to content

Commit 053422d

Browse files
TatevikGrtatevikg1
andauthored
Em flush (#160)
* Fix composer json * Add flush after delete * Fix: test * SubscriberBlacklistManager * listMessageManager * AdminController flush * TemplateController flush * SubscribePageController flush * save * fix test --------- Co-authored-by: Tatevik <tatevikg1@gmail.com>
1 parent d68ce67 commit 053422d

21 files changed

+120
-285
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
PhpList\Core\Domain\Messaging\MessageHandler\CampaignProcessorMessageHandler:
3+
autowire: true
4+
autoconfigure: true
5+
public: false

src/Identity/Controller/AdminAttributeDefinitionController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\RestBundle\Identity\Controller;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use OpenApi\Attributes as OA;
89
use PhpList\Core\Domain\Identity\Model\AdminAttributeDefinition;
910
use PhpList\Core\Domain\Identity\Service\AdminAttributeDefinitionManager;
@@ -32,7 +33,8 @@ public function __construct(
3233
RequestValidator $validator,
3334
AdminAttributeDefinitionManager $definitionManager,
3435
AdminAttributeDefinitionNormalizer $normalizer,
35-
PaginatedDataProvider $paginatedDataProvider
36+
PaginatedDataProvider $paginatedDataProvider,
37+
private readonly EntityManagerInterface $entityManager,
3638
) {
3739
parent::__construct($authentication, $validator);
3840
$this->definitionManager = $definitionManager;
@@ -89,6 +91,8 @@ public function create(Request $request): JsonResponse
8991
$definitionRequest = $this->validator->validate($request, CreateAttributeDefinitionRequest::class);
9092

9193
$attributeDefinition = $this->definitionManager->create($definitionRequest->getDto());
94+
$this->entityManager->flush();
95+
9296
$json = $this->normalizer->normalize($attributeDefinition, 'json');
9397

9498
return $this->json($json, Response::HTTP_CREATED);
@@ -156,6 +160,7 @@ public function update(
156160
attributeDefinition: $attributeDefinition,
157161
attributeDefinitionDto: $definitionRequest->getDto(),
158162
);
163+
$this->entityManager->flush();
159164
$json = $this->normalizer->normalize($attributeDefinition, 'json');
160165

161166
return $this->json($json, Response::HTTP_OK);
@@ -211,6 +216,7 @@ public function delete(
211216
}
212217

213218
$this->definitionManager->delete($attributeDefinition);
219+
$this->entityManager->flush();
214220

215221
return $this->json(null, Response::HTTP_NO_CONTENT);
216222
}

src/Identity/Controller/AdminAttributeValueController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function delete(
198198
throw $this->createNotFoundException('Administrator attribute not found.');
199199
}
200200
$this->attributeManager->delete($attribute);
201+
$this->entityManager->flush();
201202

202203
return $this->json(null, Response::HTTP_NO_CONTENT);
203204
}
@@ -355,6 +356,7 @@ public function getAttributeDefinition(
355356
attributeDefinitionId: $definition->getId()
356357
);
357358
$this->attributeManager->delete($attribute);
359+
$this->entityManager->flush();
358360

359361
return $this->json(
360362
$this->normalizer->normalize($attribute),

src/Identity/Controller/AdministratorController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\RestBundle\Identity\Controller;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use OpenApi\Attributes as OA;
89
use PhpList\Core\Domain\Identity\Model\Administrator;
910
use PhpList\Core\Domain\Identity\Service\AdministratorManager;
@@ -35,7 +36,8 @@ public function __construct(
3536
RequestValidator $validator,
3637
AdministratorManager $administratorManager,
3738
AdministratorNormalizer $normalizer,
38-
PaginatedDataProvider $paginatedProvider
39+
PaginatedDataProvider $paginatedProvider,
40+
private readonly EntityManagerInterface $entityManager,
3941
) {
4042
parent::__construct($authentication, $validator);
4143
$this->administratorManager = $administratorManager;
@@ -149,6 +151,7 @@ public function createAdministrator(
149151
$createRequest = $validator->validate($request, CreateAdministratorRequest::class);
150152

151153
$administrator = $this->administratorManager->createAdministrator($createRequest->getDto());
154+
$this->entityManager->flush();
152155
$json = $normalizer->normalize($administrator, 'json');
153156

154157
return $this->json($json, Response::HTTP_CREATED);
@@ -255,6 +258,7 @@ public function updateAdministrator(
255258
/** @var UpdateAdministratorRequest $updateRequest */
256259
$updateRequest = $this->validator->validate($request, UpdateAdministratorRequest::class);
257260
$this->administratorManager->updateAdministrator($administrator, $updateRequest->getDto());
261+
$this->entityManager->flush();
258262

259263
return $this->json($this->normalizer->normalize($administrator), Response::HTTP_OK);
260264
}
@@ -303,6 +307,7 @@ public function deleteAdministrator(
303307
throw $this->createNotFoundException('Administrator not found.');
304308
}
305309
$this->administratorManager->deleteAdministrator($administrator);
310+
$this->entityManager->flush();
306311

307312
return $this->json(null, Response::HTTP_NO_CONTENT);
308313
}

src/Identity/Controller/PasswordResetController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\RestBundle\Identity\Controller;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use OpenApi\Attributes as OA;
89
use PhpList\Core\Domain\Identity\Service\PasswordManager;
910
use PhpList\Core\Security\Authentication;
@@ -29,6 +30,7 @@ public function __construct(
2930
Authentication $authentication,
3031
RequestValidator $validator,
3132
PasswordManager $passwordManager,
33+
private readonly EntityManagerInterface $entityManager,
3234
) {
3335
parent::__construct($authentication, $validator);
3436

@@ -74,6 +76,7 @@ public function requestPasswordReset(Request $request): JsonResponse
7476
$resetRequest = $this->validator->validate($request, RequestPasswordResetRequest::class);
7577

7678
$this->passwordManager->generatePasswordResetToken($resetRequest->email);
79+
$this->entityManager->flush();
7780

7881
return $this->json(null, Response::HTTP_NO_CONTENT);
7982
}
@@ -117,6 +120,7 @@ public function validateToken(Request $request): JsonResponse
117120
$validateRequest = $this->validator->validate($request, ValidateTokenRequest::class);
118121

119122
$administrator = $this->passwordManager->validatePasswordResetToken($validateRequest->token);
123+
$this->entityManager->flush();
120124

121125
return $this->json([ 'valid' => $administrator !== null]);
122126
}
@@ -169,6 +173,7 @@ public function resetPassword(Request $request): JsonResponse
169173
$resetRequest->token,
170174
$resetRequest->newPassword
171175
);
176+
$this->entityManager->flush();
172177

173178
if ($success) {
174179
return $this->json([ 'message' => 'Password updated successfully']);

src/Identity/Controller/SessionController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\RestBundle\Identity\Controller;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use OpenApi\Attributes as OA;
89
use PhpList\Core\Domain\Identity\Model\AdministratorToken;
910
use PhpList\Core\Domain\Identity\Service\SessionManager;
@@ -34,6 +35,7 @@ public function __construct(
3435
Authentication $authentication,
3536
RequestValidator $validator,
3637
SessionManager $sessionManager,
38+
private readonly EntityManagerInterface $entityManager,
3739
) {
3840
parent::__construct($authentication, $validator);
3941

@@ -96,6 +98,7 @@ public function createSession(
9698
loginName:$createSessionRequest->loginName,
9799
password: $createSessionRequest->password
98100
);
101+
$this->entityManager->flush();
99102

100103
$json = $normalizer->normalize($token, 'json');
101104

@@ -163,6 +166,7 @@ public function deleteSession(
163166
}
164167

165168
$this->sessionManager->deleteSession($token);
169+
$this->entityManager->flush();
166170

167171
return $this->json(null, Response::HTTP_NO_CONTENT);
168172
}

src/Messaging/Controller/BounceRegexController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\RestBundle\Messaging\Controller;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use OpenApi\Attributes as OA;
89
use PhpList\Core\Domain\Messaging\Service\Manager\BounceRegexManager;
910
use PhpList\Core\Security\Authentication;
@@ -27,6 +28,7 @@ public function __construct(
2728
RequestValidator $validator,
2829
private readonly BounceRegexManager $manager,
2930
private readonly BounceRegexNormalizer $normalizer,
31+
private readonly EntityManagerInterface $entityManager,
3032
) {
3133
parent::__construct($authentication, $validator);
3234
}
@@ -188,6 +190,7 @@ public function createOrUpdate(Request $request): JsonResponse
188190
comment: $dto->comment,
189191
status: $dto->status
190192
);
193+
$this->entityManager->flush();
191194

192195
return $this->json($this->normalizer->normalize($entity), Response::HTTP_CREATED);
193196
}
@@ -240,6 +243,7 @@ public function delete(Request $request, string $regexHash): JsonResponse
240243
throw $this->createNotFoundException('Bounce regex not found.');
241244
}
242245
$this->manager->delete($entity);
246+
$this->entityManager->flush();
243247

244248
return $this->json(null, Response::HTTP_NO_CONTENT);
245249
}

src/Messaging/Controller/CampaignController.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
namespace PhpList\RestBundle\Messaging\Controller;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use OpenApi\Attributes as OA;
9+
use PhpList\Core\Domain\Messaging\Message\SyncCampaignProcessorMessage;
810
use PhpList\Core\Domain\Messaging\Model\Message;
9-
use PhpList\Core\Domain\Messaging\Service\Processor\CampaignProcessor;
1011
use PhpList\Core\Security\Authentication;
1112
use PhpList\RestBundle\Common\Controller\BaseController;
1213
use PhpList\RestBundle\Common\Validator\RequestValidator;
@@ -17,6 +18,7 @@
1718
use Symfony\Component\HttpFoundation\JsonResponse;
1819
use Symfony\Component\HttpFoundation\Request;
1920
use Symfony\Component\HttpFoundation\Response;
21+
use Symfony\Component\Messenger\MessageBusInterface;
2022
use Symfony\Component\Routing\Attribute\Route;
2123

2224
/**
@@ -28,17 +30,18 @@
2830
class CampaignController extends BaseController
2931
{
3032
private CampaignService $campaignService;
31-
private CampaignProcessor $campaignProcessor;
33+
private MessageBusInterface $messageBus;
3234

3335
public function __construct(
3436
Authentication $authentication,
3537
RequestValidator $validator,
3638
CampaignService $campaignService,
37-
CampaignProcessor $campaignProcessor,
39+
MessageBusInterface $messageBus,
40+
private readonly EntityManagerInterface $entityManager,
3841
) {
3942
parent::__construct($authentication, $validator);
4043
$this->campaignService = $campaignService;
41-
$this->campaignProcessor = $campaignProcessor;
44+
$this->messageBus = $messageBus;
4245
}
4346

4447
#[Route('', name: 'get_list', methods: ['GET'])]
@@ -211,11 +214,10 @@ public function createMessage(Request $request): JsonResponse
211214

212215
/** @var CreateMessageRequest $createMessageRequest */
213216
$createMessageRequest = $this->validator->validate($request, CreateMessageRequest::class);
217+
$message = $this->campaignService->createMessage($createMessageRequest, $authUser);
218+
$this->entityManager->flush();
214219

215-
return $this->json(
216-
$this->campaignService->createMessage($createMessageRequest, $authUser),
217-
Response::HTTP_CREATED
218-
);
220+
return $this->json(data: $message, status: Response::HTTP_CREATED);
219221
}
220222

221223
#[Route('/{messageId}', name: 'update', requirements: ['messageId' => '\d+'], methods: ['PUT'])]
@@ -284,11 +286,10 @@ public function updateMessage(
284286

285287
/** @var UpdateMessageRequest $updateMessageRequest */
286288
$updateMessageRequest = $this->validator->validate($request, UpdateMessageRequest::class);
289+
$message = $this->campaignService->updateMessage($updateMessageRequest, $authUser, $message);
290+
$this->entityManager->flush();
287291

288-
return $this->json(
289-
$this->campaignService->updateMessage($updateMessageRequest, $authUser, $message),
290-
Response::HTTP_OK
291-
);
292+
return $this->json(data:$message, status: Response::HTTP_OK);
292293
}
293294

294295
#[Route('/{messageId}', name: 'delete', requirements: ['messageId' => '\d+'], methods: ['DELETE'])]
@@ -339,6 +340,7 @@ public function deleteMessage(
339340
$authUser = $this->requireAuthentication($request);
340341

341342
$this->campaignService->deleteMessage($authUser, $message);
343+
$this->entityManager->flush();
342344

343345
return $this->json(null, Response::HTTP_NO_CONTENT);
344346
}
@@ -388,7 +390,7 @@ public function sendMessage(
388390
throw $this->createNotFoundException('Campaign not found.');
389391
}
390392

391-
$this->campaignProcessor->process($message);
393+
$this->messageBus->dispatch(new SyncCampaignProcessorMessage($message->getId()));
392394

393395
return $this->json($this->campaignService->getMessage($message), Response::HTTP_OK);
394396
}

src/Messaging/Controller/ListMessageController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\RestBundle\Messaging\Controller;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use OpenApi\Attributes as OA;
89
use PhpList\Core\Domain\Messaging\Model\Message;
910
use PhpList\Core\Domain\Messaging\Service\Manager\ListMessageManager;
@@ -37,7 +38,8 @@ public function __construct(
3738
ListMessageManager $listMessageManager,
3839
ListMessageNormalizer $listMessageNormalizer,
3940
SubscriberListNormalizer $subscriberListNormalizer,
40-
MessageNormalizer $messageNormalizer
41+
MessageNormalizer $messageNormalizer,
42+
private readonly EntityManagerInterface $entityManager,
4143
) {
4244
parent::__construct($authentication, $validator);
4345
$this->listMessageManager = $listMessageManager;
@@ -262,6 +264,7 @@ public function associateMessageWithList(
262264
}
263265

264266
$listMessage = $this->listMessageManager->associateMessageWithList($message, $subscriberList);
267+
$this->entityManager->flush();
265268

266269
return $this->json(
267270
data: $this->listMessageNormalizer->normalize($listMessage),

src/Messaging/Controller/TemplateController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\RestBundle\Messaging\Controller;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use OpenApi\Attributes as OA;
89
use PhpList\Core\Domain\Messaging\Model\Template;
910
use PhpList\Core\Domain\Messaging\Service\Manager\TemplateManager;
@@ -37,6 +38,7 @@ public function __construct(
3738
TemplateNormalizer $normalizer,
3839
TemplateManager $templateManager,
3940
PaginatedDataProvider $paginatedDataProvider,
41+
private readonly EntityManagerInterface $entityManager,
4042
) {
4143
parent::__construct($authentication, $validator);
4244
$this->normalizer = $normalizer;
@@ -260,9 +262,11 @@ public function createTemplates(Request $request): JsonResponse
260262

261263
/** @var CreateTemplateRequest $createTemplateRequest */
262264
$createTemplateRequest = $this->validator->validate($request, CreateTemplateRequest::class);
265+
$template = $this->templateManager->create($createTemplateRequest->getDto());
266+
$this->entityManager->flush();
263267

264268
return $this->json(
265-
$this->normalizer->normalize($this->templateManager->create($createTemplateRequest->getDto())),
269+
$this->normalizer->normalize($template),
266270
Response::HTTP_CREATED
267271
);
268272
}
@@ -318,6 +322,7 @@ public function delete(
318322
}
319323

320324
$this->templateManager->delete($template);
325+
$this->entityManager->flush();
321326

322327
return $this->json(null, Response::HTTP_NO_CONTENT);
323328
}

0 commit comments

Comments
 (0)