Skip to content

Commit

Permalink
[#35] - Renames the message table and make the necessary changes to t…
Browse files Browse the repository at this point in the history
…he classes that manipulates it.
  • Loading branch information
cristiano-pacheco committed Feb 2, 2024
1 parent 1f2cb77 commit 5589b4c
Show file tree
Hide file tree
Showing 40 changed files with 196 additions and 170 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"sniffer": "vendor/bin/phpcs --colors -p ./src --standard=phpcs-ruleset.xml",
"fix-style": "vendor/bin/phpcbf --colors -p ./src --standard=phpcs-ruleset.xml",
"sniffer:php8.1": "vendor/bin/phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.1",
"sniffer:php8.2": "vendor/bin/phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.2",
"mess-detector": "vendor/bin/phpmd src html phpmd-ruleset.xml --exclude \"Test\" --strict --reportfile reports/phpmd/phpmd.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace RunAsRoot\MessageQueueRetry\Api\Data;

interface MessageInterface
interface QueueErrorMessageInterface
{
public const TABLE_NAME = 'run_as_root_message';
public const TABLE_NAME = 'run_as_root_queue_error_message';
public const ENTITY_ID = 'entity_id';
public const TOPIC_NAME = 'topic_name';
public const MESSAGE_BODY = 'message_body';
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/MessageBodyDownloadFileNameBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace RunAsRoot\MessageQueueRetry\Builder;

use RunAsRoot\MessageQueueRetry\Model\Message;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage;

class MessageBodyDownloadFileNameBuilder
{
public function build(Message $message): string
public function build(QueueErrorMessage $message): string
{
return $message->getTopicName() . '_' . $message->getId() . '.json';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Adminhtml/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function execute(): Page
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__('Messages')->render());
$resultPage->getConfig()->getTitle()->prepend(__('Queue Error Messages')->render());
$resultPage->setActiveMenu('RunAsRoot_MessageQueueRetry::message_queue_retry');

return $resultPage;
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/Adminhtml/Message/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
use Magento\Framework\Controller\Result\RawFactory;
use RunAsRoot\MessageQueueRetry\Exception\EmptyQueueMessageBodyException;
use RunAsRoot\MessageQueueRetry\Exception\MessageNotFoundException;
use RunAsRoot\MessageQueueRetry\Mapper\MessageToRawResponseMapper;
use RunAsRoot\MessageQueueRetry\Repository\MessageRepository;
use RunAsRoot\MessageQueueRetry\Mapper\QueueErrorMessageToRawResponseMapper;
use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository;

class Download extends Action
{
public const ADMIN_RESOURCE = 'RunAsRoot_MessageQueueRetry::download';

public function __construct(
Context $context,
private MessageRepository $messageRepository,
private QueueErrorMessageRepository $messageRepository,
private RawFactory $rawFactory,
private MessageToRawResponseMapper $messageToRawResponseMapper
private QueueErrorMessageToRawResponseMapper $messageToRawResponseMapper
) {
parent::__construct($context);
}
Expand Down
17 changes: 10 additions & 7 deletions src/Controller/Adminhtml/Message/MassDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Ui\Component\MassAction\Filter;
use RunAsRoot\MessageQueueRetry\Model\Message;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollectionFactory;
use RunAsRoot\MessageQueueRetry\Repository\MessageRepository;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollectionFactory;
use RunAsRoot\MessageQueueRetry\Repository\QueueErrorMessageRepository;

class MassDelete extends Action
{
public const ADMIN_RESOURCE = 'RunAsRoot_MessageQueueRetry::mass_delete';

public function __construct(
Context $context,
private MessageRepository $messageRepository,
private QueueErrorMessageRepository $messageRepository,
private RedirectFactory $redirectFactory,
private MessageCollectionFactory $collectionFactory,
private QueueErrorMessageCollectionFactory $collectionFactory,
private Filter $filter
) {
parent::__construct($context);
Expand All @@ -32,10 +33,12 @@ public function execute(): Redirect
$redirect = $this->redirectFactory->create();

try {
$collection = $this->filter->getCollection($this->collectionFactory->create());
/** @var AbstractDb $messageCollection */
$messageCollection = $this->collectionFactory->create();
$collection = $this->filter->getCollection($messageCollection);

foreach ($collection->getItems() as $message) {
if (!$message instanceof Message) {
if (!$message instanceof QueueErrorMessage) {
continue;
}

Expand Down
13 changes: 8 additions & 5 deletions src/Controller/Adminhtml/Message/MassRequeue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Ui\Component\MassAction\Filter;
use RunAsRoot\MessageQueueRetry\Model\Message;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollectionFactory;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollectionFactory;
use RunAsRoot\MessageQueueRetry\Service\PublishMessageToQueueService;

class MassRequeue extends Action
Expand All @@ -21,7 +22,7 @@ public function __construct(
Context $context,
private PublishMessageToQueueService $publishMessageToQueueService,
private RedirectFactory $redirectFactory,
private MessageCollectionFactory $collectionFactory,
private QueueErrorMessageCollectionFactory $collectionFactory,
private Filter $filter
) {
parent::__construct($context);
Expand All @@ -32,10 +33,12 @@ public function execute(): Redirect
$redirect = $this->redirectFactory->create();

try {
$collection = $this->filter->getCollection($this->collectionFactory->create());
/** @var AbstractDb $messageCollection */
$messageCollection = $this->collectionFactory->create();
$collection = $this->filter->getCollection($messageCollection);

foreach ($collection->getItems() as $message) {
if (!$message instanceof Message) {
if (!$message instanceof QueueErrorMessage) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Magento\Framework\Controller\Result\Raw as RawResponse;
use RunAsRoot\MessageQueueRetry\Builder\MessageBodyDownloadFileNameBuilder;
use RunAsRoot\MessageQueueRetry\Exception\EmptyQueueMessageBodyException;
use RunAsRoot\MessageQueueRetry\Model\Message;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage;

class MessageToRawResponseMapper
class QueueErrorMessageToRawResponseMapper
{
public function __construct(
private MessageBodyDownloadFileNameBuilder $messageBodyDownloadFileNameBuilder
Expand All @@ -19,7 +19,7 @@ public function __construct(
/**
* @throws EmptyQueueMessageBodyException
*/
public function map(Message $message, RawResponse $rawResponse): RawResponse
public function map(QueueErrorMessage $message, RawResponse $rawResponse): RawResponse
{
$messageBody = $message->getMessageBody();

Expand Down
12 changes: 6 additions & 6 deletions src/Model/Message.php → src/Model/QueueErrorMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace RunAsRoot\MessageQueueRetry\Model;

use Magento\Framework\Model\AbstractModel;
use RunAsRoot\MessageQueueRetry\Api\Data\MessageInterface;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\Message\MessageCollection;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource;
use RunAsRoot\MessageQueueRetry\Api\Data\QueueErrorMessageInterface;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage\QueueErrorMessageCollection;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource;

class Message extends AbstractModel implements MessageInterface
class QueueErrorMessage extends AbstractModel implements QueueErrorMessageInterface
{
public function getTopicName(): string
{
Expand Down Expand Up @@ -73,7 +73,7 @@ public function setCreatedAt(string $value): void

protected function _construct(): void
{
$this->_init(MessageResource::class);
$this->_collectionName = MessageCollection::class;
$this->_init(QueueErrorMessageResource::class);
$this->_collectionName = QueueErrorMessageCollection::class;
}
}
17 changes: 0 additions & 17 deletions src/Model/ResourceModel/Message/MessageCollection.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Model/ResourceModel/MessageResource.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessage;

use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage as Model;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel;

class QueueErrorMessageCollection extends AbstractCollection
{
protected function _construct(): void
{
$this->_init(Model::class, ResourceModel::class);
}
}
16 changes: 16 additions & 0 deletions src/Model/ResourceModel/QueueErrorMessageResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace RunAsRoot\MessageQueueRetry\Model\ResourceModel;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use RunAsRoot\MessageQueueRetry\Api\Data\QueueErrorMessageInterface;

class QueueErrorMessageResource extends AbstractDb
{
protected function _construct(): void
{
$this->_init(QueueErrorMessageInterface::TABLE_NAME, QueueErrorMessageInterface::ENTITY_ID);
}
}
6 changes: 3 additions & 3 deletions src/Repository/Command/CreateMessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace RunAsRoot\MessageQueueRetry\Repository\Command;

use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeCreatedException;
use RunAsRoot\MessageQueueRetry\Model\Message;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel;

class CreateMessageCommand
{
Expand All @@ -17,7 +17,7 @@ public function __construct(private ResourceModel $resourceModel)
/**
* @throws MessageCouldNotBeCreatedException
*/
public function execute(Message $message): Message
public function execute(QueueErrorMessage $message): QueueErrorMessage
{
try {
$this->resourceModel->save($message);
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/Command/DeleteMessageByIdCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace RunAsRoot\MessageQueueRetry\Repository\Command;

use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel;
use RunAsRoot\MessageQueueRetry\Repository\Query\FindMessageByIdQuery;

class DeleteMessageByIdCommand
Expand Down
6 changes: 3 additions & 3 deletions src/Repository/Command/DeleteMessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace RunAsRoot\MessageQueueRetry\Repository\Command;

use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException;
use RunAsRoot\MessageQueueRetry\Model\Message;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel;

class DeleteMessageCommand
{
Expand All @@ -17,7 +17,7 @@ public function __construct(private ResourceModel $resourceModel)
/**
* @throws MessageCouldNotBeDeletedException
*/
public function execute(Message $message): void
public function execute(QueueErrorMessage $message): void
{
try {
$this->resourceModel->delete($message);
Expand Down
8 changes: 4 additions & 4 deletions src/Repository/Query/FindMessageByIdQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace RunAsRoot\MessageQueueRetry\Repository\Query;

use RunAsRoot\MessageQueueRetry\Exception\MessageNotFoundException;
use RunAsRoot\MessageQueueRetry\Model\Message;
use RunAsRoot\MessageQueueRetry\Model\MessageFactory as ModelFactory;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\MessageResource as ResourceModel;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessageFactory as ModelFactory;
use RunAsRoot\MessageQueueRetry\Model\ResourceModel\QueueErrorMessageResource as ResourceModel;

class FindMessageByIdQuery
{
Expand All @@ -20,7 +20,7 @@ public function __construct(
/**
* @throws MessageNotFoundException
*/
public function execute(int $entityId): Message
public function execute(int $entityId): QueueErrorMessage
{
$model = $this->modelFactory->create();
$this->resourceModel->load($model, $entityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeCreatedException;
use RunAsRoot\MessageQueueRetry\Exception\MessageCouldNotBeDeletedException;
use RunAsRoot\MessageQueueRetry\Exception\MessageNotFoundException;
use RunAsRoot\MessageQueueRetry\Model\Message;
use RunAsRoot\MessageQueueRetry\Model\QueueErrorMessage;
use RunAsRoot\MessageQueueRetry\Repository\Command\CreateMessageCommand;
use RunAsRoot\MessageQueueRetry\Repository\Command\DeleteMessageByIdCommand;
use RunAsRoot\MessageQueueRetry\Repository\Command\DeleteMessageCommand;
use RunAsRoot\MessageQueueRetry\Repository\Query\FindMessageByIdQuery;

class MessageRepository
class QueueErrorMessageRepository
{
public function __construct(
private CreateMessageCommand $createMessageCommand,
Expand All @@ -26,15 +26,15 @@ public function __construct(
/**
* @throws MessageNotFoundException
*/
public function findById(int $id): Message
public function findById(int $id): QueueErrorMessage
{
return $this->findMessageByIdQuery->execute($id);
}

/**
* @throws MessageCouldNotBeCreatedException
*/
public function create(Message $message): Message
public function create(QueueErrorMessage $message): QueueErrorMessage
{
return $this->createMessageCommand->execute($message);
}
Expand All @@ -50,7 +50,7 @@ public function deleteById(int $id): void
/**
* @throws MessageCouldNotBeDeletedException
*/
public function delete(Message $message): void
public function delete(QueueErrorMessage $message): void
{
$this->deleteMessageCommand->execute($message);
}
Expand Down
Loading

0 comments on commit 5589b4c

Please sign in to comment.