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

[shopsys] replace swiftmailer with symfony/mailer #2470

Merged
merged 6 commits into from
Jul 8, 2022
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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
"snc/redis-bundle": "^3.2.2",
"stof/doctrine-extensions-bundle": "^1.3.0",
"superbalist/flysystem-google-storage": "^7.1",
"swiftmailer/swiftmailer": "^6.0",
grossmannmartin marked this conversation as resolved.
Show resolved Hide resolved
"symfony-cmf/routing": "^2.0.3",
"symfony-cmf/routing-bundle": "^2.0.3",
"symfony/browser-kit": "^4.4.0",
Expand All @@ -135,12 +134,12 @@
"symfony/event-dispatcher": "^4.4.0",
"symfony/flex": "^1.17",
"symfony/form": "^4.4.0",
"symfony/mailer": "^5.0",
"symfony/monolog-bridge": "^4.4.0",
"symfony/monolog-bundle": "^3.5.0",
"symfony/property-info": "^4.4.0",
"symfony/proxy-manager-bridge": "^4.4.25",
"symfony/security-bundle": "^4.4.0",
"symfony/swiftmailer-bundle": "^3.2.2",
"symfony/translation": "^4.4.0",
"symfony/twig-bundle": "^4.4.0",
"symfony/validator": "^4.4.0",
Expand Down Expand Up @@ -218,7 +217,8 @@
"public-dir": "project-base/web",
"symfony": {
"allow-contrib": true,
"require": "^4.4.0"
"require": "^4.4.0",
"docker": false
grossmannmartin marked this conversation as resolved.
Show resolved Hide resolved
}
},
"replace": {
Expand Down
47 changes: 20 additions & 27 deletions docs/installation/application-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,26 @@ You may want to set some settings in a different way (such as production, test,

### Application

!!! note
To propagate the change of `MAILER_DELIVERY_WHITELIST`, `MAILER_DISABLE_DELIVERY` and `MAILER_MASTER_EMAIL_ADDRESS` cache must be cleaned.

| Name | Default | Description |
| -------------------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------ |
| `DATABASE_HOST` | `'postgres'` | access data of your PostgreSQL database |
| `DATABASE_PORT` | `null` | ... |
| `DATABASE_NAME` | `'shopsys'` | ... |
| `DATABASE_USER` | `'root'` | ... |
| `DATABASE_PASSWORD` | `'root'` | ... |
| `ELASTICSEARCH_HOST` | `'elasticsearch:9200'` | host of your Elasticsearch, you can use multiple hosts like `'["elasticsearch:9200", "elasticsearch2:9200"]'` |
| `REDIS_HOST` | `'redis'` | host of your Redis storage (credentials are not supported right now) |
| `REDIS_PREFIX` | `''` | separates more projects that use the same redis service |
| `MAILER_TRANSPORT` | `'smtp'` | access data of your mail server |
| `MAILER_HOST` | `'smtp-server'` | ... |
| `MAILER_USER` | `null` | ... |
| `MAILER_PASSWORD` | `null` | ... |
| `MAILER_DELIVERY_WHITELIST` | `'/@shopsys\.com$/'` | regex text items if you want to have master email but allow sending to specific addresses (set as text separated by comma for multiple values) |
| `MAILER_DISABLE_DELIVERY` | `false` | set to `true` if you don't want to send any emails |
| `MAILER_MASTER_EMAIL_ADDRESS` | `'no-reply@shopsys.com'` | set if you want to send all emails to one address (useful for development) |
| `APP_SECRET` | `'ThisTokenIsNotSoSecretChangeIt'` | randomly generated secret token |
| `ELASTIC_SEARCH_INDEX_PREFIX` | `''` | separates more projects that use the same elasticsearch service |
| `IGNORE_DEFAULT_ADMIN_PASSWORD_CHECK` | `'0'` | set to `true` if you want to allow administrators to log in with default credentials |
| `OVERWRITE_DOMAIN_URL` | `'http://webserver:8080'` | overwrites URL of all domains for acceptance testing (set to `~` to disable) |
| `SELENIUM_SERVER_HOST` | `'selenium-server'` | with native installation the selenium server is on `localhost` |
| `SHOPSYS_CONTENT_DIR_NAME` | `'content-test'` | web/content-test/ directory is used instead of web/content/ during the tests |
| `TRUSTED_PROXIES` | `'127.0.0.1'` | proxies that are trusted to pass traffic, used mainly for production (set as text separated by comma for multiple values) |
| Name | Default | Description |
|---------------------------------------| ------------------------------------ |------------------------------------------------------------------------------------------------------------------------------------------------|
| `DATABASE_HOST` | `'postgres'` | access data of your PostgreSQL database |
| `DATABASE_PORT` | `null` | ... |
| `DATABASE_NAME` | `'shopsys'` | ... |
| `DATABASE_USER` | `'root'` | ... |
| `DATABASE_PASSWORD` | `'root'` | ... |
| `ELASTICSEARCH_HOST` | `'elasticsearch:9200'` | host of your Elasticsearch, you can use multiple hosts like `'["elasticsearch:9200", "elasticsearch2:9200"]'` |
| `REDIS_HOST` | `'redis'` | host of your Redis storage (credentials are not supported right now) |
| `REDIS_PREFIX` | `''` | separates more projects that use the same redis service |
| `MAILER_DELIVERY_WHITELIST` | `'/@shopsys\.com$/'` | regex text items if you want to have master email but allow sending to specific addresses (set as text separated by comma for multiple values) |
| `MAILER_DSN` | `smtp://smtp-server:25` | set to `null://null` if you don't want to send any emails, see https://symfony.com/doc/current/mailer.html#disabling-delivery |
| `MAILER_MASTER_EMAIL_ADDRESS` | `'no-reply@shopsys.com'` | set if you want to send all emails to one address (useful for development) |
| `APP_SECRET` | `'ThisTokenIsNotSoSecretChangeIt'` | randomly generated secret token |
| `ELASTIC_SEARCH_INDEX_PREFIX` | `''` | separates more projects that use the same elasticsearch service |
| `IGNORE_DEFAULT_ADMIN_PASSWORD_CHECK` | `'0'` | set to `true` if you want to allow administrators to log in with default credentials |
| `OVERWRITE_DOMAIN_URL` | `'http://webserver:8080'` | overwrites URL of all domains for acceptance testing (set to `~` to disable) |
| `SELENIUM_SERVER_HOST` | `'selenium-server'` | with native installation the selenium server is on `localhost` |
| `SHOPSYS_CONTENT_DIR_NAME` | `'content-test'` | web/content-test/ directory is used instead of web/content/ during the tests |
| `TRUSTED_PROXIES` | `'127.0.0.1'` | proxies that are trusted to pass traffic, used mainly for production (set as text separated by comma for multiple values) |


### Google Cloud Bundle
Expand Down
39 changes: 20 additions & 19 deletions docs/introduction/faq-and-common-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ For more detailed information about the Shopsys Framework, please see [Shopsys F
- [Why are you using entity data instead of entities for Symfony forms?](#why-are-you-using-entity-data-instead-of-entities-for-symfony-forms)
- [What is the configuration file `services_test.yaml` good for?](#what-is-the-configuration-file-services_testyaml-good-for)
- [How to change the behavior of the product search on the front-end?](#how-to-change-the-behavior-of-the-product-search-on-the-front-end)
- [Why are emails not sent immediately but at the end of the script](#why-are-emails-sent-before-end-of-the-script-and-not-immediately)
- [Where does the business logic belong?](#where-does-the-business-logic-belong)
- [How can I create a friendly URL for my entity?](#how-can-i-create-a-friendly-url-for-my-entity)
- [How can I create Front-end Breadcrumb navigation?](#how-can-i-create-front-end-breadcrumb-navigation)
Expand Down Expand Up @@ -116,12 +115,6 @@ E.g., by default, all our services are defined as private. However, in tests, we
Full-text product search on the front-end is handled via Elasticsearch.
If you want to change its behavior (e.g. make the EAN not as important or change the way the search string is handled - whether to use an n-gram or not) please see [Product Searching](../model/front-end-product-searching.md).

## Why are emails sent before end of the script and not immediately
Project uses `SwiftMailer` package for sending emails and defaultly it has set `spool queue` that stores all mails into `memory` until the script execution is at the end.
This spooling method helps the user not to wait for the next page to load while the email is sending.
However, based on implementations of many projects, project gained functionality that releases spool after the `*cronModule` run is ended in case of `cron` phing target that runs all cron modules at once.
It is also possible to turn the spool off by removing it from [swiftmailer.yaml](https://github.com/shopsys/shopsys/blob/master/project-base/config/packages/swiftmailer.yaml) or changing the behavior of storing emails based on [symfony docs](https://symfony.com/doc/3.4/email/spool.html) or [snc_redis docs](https://github.com/snc/SncRedisBundle/blob/master/Resources/doc/index.md#swiftmailer-spooling).

## Where does the business logic belong?
The business logic should be implemented directly in an entity every time when there is no need for external services.
Otherwise, the logic is in facades (resp. the facades are used as delegates to other services, e.g. another *Facade*, *Repository*, *Calculation*, etc.). You can read more about the model architecture in [Introduction to model architecture](../model/introduction-to-model-architecture.md).
Expand All @@ -133,22 +126,30 @@ See [Friendly URL](./friendly-url.md) article.
See [Front-end Breadcrumb Navigation](./front-end-breadcrumb-navigation.md) article.

## Do you have any tips how to debug emails during development in Docker?
Yes we have, you can easily use [`djfarrelly/MailDev`](https://github.com/djfarrelly/MailDev) library that provides you web UI where you can see the emails including their headers:
1. In your `docker-compose.yml`, change the `smtp-server` service:
```diff
smtp-server:
- image: namshi/smtp:latest
+ image: djfarrelly/maildev
container_name: shopsys-framework-smtp-server
+ ports:
+ - "8025:80"
```
1. Run `docker-compose up -d`
1. Now you are able to see all the application emails in the inbox on [`http://127.0.0.1:8025`](http://127.0.0.1:8025).
Yes we have, you can easily use [`maildev/maildev`](https://github.com/maildev/maildev) library that provides you web UI where you can see the emails including their headers:

* In your `docker-compose.yml`, change the `smtp-server` service:
```diff
smtp-server:
- image: namshi/smtp:latest
+ image: maildev/maildev
container_name: shopsys-framework-smtp-server
+ ports:
+ - "8025:80"
```
* Run `docker-compose up -d`
* add `?verify_peer=false` at the end of the `MAILER_DSN` environment variable value:
```diff
- MAILER_DSN=smtp://smtp-server:25
+ MAILER_DSN=smtp://smtp-server:25?verify_peer=false
```
* Now you are able to see all the application emails in the inbox on [`http://127.0.0.1:8025`](http://127.0.0.1:8025).

*Note: Beware, by using this setting, no emails are delivered to their original recipients.
See [Outgoing emails](https://github.com/djfarrelly/MailDev#outgoing-email) in the documentation of the library for more information.*

*Note: You can also view the outgoing emails in the Symfony profiler.*

## Can I see what is really happening in the Codeception acceptance tests when using Docker?
Yes, you can! Check [the quick guide](../automated-testing/running-acceptance-tests.md#how-to-watch-what-is-going-on-in-the-selenium-browser).

Expand Down
6 changes: 3 additions & 3 deletions packages/framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,12 @@
"shopsys/postgres-search-bundle": "^0.2",
"snc/redis-bundle": "^3.2.1",
"stof/doctrine-extensions-bundle": "^1.3.0",
"swiftmailer/swiftmailer": "^6.0",
"symfony/event-dispatcher": "^4.4",
"symfony/mailer": "^5.0",
"symfony/monolog-bundle": "^3.5.0",
"symfony/property-info": "^4.4",
"symfony/proxy-manager-bridge": "^4.4.25",
"symfony/security": "^4.4",
"symfony/swiftmailer-bundle": "^3.2.2",
"symfony-cmf/routing": "^2.0.3",
"symfony-cmf/routing-bundle": "^2.0.3",
"symfony/polyfill-php80": "^1.24.0",
Expand All @@ -114,7 +113,8 @@
"dev-master": "11.0.x-dev"
},
"symfony": {
"require": "^4.4.0"
"require": "^4.4.0",
"docker": false
}
},
"conflict": {
Expand Down
1 change: 1 addition & 0 deletions packages/framework/ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
__DIR__ . '/tests/Unit/Model/Category/CategoryNestedSetCalculatorTest.php',
__DIR__ . '/tests/Unit/Model/Payment/PaymentPriceCalculationTest.php',
__DIR__ . '/src/Form/Constraints/FileAbstractFilesystemValidator.php',
__DIR__ . '/tests/Unit/Model/Mail/EnvelopeListenerTest.php',
],
PropertyPerClassLimitSniff::class => [
__DIR__ . '/src/Model/Order/Order.php',
Expand Down
19 changes: 0 additions & 19 deletions packages/framework/src/Component/Cron/CronFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use DateTimeInterface;
use Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig;
use Shopsys\FrameworkBundle\Component\Cron\Config\CronModuleConfig;
use Shopsys\FrameworkBundle\Model\Mail\Mailer;
use Swift_TransportException;
use Symfony\Bridge\Monolog\Logger;
use Throwable;

Expand All @@ -27,11 +25,6 @@ class CronFacade
*/
protected $cronModuleFacade;

/**
* @var \Shopsys\FrameworkBundle\Model\Mail\Mailer
*/
protected $mailer;

/**
* @var \Shopsys\FrameworkBundle\Component\Cron\CronModuleExecutor
*/
Expand All @@ -41,20 +34,17 @@ class CronFacade
* @param \Symfony\Bridge\Monolog\Logger $logger
* @param \Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig $cronConfig
* @param \Shopsys\FrameworkBundle\Component\Cron\CronModuleFacade $cronModuleFacade
* @param \Shopsys\FrameworkBundle\Model\Mail\Mailer $mailer
* @param \Shopsys\FrameworkBundle\Component\Cron\CronModuleExecutor $cronModuleExecutor
*/
public function __construct(
Logger $logger,
CronConfig $cronConfig,
CronModuleFacade $cronModuleFacade,
Mailer $mailer,
CronModuleExecutor $cronModuleExecutor
) {
$this->logger = $logger;
$this->cronConfig = $cronConfig;
$this->cronModuleFacade = $cronModuleFacade;
$this->mailer = $mailer;
$this->cronModuleExecutor = $cronModuleExecutor;
}

Expand Down Expand Up @@ -135,15 +125,6 @@ protected function runSingleModule(CronModuleConfig $cronModuleConfig)

$this->cronModuleFacade->markCronAsEnded($cronModuleConfig);

try {
$this->mailer->flushSpoolQueue();
} catch (Swift_TransportException $exception) {
$this->logger->addError(
'An exception occurred while flushing email queue. Message: "{message}"',
['exception' => $exception, 'message' => $exception->getMessage()]
);
}

if ($status === CronModuleExecutor::RUN_STATUS_OK) {
$this->cronModuleFacade->unscheduleModule($cronModuleConfig);
$this->logger->addInfo('End of ' . $cronModuleConfig->getServiceId());
Expand Down
3 changes: 0 additions & 3 deletions packages/framework/src/Controller/Admin/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider;
use Shopsys\FrameworkBundle\Model\AdvancedSearchOrder\AdvancedSearchOrderFacade;
use Shopsys\FrameworkBundle\Model\Customer\Exception\CustomerUserNotFoundException;
use Shopsys\FrameworkBundle\Model\Mail\Exception\MailException;
use Shopsys\FrameworkBundle\Model\Order\Exception\OrderNotFoundException;
use Shopsys\FrameworkBundle\Model\Order\Item\OrderItemFacade;
use Shopsys\FrameworkBundle\Model\Order\Item\OrderItemPriceCalculation;
Expand Down Expand Up @@ -133,8 +132,6 @@ public function editAction(Request $request, $id)
$this->addErrorFlash(
t('Entered customer not found, please check entered data.')
);
} catch (MailException $e) {
$this->addErrorFlash(t('Unable to send updating email'));
}
}

Expand Down
Loading