-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b6774b
commit 315bf28
Showing
7 changed files
with
48 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EmrecanMuslu\Messenger\Transport\NotificationTransport; | ||
|
||
use App\Message\NotificationSmsMessage; | ||
use Doctrine\DBAL\Connection as DBALConnection; | ||
use Doctrine\DBAL\DBALException; | ||
use Doctrine\DBAL\Driver\Result as DriverResult; | ||
|
@@ -31,12 +21,6 @@ | |
use Symfony\Component\Messenger\Exception\TransportException; | ||
use Symfony\Contracts\Service\ResetInterface; | ||
|
||
/** | ||
* @internal since Symfony 5.1 | ||
* | ||
* @author Vincent Touzet <[email protected]> | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
class Connection implements ResetInterface | ||
{ | ||
protected const TABLE_OPTION_NAME = '_symfony_messenger_table_name'; | ||
|
@@ -134,12 +118,16 @@ public function send(Envelope $envelope, string $encodedMessage, array $headers, | |
$notificationSmsMessage = $envelope->getMessage()->getMessage(); | ||
$notificationSmsTemplate = $notificationSmsMessage->getTemplate(); | ||
$notificationSmsOrderDetail = $notificationSmsMessage->getOrderDetails(); | ||
|
||
$orderId = $notificationSmsOrderDetail->getId(); | ||
$template_name = $this->configuration['template_name']; | ||
$now = new \DateTime(); | ||
$availableAt = (clone $now)->modify(sprintf('+%d seconds', $delay / 1000)); | ||
|
||
$queryBuilder = $this->driverConnection->createQueryBuilder() | ||
->insert($this->configuration['table_name']) | ||
$checkRowId = $this->createQueryBuilderCheckRow($orderId, $template_name); | ||
$queryBuilder = $this->driverConnection->createQueryBuilder(); | ||
|
||
if(null === $checkRowId){ | ||
$queryBuilder->insert($this->configuration['table_name']) | ||
->values([ | ||
'order_id' => '?', | ||
'encoded_message' => '?', | ||
|
@@ -152,30 +140,44 @@ public function send(Envelope $envelope, string $encodedMessage, array $headers, | |
'created_at' => '?', | ||
'available_at' => '?', | ||
]); | ||
}else{ | ||
$queryBuilder->update($this->configuration['table_name']) | ||
->where("id = $checkRowId") | ||
->set('order_id','?') | ||
->set('encoded_message','?') | ||
->set('headers','?') | ||
->set('provider_name','?') | ||
->set('template_name','?') | ||
->set('handled','?') | ||
->set('created_at','?') | ||
->set('available_at','?'); | ||
} | ||
|
||
|
||
$this->executeStatement($queryBuilder->getSQL(), [ | ||
$notificationSmsOrderDetail->getId(), | ||
|
||
$queryBuilder->setParameters([ | ||
$orderId, | ||
$encodedMessage, | ||
json_encode($headers), | ||
$this->configuration['provider_name'], | ||
$this->configuration['template_name'], | ||
null, | ||
null, | ||
$template_name, | ||
0, | ||
$now, | ||
$availableAt, | ||
$availableAt | ||
], [ | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null, | ||
Types::DATETIME_MUTABLE, | ||
Types::DATETIME_MUTABLE, | ||
Types::DATETIME_MUTABLE | ||
]); | ||
|
||
$sql = $queryBuilder->getSQL(); | ||
|
||
$this->executeStatement($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes()); | ||
|
||
return $this->driverConnection->lastInsertId(); | ||
} | ||
|
@@ -372,6 +374,24 @@ private function createQueryBuilder(): QueryBuilder | |
->from($this->configuration['table_name'], 'm'); | ||
} | ||
|
||
private function createQueryBuilderCheckRow(int $orderId, string $template_name): int | ||
{ | ||
$queryBuilder = $this->driverConnection->createQueryBuilder() | ||
->select('*') | ||
->from($this->configuration['table_name']) | ||
->where('order_id = ?') | ||
->andWhere('template_name = ?') | ||
->setParameters([ | ||
$orderId, | ||
$template_name, | ||
]) | ||
->setMaxResults(1); | ||
|
||
$result = $this->executeQuery($queryBuilder->getSQL(), $queryBuilder->getParameters(), $queryBuilder->getParameterTypes()); | ||
|
||
return $result instanceof Result || $result instanceof DriverResult ? $result->fetchOne() : $result->fetchColumn(); | ||
} | ||
|
||
private function executeQuery(string $sql, array $parameters = [], array $types = []) | ||
{ | ||
try { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EmrecanMuslu\Messenger\Transport\NotificationTransport; | ||
|
||
use Symfony\Component\Messenger\Stamp\NonSendableStampInterface; | ||
|
||
/** | ||
* @author Vincent Touzet <[email protected]> | ||
*/ | ||
class DoctrineReceivedStamp implements NonSendableStampInterface | ||
{ | ||
private $id; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EmrecanMuslu\Messenger\Transport\NotificationTransport; | ||
|
||
use Doctrine\DBAL\DBALException; | ||
|
@@ -24,9 +15,6 @@ | |
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; | ||
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; | ||
|
||
/** | ||
* @author Vincent Touzet <[email protected]> | ||
*/ | ||
class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface, ListableReceiverInterface | ||
{ | ||
private const MAX_RETRIES = 3; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EmrecanMuslu\Messenger\Transport\NotificationTransport; | ||
|
||
use Doctrine\DBAL\DBALException; | ||
|
@@ -20,10 +11,6 @@ | |
use Symfony\Component\Messenger\Transport\Sender\SenderInterface; | ||
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; | ||
|
||
|
||
/** | ||
* @author Vincent Touzet <[email protected]> | ||
*/ | ||
class DoctrineSender implements SenderInterface | ||
{ | ||
private $connection; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EmrecanMuslu\Messenger\Transport\NotificationTransport; | ||
|
||
use Doctrine\DBAL\Connection as DbalConnection; | ||
|
@@ -21,9 +12,6 @@ | |
use Symfony\Component\Messenger\Transport\SetupableTransportInterface; | ||
use Symfony\Component\Messenger\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Vincent Touzet <[email protected]> | ||
*/ | ||
class DoctrineTransport implements TransportInterface, SetupableTransportInterface, MessageCountAwareInterface, ListableReceiverInterface | ||
{ | ||
private $connection; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EmrecanMuslu\Messenger\Transport\NotificationTransport; | ||
|
||
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; | ||
|
@@ -20,9 +11,6 @@ | |
use Symfony\Component\Messenger\Transport\TransportFactoryInterface; | ||
use Symfony\Component\Messenger\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Vincent Touzet <[email protected]> | ||
*/ | ||
class DoctrineTransportFactory implements TransportFactoryInterface | ||
{ | ||
private $registry; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,9 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EmrecanMuslu\Messenger\Transport\NotificationTransport; | ||
|
||
use Doctrine\DBAL\Schema\Table; | ||
|
||
/** | ||
* Uses PostgreSQL LISTEN/NOTIFY to push messages to workers. | ||
* | ||
* @internal | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
final class PostgreSqlConnection extends Connection | ||
{ | ||
/** | ||
|