From 5d739704f2a0ad0de0ac34db9730681da99da4d5 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sun, 28 Jul 2019 22:26:18 +0200 Subject: [PATCH 1/4] [Messenger] Fix incompatibility with FrameworkBundle <4.3.1 --- .../FrameworkBundle/Resources/config/console.xml | 2 +- .../Messenger/Command/ConsumeMessagesCommand.php | 2 ++ .../Messenger/DependencyInjection/MessengerPass.php | 11 ++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml index ebd7d6ce46..c0d185a00f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml @@ -82,7 +82,7 @@ - + diff --git a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php index be6f4c1733..79c4aa3597 100644 --- a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php +++ b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php @@ -57,6 +57,8 @@ class ConsumeMessagesCommand extends Command // to be deprecated in 4.4 if ($routableBus instanceof ContainerInterface) { $routableBus = new RoutableMessageBus($routableBus); + } elseif (!$routableBus instanceof RoutableMessageBus) { + throw new \TypeError(sprintf('The first argument must be an instance of "%s".', RoutableMessageBus::class)); } if (\is_array($retryStrategyLocator)) { diff --git a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php index b83272792f..8836c4ac83 100644 --- a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php +++ b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php @@ -253,14 +253,19 @@ class MessengerPass implements CompilerPassInterface $buses[$busId] = new Reference($busId); } - if ($container->hasDefinition('messenger.routable_message_bus')) { + if ($hasRoutableMessageBus = $container->hasDefinition('messenger.routable_message_bus')) { $container->getDefinition('messenger.routable_message_bus') ->replaceArgument(0, ServiceLocatorTagPass::register($container, $buses)); } if ($container->hasDefinition('console.command.messenger_consume_messages')) { - $container->getDefinition('console.command.messenger_consume_messages') - ->replaceArgument(3, array_values($receiverNames)); + $consumeCommandDefinition = $container->getDefinition('console.command.messenger_consume_messages'); + + if ($hasRoutableMessageBus) { + $consumeCommandDefinition->replaceArgument(0, new Reference('messenger.routable_message_bus')); + } + + $consumeCommandDefinition->replaceArgument(3, array_values($receiverNames)); } if ($container->hasDefinition('console.command.messenger_setup_transports')) { From b500f929219742d78c0223b577e5d3318661832b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kowalewski?= Date: Tue, 30 Jul 2019 16:40:17 +0200 Subject: [PATCH 2/4] Create mailBody with only attachments part present --- src/Symfony/Component/Mime/Email.php | 12 ++++++++---- src/Symfony/Component/Mime/Tests/EmailTest.php | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Mime/Email.php b/src/Symfony/Component/Mime/Email.php index 3fbebc461f..1bcdc8a1cd 100644 --- a/src/Symfony/Component/Mime/Email.php +++ b/src/Symfony/Component/Mime/Email.php @@ -423,12 +423,12 @@ class Email extends Message */ private function generateBody(): AbstractPart { - if (null === $this->text && null === $this->html) { - throw new LogicException('A message must have a text and/or an HTML part.'); + [$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts(); + if (null === $this->text && null === $this->html && !$attachmentParts) { + throw new LogicException('A message must have a text or an HTML part or attachments.'); } $part = null === $this->text ? null : new TextPart($this->text, $this->textCharset); - [$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts(); if (null !== $htmlPart) { if (null !== $part) { $part = new AlternativePart($part, $htmlPart); @@ -442,7 +442,11 @@ class Email extends Message } if ($attachmentParts) { - $part = new MixedPart($part, ...$attachmentParts); + if ($part) { + $part = new MixedPart($part, ...$attachmentParts); + } else { + $part = new MixedPart(...$attachmentParts); + } } return $part; diff --git a/src/Symfony/Component/Mime/Tests/EmailTest.php b/src/Symfony/Component/Mime/Tests/EmailTest.php index 1d45cab9f4..d8a982add7 100644 --- a/src/Symfony/Component/Mime/Tests/EmailTest.php +++ b/src/Symfony/Component/Mime/Tests/EmailTest.php @@ -284,6 +284,10 @@ class EmailTest extends TestCase $e->html('html content'); $this->assertEquals(new MixedPart($html, $att), $e->getBody()); + $e = new Email(); + $e->attach($file); + $this->assertEquals(new MixedPart($att), $e->getBody()); + $e = new Email(); $e->html('html content'); $e->text('text content'); From d2c4bf0da81a1970b871c60f5d09a500deb09314 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 4 Aug 2019 17:48:42 +0200 Subject: [PATCH 3/4] [HttpClient] use "idle" instead of "inactivity" when telling about the timeout option --- .../FrameworkBundle/DependencyInjection/Configuration.php | 2 +- src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php | 2 +- src/Symfony/Contracts/HttpClient/ChunkInterface.php | 8 ++++---- src/Symfony/Contracts/HttpClient/HttpClientInterface.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 488d56aac0..b4ce6a2c6a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1348,7 +1348,7 @@ class Configuration implements ConfigurationInterface ->info('A comma separated list of hosts that do not require a proxy to be reached.') ->end() ->floatNode('timeout') - ->info('Defaults to "default_socket_timeout" ini parameter.') + ->info('The idle timeout, defaults to the "default_socket_timeout" ini parameter.') ->end() ->scalarNode('bindto') ->info('A network interface name, IP address, a host name or a UNIX socket to bind to.') diff --git a/src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php b/src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php index 6b1e44f69f..d2a69bc38a 100644 --- a/src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php +++ b/src/Symfony/Component/HttpClient/Chunk/ErrorChunk.php @@ -30,7 +30,7 @@ class ErrorChunk implements ChunkInterface { $this->offset = $offset; $this->error = $error; - $this->errorMessage = null !== $error ? $error->getMessage() : 'Reading from the response stream reached the inactivity timeout.'; + $this->errorMessage = null !== $error ? $error->getMessage() : 'Reading from the response stream reached the idle timeout.'; } /** diff --git a/src/Symfony/Contracts/HttpClient/ChunkInterface.php b/src/Symfony/Contracts/HttpClient/ChunkInterface.php index bbec2cdfa6..d6fd73d894 100644 --- a/src/Symfony/Contracts/HttpClient/ChunkInterface.php +++ b/src/Symfony/Contracts/HttpClient/ChunkInterface.php @@ -27,7 +27,7 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; interface ChunkInterface { /** - * Tells when the inactivity timeout has been reached. + * Tells when the idle timeout has been reached. * * @throws TransportExceptionInterface on a network error */ @@ -36,21 +36,21 @@ interface ChunkInterface /** * Tells when headers just arrived. * - * @throws TransportExceptionInterface on a network error or when the inactivity timeout is reached + * @throws TransportExceptionInterface on a network error or when the idle timeout is reached */ public function isFirst(): bool; /** * Tells when the body just completed. * - * @throws TransportExceptionInterface on a network error or when the inactivity timeout is reached + * @throws TransportExceptionInterface on a network error or when the idle timeout is reached */ public function isLast(): bool; /** * Returns the content of the response chunk. * - * @throws TransportExceptionInterface on a network error or when the inactivity timeout is reached + * @throws TransportExceptionInterface on a network error or when the idle timeout is reached */ public function getContent(): string; diff --git a/src/Symfony/Contracts/HttpClient/HttpClientInterface.php b/src/Symfony/Contracts/HttpClient/HttpClientInterface.php index 6636af7a23..c974ba97e3 100644 --- a/src/Symfony/Contracts/HttpClient/HttpClientInterface.php +++ b/src/Symfony/Contracts/HttpClient/HttpClientInterface.php @@ -52,7 +52,7 @@ interface HttpClientInterface 'resolve' => [], // string[] - a map of host to IP address that SHOULD replace DNS resolution 'proxy' => null, // string - by default, the proxy-related env vars handled by curl SHOULD be honored 'no_proxy' => null, // string - a comma separated list of hosts that do not require a proxy to be reached - 'timeout' => null, // float - the inactivity timeout - defaults to ini_get('default_socket_timeout') + 'timeout' => null, // float - the idle timeout - defaults to ini_get('default_socket_timeout') 'bindto' => '0', // string - the interface or the local socket to bind to 'verify_peer' => true, // see https://php.net/context.ssl for the following options 'verify_host' => true, @@ -85,7 +85,7 @@ interface HttpClientInterface * Yields responses chunk by chunk as they complete. * * @param ResponseInterface|ResponseInterface[]|iterable $responses One or more responses created by the current HTTP client - * @param float|null $timeout The inactivity timeout before exiting the iterator + * @param float|null $timeout The idle timeout before yielding timeout chunks */ public function stream($responses, float $timeout = null): ResponseStreamInterface; } From fc0e4baf2fd34079e84d287694727b2f0095d018 Mon Sep 17 00:00:00 2001 From: David Legatt Date: Wed, 31 Jul 2019 11:11:19 -0500 Subject: [PATCH 4/4] [Messenger] Removed named parameters and replaced with `?` placeholders for sqlsrv compatibility --- .../Transport/Doctrine/Connection.php | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php index d86707b81b..41cf70bbf0 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php @@ -111,19 +111,19 @@ class Connection $queryBuilder = $this->driverConnection->createQueryBuilder() ->insert($this->configuration['table_name']) ->values([ - 'body' => ':body', - 'headers' => ':headers', - 'queue_name' => ':queue_name', - 'created_at' => ':created_at', - 'available_at' => ':available_at', + 'body' => '?', + 'headers' => '?', + 'queue_name' => '?', + 'created_at' => '?', + 'available_at' => '?', ]); $this->executeQuery($queryBuilder->getSQL(), [ - ':body' => $body, - ':headers' => json_encode($headers), - ':queue_name' => $this->configuration['queue_name'], - ':created_at' => self::formatDateTime($now), - ':available_at' => self::formatDateTime($availableAt), + $body, + json_encode($headers), + $this->configuration['queue_name'], + self::formatDateTime($now), + self::formatDateTime($availableAt), ]); return $this->driverConnection->lastInsertId(); @@ -156,12 +156,12 @@ class Connection $queryBuilder = $this->driverConnection->createQueryBuilder() ->update($this->configuration['table_name']) - ->set('delivered_at', ':delivered_at') - ->where('id = :id'); + ->set('delivered_at', '?') + ->where('id = ?'); $now = new \DateTime(); $this->executeQuery($queryBuilder->getSQL(), [ - ':id' => $doctrineEnvelope['id'], - ':delivered_at' => self::formatDateTime($now), + self::formatDateTime($now), + $doctrineEnvelope['id'], ]); $this->driverConnection->commit(); @@ -249,10 +249,10 @@ class Connection } $queryBuilder = $this->createQueryBuilder() - ->where('m.id = :id'); + ->where('m.id = ?'); $data = $this->executeQuery($queryBuilder->getSQL(), [ - 'id' => $id, + $id, ])->fetch(); return false === $data ? null : $this->decodeEnvelopeHeaders($data); @@ -264,13 +264,13 @@ class Connection $redeliverLimit = (clone $now)->modify(sprintf('-%d seconds', $this->configuration['redeliver_timeout'])); return $this->createQueryBuilder() - ->where('m.delivered_at is null OR m.delivered_at < :redeliver_limit') - ->andWhere('m.available_at <= :now') - ->andWhere('m.queue_name = :queue_name') + ->where('m.delivered_at is null OR m.delivered_at < ?') + ->andWhere('m.available_at <= ?') + ->andWhere('m.queue_name = ?') ->setParameters([ - ':now' => self::formatDateTime($now), - ':queue_name' => $this->configuration['queue_name'], - ':redeliver_limit' => self::formatDateTime($redeliverLimit), + self::formatDateTime($redeliverLimit), + self::formatDateTime($now), + $this->configuration['queue_name'], ]); }