2

Symfony2.7を使っています。
gmailでメールを送信する為に、config.ymlとparameters.ymlに設定を追加しています。
ところが、composer requireコマンドでパッケージの追加を実行すると、パッケージインストール後のスクリプトの実行でエラーがでます。この時、parameters.ymlをチェックすると、追加したはずのパラメータがなくなっています。

この現象の原因と、対応方法を教えてください。

# composer require の実行結果

composer require でパッケージを追加インストールしました。
インストール後のスクリプトの実行で mailer_encryption が無いといった感じで、エラーになっています。

$ composer require 'doctrine/doctrine-migrations-bundle:1.0.*'
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing doctrine/migrations (dev-master 67f0268)
    Cloning 67f02686c6c779ae50489728b91026bc8199720c

  - Installing doctrine/doctrine-migrations-bundle (1.0.1)
    Downloading: 100%         

Writing lock file
Generating autoload files
Updating the "app/config/parameters.yml" file



  [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]  
  You have requested a non-existent parameter "mailer_encryption".              



Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception



  [RuntimeException]                                                         
  An error occurred when executing the "'cache:clear --no-warmup'" command.  

# composer実行前の設定ファイル

composer require を実行すると、parameters.yml 内の mailer_encryption と mailer_auth_mode が消えてしまいます。

app/config/comfig.yml

swiftmailer:
    ...
    encryption: "%mailer_encryption%"
    auth_mode: "%mailer_auth_mode%"
    ...

app/config/parameters.yml

parameters:
    ...
    mailer_encryption: ssl
    mailer_auth_mode: login
    ...

1 件の回答 1

2

Symfony 2.3 以降、 parameters.yml は parameters.yml.dist から自動生成されるようになっています。

  • dist側で新しいものが追加されていればその値をユーザーに尋ねて設定
  • dist側でパラメータが削除されていれば parameters.yml からも削除する

この処理が composer install 時に行われます。

このため、パラメータを追加する際はdist側にも追加しないと、そのような現象が発生するかと思います。

composer.json 内で extra.incenteev-parameters.keep-outdated を設定すればこの挙動は回避できるようですが、これは「パラメータが削除されたときにも値を残しておきたい」という時に使うものでしょうから、今回の場合は parameters.yml.dist に追加されることをお勧めします。

参考

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。