EnsureProductionSettingsCommand.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. namespace Doctrine\ORM\Tools\Console\Command;
  22. use Symfony\Component\Console\Input\InputArgument,
  23. Symfony\Component\Console\Input\InputOption,
  24. Symfony\Component\Console;
  25. /**
  26. * Command to ensure that Doctrine is properly configured for a production environment.
  27. *
  28. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  29. * @link www.doctrine-project.org
  30. * @since 2.0
  31. * @version $Revision$
  32. * @author Benjamin Eberlei <kontakt@beberlei.de>
  33. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  34. * @author Jonathan Wage <jonwage@gmail.com>
  35. * @author Roman Borschel <roman@code-factory.org>
  36. */
  37. class EnsureProductionSettingsCommand extends Console\Command\Command
  38. {
  39. /**
  40. * @see Console\Command\Command
  41. */
  42. protected function configure()
  43. {
  44. $this
  45. ->setName('orm:ensure-production-settings')
  46. ->setDescription('Verify that Doctrine is properly configured for a production environment.')
  47. ->setDefinition(array(
  48. new InputOption(
  49. 'complete', null, InputOption::VALUE_NONE,
  50. 'Flag to also inspect database connection existance.'
  51. )
  52. ))
  53. ->setHelp(<<<EOT
  54. Verify that Doctrine is properly configured for a production environment.
  55. EOT
  56. );
  57. }
  58. /**
  59. * @see Console\Command\Command
  60. */
  61. protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
  62. {
  63. $em = $this->getHelper('em')->getEntityManager();
  64. $error = false;
  65. try {
  66. $em->getConfiguration()->ensureProductionSettings();
  67. if ($input->getOption('complete') !== null) {
  68. $em->getConnection()->connect();
  69. }
  70. } catch (\Exception $e) {
  71. $error = true;
  72. $output->writeln('<error>' . $e->getMessage() . '</error>');
  73. }
  74. if ($error === false) {
  75. $output->write('<info>Environment is correctly configured for production.</info>' . PHP_EOL);
  76. }
  77. }
  78. }