diff --git a/Core/Executor/MailExecutor.php b/Core/Executor/MailExecutor.php index 1fa80e50..bdd8d4ba 100644 --- a/Core/Executor/MailExecutor.php +++ b/Core/Executor/MailExecutor.php @@ -74,8 +74,14 @@ protected function send($dsl, $context) if (isset($dsl['body'])) { $message->setBody($this->resolveReferencesInText($dsl['body'])); } - if (isset($dsl['attach'])) { /// @todo - $message->attach(Swift_Attachment::fromPath($this->resolveReferencesRecursively($dsl['attach']))); + if (isset($dsl['attach'])) { + $path = $this->resolveReferencesRecursively($dsl['attach']); + // we use the same logic as for the image/file fields in content: look up file 1st relative to the migration + $attachment = dirname($context['path']) . '/' . $path; + if (!is_file($attachment)) { + $attachment = $path; + } + $message->attach(Swift_Attachment::fromPath($attachment)); } if (isset($dsl['priority'])) { diff --git a/Core/Executor/ReferenceExecutor.php b/Core/Executor/ReferenceExecutor.php index d81e2e84..19aebddb 100644 --- a/Core/Executor/ReferenceExecutor.php +++ b/Core/Executor/ReferenceExecutor.php @@ -56,8 +56,9 @@ protected function set($dsl, $context) throw new \Exception("Invalid step definition: miss 'value' for setting reference"); } $value = $dsl['value']; - if (preg_match('/%.+%$/', $value)) { - $value = $this->container->getParameter(trim($value, '%')); + if (preg_match('/.*%.+%.*$/', $value)) { + // we use the same parameter resolving rule as symfony, even though this means abusing the ContainerInterface + $value = $this->container->getParameterBag()->resolveString($value); } $overwrite = isset($dsl['overwrite']) ? $overwrite = $dsl['overwrite'] : false; $this->referenceResolver->addReference($dsl['identifier'], $value, $overwrite); diff --git a/Tests/dsl/bad/parsing/UnitTestKO011_invalid_json.json b/Tests/dsl/bad/parsing/UnitTestKO012_invalid_json.json similarity index 100% rename from Tests/dsl/bad/parsing/UnitTestKO011_invalid_json.json rename to Tests/dsl/bad/parsing/UnitTestKO012_invalid_json.json diff --git a/Tests/dsl/bad/parsing/UnitTestKO012_wrong_json.json b/Tests/dsl/bad/parsing/UnitTestKO013_wrong_json.json similarity index 100% rename from Tests/dsl/bad/parsing/UnitTestKO012_wrong_json.json rename to Tests/dsl/bad/parsing/UnitTestKO013_wrong_json.json diff --git a/Tests/dsl/good/UnitTestOK22_file.yml b/Tests/dsl/good/UnitTestOK022_file.yml similarity index 100% rename from Tests/dsl/good/UnitTestOK22_file.yml rename to Tests/dsl/good/UnitTestOK022_file.yml diff --git a/Tests/dsl/good/UnitTestOK023_mail.yml b/Tests/dsl/good/UnitTestOK023_mail.yml new file mode 100644 index 00000000..0b6bc8f7 --- /dev/null +++ b/Tests/dsl/good/UnitTestOK023_mail.yml @@ -0,0 +1,83 @@ +- + type: reference + mode: set + identifier: kmb_test_023_subject + value: testing + +- + type: reference + mode: set + identifier: kmb_test_023_body + value: migrations + +- + type: mail + mode: send + from: test@test.me + to: test@test.you + cc: test@test.him + bcc: + - test@test.her + - test@test.they + subject: "this is an email subject about [reference:kmb_test_023_subject] etc..." + body: "this is an email body about [reference:kmb_test_023_body] etc..." + attach: files/emptyfile.txt + +# NB: this file is made available by a custom swiftmailer listener +- + type: file + mode: load + file: /tmp/mail.txt + references: + - + attribute: body + identifier: kmb_test_023_mailmessage + +- + type: assert + target: reference + identifier: reference:kmb_test_023_mailmessage + test: + contains: "From: test@test.me" + +- + type: assert + target: reference + identifier: reference:kmb_test_023_mailmessage + test: + contains: "To: test@test.you" + +- + type: assert + target: reference + identifier: reference:kmb_test_023_mailmessage + test: + contains: "Cc: test@test.him" + +- + type: assert + target: reference + identifier: reference:kmb_test_023_mailmessage + test: + contains: "Bcc: test@test.her, test@test.they" + +- + type: assert + target: reference + identifier: reference:kmb_test_023_mailmessage + test: + contains: "Content-Type: multipart/mixed;" + +- + type: assert + target: reference + identifier: reference:kmb_test_023_mailmessage + test: + contains: "this is an email body about migrations etc..." + +- + type: assert + target: reference + identifier: reference:kmb_test_023_mailmessage + test: + contains: "Subject: this is an email subject about testing etc..." diff --git a/Tests/ezpublish/config/config_behat_ezplatform.yml b/Tests/ezpublish/config/config_behat_ezplatform.yml index 439996ef..52b115a7 100644 --- a/Tests/ezpublish/config/config_behat_ezplatform.yml +++ b/Tests/ezpublish/config/config_behat_ezplatform.yml @@ -46,6 +46,7 @@ stash: registerDoctrineAdapter: false swiftmailer: + disable_delivery: false spool: type: file path: '%kernel.root_dir%/spool' diff --git a/Tests/ezpublish/config/config_behat_ezpublish-community.yml b/Tests/ezpublish/config/config_behat_ezpublish-community.yml index 4c5e2775..e26c3218 100644 --- a/Tests/ezpublish/config/config_behat_ezpublish-community.yml +++ b/Tests/ezpublish/config/config_behat_ezpublish-community.yml @@ -31,6 +31,7 @@ ez_publish_legacy: root_dir: %kernel.root_dir%/../../ezpublish-legacy swiftmailer: + disable_delivery: false spool: type: file path: '%kernel.root_dir%/spool' diff --git a/Tests/ezpublish/config/services.yml b/Tests/ezpublish/config/services.yml index bb77f909..79158b71 100644 --- a/Tests/ezpublish/config/services.yml +++ b/Tests/ezpublish/config/services.yml @@ -23,3 +23,7 @@ services: class: Kaliop\eZMigrationBundle\Tests\helper\CustomReferenceResolver tags: - { name: ez_migration_bundle.reference_resolver.customreference } + ez_migration_bundle.test.swiftmailer_message_logger: + class: Kaliop\eZMigrationBundle\Tests\helper\MailMessageLogger + tags: + - { name: swiftmailer.default.plugin } diff --git a/Tests/helper/MailMessageLogger.php b/Tests/helper/MailMessageLogger.php new file mode 100644 index 00000000..14cc9ae1 --- /dev/null +++ b/Tests/helper/MailMessageLogger.php @@ -0,0 +1,19 @@ +getMessage(); + file_put_contents('/tmp/mail.txt', $msg->toString()); + } +} diff --git a/WHATSNEW.md b/WHATSNEW.md index 66195be3..a964c319 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -3,6 +3,10 @@ Version 4.0 * New: allow to set references to contentType default_always_available, default_sort_field, default_sort_order, is_container +* Improved: parameter resolving in migration steps reference/set now works even when the parameter is not the full value of the string, eg: '%kernel.root_dir%/spool' + +* Improved: path to attachment files can be specified relative to the migration file for migration steps mail/send + Version 4.0 RC-5 ================