Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maintenance] Add missing deprecations to CreditMemoEmailSender #420

Merged
merged 3 commits into from
Feb 12, 2024
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
10 changes: 10 additions & 0 deletions UPGRADE-1.5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### UPGRADE FROM 1.4.X TO 1.5.0

1. Passing `$creditMemoPdfFileGenerator` and `$fileManager` to the constructor of
`Sylius\RefundPlugin\Sender\CreditMemoEmailSender` as the first and third
arguments respectively has been deprecated and will be prohibited in 2.0.

2. The `Sylius\RefundPlugin\File\FileManagerInterface` interface,
`Sylius\RefundPlugin\File\TemporaryFileManager` class and
service with id `Sylius\RefundPlugin\File\TemporaryFileManager`
have all been deprecated and will be removed in 2.0. There is no replacement.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"symfony/web-profiler-bundle": "^5.4 || ^6.0",
"symfony/webpack-encore-bundle": "^1.15"
},
"conflict": {
"behat/mink-selenium2-driver": ">=1.7.0"
},
"autoload": {
"psr-4": {
"Sylius\\RefundPlugin\\": "src/",
Expand Down
3 changes: 3 additions & 0 deletions src/File/FileManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace Sylius\RefundPlugin\File;

/**
* @deprecated since 1.5, to be removed in 2.0
*/
interface FileManagerInterface
{
public function createWithContent(string $fileName, string $content): void;
Expand Down
3 changes: 3 additions & 0 deletions src/File/TemporaryFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace Sylius\RefundPlugin\File;

/**
* @deprecated since 1.5, to be removed in 2.0
*/
final class TemporaryFileManager implements FileManagerInterface
{
private string $baseDirectory;
Expand Down
8 changes: 5 additions & 3 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
</service>

<service id="Sylius\RefundPlugin\Sender\CreditMemoEmailSenderInterface" class="Sylius\RefundPlugin\Sender\CreditMemoEmailSender">
<argument type="service" id="Sylius\RefundPlugin\Generator\CreditMemoPdfFileGeneratorInterface" />
<argument>null</argument>
<argument type="service" id="sylius.email_sender" />
<argument type="service" id="Sylius\RefundPlugin\File\TemporaryFileManager" />
<argument>null</argument>
<argument type="string">%sylius_refund.pdf_generator.enabled%</argument>
<argument type="service" id="Sylius\RefundPlugin\Resolver\CreditMemoFileResolverInterface" />
<argument type="service" id="Sylius\RefundPlugin\Resolver\CreditMemoFilePathResolverInterface" />
Expand All @@ -64,7 +64,9 @@
<deprecated package="sylius/refund-plugin" version="1.0">The "%alias_id%" service alias is deprecated and will be removed in RefundPlugin 2.0, use Sylius\RefundPlugin\Sender\CreditMemoEmailSenderInterface instead.</deprecated>
</service>

<service id="Sylius\RefundPlugin\File\TemporaryFileManager" />
<service id="Sylius\RefundPlugin\File\TemporaryFileManager">
<deprecated package="sylius/refund-plugin" version="1.5">The "%service_id%" service is deprecated and will be removed in RefundPlugin 2.0, there is no replacement.</deprecated>
</service>

<service id="Sylius\RefundPlugin\ResponseBuilder\CreditMemoFileResponseBuilderInterface" class="Sylius\RefundPlugin\ResponseBuilder\CreditMemoFileResponseBuilder" />
<service id="Sylius\RefundPlugin\ResponseBuilder\CreditMemoFileResponseBuilder" alias="Sylius\RefundPlugin\ResponseBuilder\CreditMemoFileResponseBuilderInterface">
Expand Down
44 changes: 34 additions & 10 deletions src/Sender/CreditMemoEmailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,32 @@ final class CreditMemoEmailSender implements CreditMemoEmailSenderInterface
private const UNITS_REFUNDED = 'units_refunded';

public function __construct(
private CreditMemoPdfFileGeneratorInterface $creditMemoPdfFileGenerator,
private ?CreditMemoPdfFileGeneratorInterface $creditMemoPdfFileGenerator,
private SenderInterface $sender,
private FileManagerInterface $fileManager,
private ?FileManagerInterface $fileManager,
private bool $hasEnabledPdfFileGenerator,
private ?CreditMemoFileResolverInterface $creditMemoFileResolver = null,
private ?CreditMemoFilePathResolverInterface $creditMemoFilePathResolver = null,
) {
if (null !== $this->creditMemoPdfFileGenerator) {
@trigger_error(
sprintf('Passing a $creditMemoPdfFileGenerator to %s constructor is deprecated since sylius/refund-plugin 1.5 and will be prohibited in 2.0.', self::class),
\E_USER_DEPRECATED,
);
}
if (null !== $this->fileManager) {
@trigger_error(
sprintf('Passing a $fileManager to %s constructor is deprecated since sylius/refund-plugin 1.5 and will be prohibited in 2.0.', self::class),
\E_USER_DEPRECATED,
);
}

if (null === $this->creditMemoFileResolver) {
@trigger_error(
sprintf('Not passing a $creditMemoFileResolver to %s constructor is deprecated since sylius/refund-plugin 1.3 and will be prohibited in 2.0.', self::class),
\E_USER_DEPRECATED,
);
}

if (null === $this->creditMemoFilePathResolver) {
@trigger_error(
sprintf('Not passing a $creditMemoFilePathResolver to %s constructor is deprecated since sylius/refund-plugin 1.3 and will be prohibited in 2.0.', self::class),
Expand All @@ -57,7 +69,14 @@ public function send(CreditMemoInterface $creditMemo, string $recipient): void
}

if (null === $this->creditMemoFileResolver || null === $this->creditMemoFilePathResolver) {
$this->sendCreditMemoWithTemporaryFile($creditMemo, $recipient);
if (null !== $this->creditMemoPdfFileGenerator && null !== $this->fileManager) {
$this->sendCreditMemoWithTemporaryFile(
$this->creditMemoPdfFileGenerator,
$this->fileManager,
$creditMemo,
$recipient,
);
}

return;
}
Expand All @@ -79,15 +98,20 @@ private function sendCreditMemo(CreditMemoInterface $creditMemo, string $recipie
);
}

private function sendCreditMemoWithTemporaryFile(CreditMemoInterface $creditMemo, string $recipient): void
{
$creditMemoPdfFile = $this->creditMemoPdfFileGenerator->generate($creditMemo->getId());
private function sendCreditMemoWithTemporaryFile(
CreditMemoPdfFileGeneratorInterface $creditMemoPdfFileGenerator,
FileManagerInterface $fileManager,
CreditMemoInterface $creditMemo,
string $recipient,
): void {
$creditMemoPdfFile = $creditMemoPdfFileGenerator->generate($creditMemo->getId());

$creditMemoPdfPath = $creditMemoPdfFile->filename();
$this->fileManager->createWithContent($creditMemoPdfPath, $creditMemoPdfFile->content());

$this->sendCreditMemo($creditMemo, $recipient, $this->fileManager->realPath($creditMemoPdfPath));
$fileManager->createWithContent($creditMemoPdfPath, $creditMemoPdfFile->content());

$this->sendCreditMemo($creditMemo, $recipient, $fileManager->realPath($creditMemoPdfPath));

$this->fileManager->remove($creditMemoPdfPath);
$fileManager->remove($creditMemoPdfPath);
}
}
Loading