【问题标题】:Doctrine configuration in php file not updatedphp 文件中的教义配置未更新
【发布时间】:2014-07-15 09:38:20
【问题描述】:

我有一个运行一些 Symfony 控制台命令的 cron 作业。它最近停止正常工作。现在,当我登录终端并自己运行命令时,看起来以前的变量值保存在某个缓存中并且没有刷新。我的学说配置加载了一个 php 文件。

app/config/config.yml(第一行)

imports:
    - { resource: database.php }

app/config/database.php

<?php
$container->setParameter('database_driver', 'oci8');
$container->setParameter('database_host', getenv('SQL_SERVER_NAME'));
$container->setParameter('database_port', getenv('SQL_SERVER_PORT'));
$container->setParameter('database_name', getenv('SQL_ORA_SID'));
$container->setParameter('database_user', getenv('SQL_USER'));
$container->setParameter('database_password', getenv('SQL_PASSWORD'));

控制台

$ php app/console doctrine:schema:validate
[Mapping]  OK - The mapping files are correct.

  [Doctrine\DBAL\Driver\OCI8\OCI8Exception]
  ORA-24415: Missing or null username.


$ echo $SQL_USER
(some correct value)

此时,我可以确认所有变量都在 shell 环境中正确设置,并且没有任何学说命令起作用。看起来配置值是从缓存中读取的,而不是每次运行的 database.php,并且该缓存是在未正确设置 shell 环境时设置的。所以所有的值都是空的。

config.yml 的最轻微修改会触发 database.php 的重新运行,并使一切井井有条。但是执行 cache:clear 不起作用。

$ touch app/config/config.yml
$ php app/console doctrine:schema:validate
[Mapping]  OK - The mapping files are correct.
[Database] FAIL - The database schema is not in sync with the current mapping file.

这是预期的行为吗?有没有强制刷新缓存的命令开关?

【问题讨论】:

    标签: symfony doctrine


    【解决方案1】:

    由于devprod 环境,我遇到了一些问题。运行命令时,将--env=prod 添加到每个命令的末尾(如果您在生产环境中运行)。否则默认为开发环境。

    【讨论】: