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

[Cookbook][Console] remove note about memory spool handling on CLI #6250

Merged
merged 1 commit into from
Feb 10, 2016
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
2 changes: 1 addition & 1 deletion book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ to ``generate()``:
The host that's used when generating an absolute URL is automatically
detected using the current ``Request`` object. When generating absolute
URLs from outside the web context (for instance in a console command) this
doesn't work. See :doc:`/cookbook/console/sending_emails` to learn how to
doesn't work. See :doc:`/cookbook/console/request_context` to learn how to
solve this problem.

Summary
Expand Down
2 changes: 1 addition & 1 deletion cookbook/console/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Console
console_command
usage
command_in_controller
sending_emails
request_context
logging
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.. index::
single: Console; Sending emails
single: Console; Generating URLs

How to Generate URLs and Send Emails from the Console
=====================================================
How to Generate URLs from the Console
=====================================

Unfortunately, the command line context does not know about your VirtualHost
or domain name. This means that if you generate absolute URLs within a
Expand Down Expand Up @@ -84,43 +83,3 @@ from the ``router`` service and override its settings::
// ... your code here
}
}

Using Memory Spooling
---------------------

.. versionadded:: 2.3
When using Symfony 2.3+ and SwiftmailerBundle 2.3.5+, the memory spool is now
handled automatically in the CLI and the code below is not necessary anymore.

Sending emails in a console command works the same way as described in the
:doc:`/cookbook/email/email` cookbook except if memory spooling is used.

When using memory spooling (see the :doc:`/cookbook/email/spool` cookbook for more
information), you must be aware that because of how Symfony handles console
commands, emails are not sent automatically. You must take care of flushing
the queue yourself. Use the following code to send emails inside your
console command::

$message = new \Swift_Message();

// ... prepare the message

$container = $this->getContainer();
$mailer = $container->get('mailer');

$mailer->send($message);

// now manually flush the queue
$spool = $mailer->getTransport()->getSpool();
$transport = $container->get('swiftmailer.transport.real');

$spool->flushQueue($transport);

Another option is to create an environment which is only used by console
commands and uses a different spooling method.

.. note::

Taking care of the spooling is only needed when memory spooling is used.
If you are using file spooling (or no spooling at all), there is no need
to flush the queue manually within the command.
2 changes: 1 addition & 1 deletion cookbook/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* :doc:`/cookbook/console/console_command`
* :doc:`/cookbook/console/usage`
* :doc:`/cookbook/console/command_in_controller`
* :doc:`/cookbook/console/sending_emails`
* :doc:`/cookbook/console/request_context`
* :doc:`/cookbook/console/logging`

* :doc:`/cookbook/controller/index`
Expand Down
1 change: 1 addition & 0 deletions redirection_map
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/book/stable_api /contributing/code/bc
/book/internals /reference/events
/cookbook/console/sending_emails /cookbook/console/request_context
/cookbook/deployment-tools /cookbook/deployment/tools
/cookbook/doctrine/migrations /bundles/DoctrineFixturesBundle/index
/cookbook/doctrine/doctrine_fixtures /bundles/DoctrineFixturesBundle/index
Expand Down