Skip to content
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
14 changes: 13 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"role": "Maintainer"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/TatevikGr/rss-bundle.git"
}
],
"support": {
"issues": "https://github.com/phpList/rest-api/issues",
"forum": "https://discuss.phplist.org/",
Expand All @@ -41,7 +47,8 @@
"symfony/test-pack": "^1.0",
"symfony/process": "^6.4",
"zircote/swagger-php": "^4.11",
"ext-dom": "*"
"ext-dom": "*",
"tatevikgr/rss-feed": "dev-main as 0.1.0"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
Expand Down Expand Up @@ -123,5 +130,10 @@
}
}
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
5 changes: 5 additions & 0 deletions config/services/messenger_handlers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
PhpList\Core\Domain\Messaging\MessageHandler\CampaignProcessorMessageHandler:
autowire: true
autoconfigure: true
public: false
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\RestBundle\Identity\Controller;

use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Identity\Model\AdminAttributeDefinition;
use PhpList\Core\Domain\Identity\Service\AdminAttributeDefinitionManager;
Expand Down Expand Up @@ -32,7 +33,8 @@ public function __construct(
RequestValidator $validator,
AdminAttributeDefinitionManager $definitionManager,
AdminAttributeDefinitionNormalizer $normalizer,
PaginatedDataProvider $paginatedDataProvider
PaginatedDataProvider $paginatedDataProvider,
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct($authentication, $validator);
$this->definitionManager = $definitionManager;
Expand Down Expand Up @@ -89,6 +91,8 @@ public function create(Request $request): JsonResponse
$definitionRequest = $this->validator->validate($request, CreateAttributeDefinitionRequest::class);

$attributeDefinition = $this->definitionManager->create($definitionRequest->getDto());
$this->entityManager->flush();

$json = $this->normalizer->normalize($attributeDefinition, 'json');

return $this->json($json, Response::HTTP_CREATED);
Expand Down Expand Up @@ -156,6 +160,7 @@ public function update(
attributeDefinition: $attributeDefinition,
attributeDefinitionDto: $definitionRequest->getDto(),
);
$this->entityManager->flush();
$json = $this->normalizer->normalize($attributeDefinition, 'json');

return $this->json($json, Response::HTTP_OK);
Expand Down Expand Up @@ -211,6 +216,7 @@ public function delete(
}

$this->definitionManager->delete($attributeDefinition);
$this->entityManager->flush();

return $this->json(null, Response::HTTP_NO_CONTENT);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Identity/Controller/AdminAttributeValueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public function delete(
throw $this->createNotFoundException('Administrator attribute not found.');
}
$this->attributeManager->delete($attribute);
$this->entityManager->flush();

return $this->json(null, Response::HTTP_NO_CONTENT);
}
Expand Down Expand Up @@ -355,6 +356,7 @@ public function getAttributeDefinition(
attributeDefinitionId: $definition->getId()
);
$this->attributeManager->delete($attribute);
$this->entityManager->flush();

return $this->json(
$this->normalizer->normalize($attribute),
Expand Down
7 changes: 6 additions & 1 deletion src/Identity/Controller/AdministratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\RestBundle\Identity\Controller;

use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Identity\Model\Administrator;
use PhpList\Core\Domain\Identity\Service\AdministratorManager;
Expand Down Expand Up @@ -35,7 +36,8 @@ public function __construct(
RequestValidator $validator,
AdministratorManager $administratorManager,
AdministratorNormalizer $normalizer,
PaginatedDataProvider $paginatedProvider
PaginatedDataProvider $paginatedProvider,
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct($authentication, $validator);
$this->administratorManager = $administratorManager;
Expand Down Expand Up @@ -149,6 +151,7 @@ public function createAdministrator(
$createRequest = $validator->validate($request, CreateAdministratorRequest::class);

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

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

return $this->json($this->normalizer->normalize($administrator), Response::HTTP_OK);
}
Expand Down Expand Up @@ -303,6 +307,7 @@ public function deleteAdministrator(
throw $this->createNotFoundException('Administrator not found.');
}
$this->administratorManager->deleteAdministrator($administrator);
$this->entityManager->flush();

return $this->json(null, Response::HTTP_NO_CONTENT);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Identity/Controller/PasswordResetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\RestBundle\Identity\Controller;

use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Identity\Service\PasswordManager;
use PhpList\Core\Security\Authentication;
Expand All @@ -29,6 +30,7 @@ public function __construct(
Authentication $authentication,
RequestValidator $validator,
PasswordManager $passwordManager,
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct($authentication, $validator);

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

$this->passwordManager->generatePasswordResetToken($resetRequest->email);
$this->entityManager->flush();

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

$administrator = $this->passwordManager->validatePasswordResetToken($validateRequest->token);
$this->entityManager->flush();

return $this->json([ 'valid' => $administrator !== null]);
}
Expand Down Expand Up @@ -169,6 +173,7 @@ public function resetPassword(Request $request): JsonResponse
$resetRequest->token,
$resetRequest->newPassword
);
$this->entityManager->flush();

if ($success) {
return $this->json([ 'message' => 'Password updated successfully']);
Expand Down
4 changes: 4 additions & 0 deletions src/Identity/Controller/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\RestBundle\Identity\Controller;

use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Identity\Model\AdministratorToken;
use PhpList\Core\Domain\Identity\Service\SessionManager;
Expand Down Expand Up @@ -34,6 +35,7 @@ public function __construct(
Authentication $authentication,
RequestValidator $validator,
SessionManager $sessionManager,
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct($authentication, $validator);

Expand Down Expand Up @@ -96,6 +98,7 @@ public function createSession(
loginName:$createSessionRequest->loginName,
password: $createSessionRequest->password
);
$this->entityManager->flush();

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

Expand Down Expand Up @@ -163,6 +166,7 @@ public function deleteSession(
}

$this->sessionManager->deleteSession($token);
$this->entityManager->flush();

return $this->json(null, Response::HTTP_NO_CONTENT);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Messaging/Controller/BounceRegexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\RestBundle\Messaging\Controller;

use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Service\Manager\BounceRegexManager;
use PhpList\Core\Security\Authentication;
Expand All @@ -27,6 +28,7 @@ public function __construct(
RequestValidator $validator,
private readonly BounceRegexManager $manager,
private readonly BounceRegexNormalizer $normalizer,
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct($authentication, $validator);
}
Expand Down Expand Up @@ -188,6 +190,7 @@ public function createOrUpdate(Request $request): JsonResponse
comment: $dto->comment,
status: $dto->status
);
$this->entityManager->flush();

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

return $this->json(null, Response::HTTP_NO_CONTENT);
}
Expand Down
28 changes: 15 additions & 13 deletions src/Messaging/Controller/CampaignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace PhpList\RestBundle\Messaging\Controller;

use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Message\SyncCampaignProcessorMessage;
use PhpList\Core\Domain\Messaging\Model\Message;
use PhpList\Core\Domain\Messaging\Service\Processor\CampaignProcessor;
use PhpList\Core\Security\Authentication;
use PhpList\RestBundle\Common\Controller\BaseController;
use PhpList\RestBundle\Common\Validator\RequestValidator;
Expand All @@ -17,6 +18,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Attribute\Route;

/**
Expand All @@ -28,17 +30,18 @@
class CampaignController extends BaseController
{
private CampaignService $campaignService;
private CampaignProcessor $campaignProcessor;
private MessageBusInterface $messageBus;

public function __construct(
Authentication $authentication,
RequestValidator $validator,
CampaignService $campaignService,
CampaignProcessor $campaignProcessor,
MessageBusInterface $messageBus,
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct($authentication, $validator);
$this->campaignService = $campaignService;
$this->campaignProcessor = $campaignProcessor;
$this->messageBus = $messageBus;
}

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

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

return $this->json(
$this->campaignService->createMessage($createMessageRequest, $authUser),
Response::HTTP_CREATED
);
return $this->json(data: $message, status: Response::HTTP_CREATED);
}

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

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

return $this->json(
$this->campaignService->updateMessage($updateMessageRequest, $authUser, $message),
Response::HTTP_OK
);
return $this->json(data:$message, status: Response::HTTP_OK);
}

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

$this->campaignService->deleteMessage($authUser, $message);
$this->entityManager->flush();

return $this->json(null, Response::HTTP_NO_CONTENT);
}
Expand Down Expand Up @@ -388,7 +390,7 @@ public function sendMessage(
throw $this->createNotFoundException('Campaign not found.');
}

$this->campaignProcessor->process($message);
$this->messageBus->dispatch(new SyncCampaignProcessorMessage($message->getId()));

return $this->json($this->campaignService->getMessage($message), Response::HTTP_OK);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Messaging/Controller/ListMessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\RestBundle\Messaging\Controller;

use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Messaging\Model\Message;
use PhpList\Core\Domain\Messaging\Service\Manager\ListMessageManager;
Expand Down Expand Up @@ -37,7 +38,8 @@ public function __construct(
ListMessageManager $listMessageManager,
ListMessageNormalizer $listMessageNormalizer,
SubscriberListNormalizer $subscriberListNormalizer,
MessageNormalizer $messageNormalizer
MessageNormalizer $messageNormalizer,
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct($authentication, $validator);
$this->listMessageManager = $listMessageManager;
Expand Down Expand Up @@ -262,6 +264,7 @@ public function associateMessageWithList(
}

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

return $this->json(
data: $this->listMessageNormalizer->normalize($listMessage),
Expand Down
7 changes: 6 additions & 1 deletion src/Messaging/Controller/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpList\RestBundle\Messaging\Controller;

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

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

return $this->json(
$this->normalizer->normalize($this->templateManager->create($createTemplateRequest->getDto())),
$this->normalizer->normalize($template),
Response::HTTP_CREATED
);
}
Expand Down Expand Up @@ -318,6 +322,7 @@ public function delete(
}

$this->templateManager->delete($template);
$this->entityManager->flush();

return $this->json(null, Response::HTTP_NO_CONTENT);
}
Expand Down
Loading
Loading