Skip to content
This repository
tree: 67a39369c6
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 153 lines (126 sloc) 4.985 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
<?php

/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require_once(dirname(__FILE__).'/sfPropelBaseTask.class.php');

/**
* Generates Propel model, SQL and initializes the database.
*
* @package symfony
* @subpackage propel
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: sfPropelBuildAllTask.class.php 23922 2009-11-14 14:58:38Z fabien $
*/
class sfPropelBuildAllTask extends sfPropelBaseTask
{
  /**
* @see sfTask
*/
  protected function configure()
  {
    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
      new sfCommandOption('no-confirmation', null, sfCommandOption::PARAMETER_NONE, 'Do not ask for confirmation'),
      new sfCommandOption('skip-forms', 'F', sfCommandOption::PARAMETER_NONE, 'Skip generating forms'),
      new sfCommandOption('classes-only', 'C', sfCommandOption::PARAMETER_NONE, 'Do not initialize the database'),
      new sfCommandOption('phing-arg', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'Arbitrary phing argument'),
    ));

    $this->namespace = 'propel';
    $this->name = 'build-all';
    $this->briefDescription = 'Generates Propel model and form classes, SQL and initializes the database';

    $this->detailedDescription = <<<EOF
The [propel:build-all|INFO] task is a shortcut for five other tasks:

[./symfony propel:build-all|INFO]

The task is equivalent to:

[./symfony propel:build-model|INFO]
[./symfony propel:build-forms|INFO]
[./symfony propel:build-filters|INFO]
[./symfony propel:build-sql|INFO]
[./symfony propel:insert-sql|INFO]

See those tasks' help pages for more information.

To bypass confirmation prompts, you can pass the [no-confirmation|COMMENT] option:

[./symfony propel:buil-all --no-confirmation|INFO]

To build all classes but skip initializing the database, use the [classes-only|COMMENT]
option:

[./symfony propel:build-all --classes-only|INFO]
EOF;
  }

  /**
* @see sfTask
*/
  protected function execute($arguments = array(), $options = array())
  {
    $basePhingOptions = array();
    foreach ($options['phing-arg'] as $arg)
    {
      $basePhingOptions[] = '--phing-arg='.escapeshellarg($arg);
    }

    $buildModel = new sfPropelBuildModelTask($this->dispatcher, $this->formatter);
    $buildModel->setCommandApplication($this->commandApplication);
    $buildModel->setConfiguration($this->configuration);
    $ret = $buildModel->run(array(), array(
      'phing-arg' => $options['phing-arg'],
    ));

    if ($ret)
    {
      return $ret;
    }

    if (!$options['skip-forms'])
    {
      $this->logBlock(array(
        'Phing was run before and used many custom classes that might conflict with',
        'your model classes. In case of errors try running "propel:build-forms" and',
        '"propel:build-filters" alone. This is due to a PHP limitation that cannot be',
        'fixed in symfony.',
      ), 'INFO');

      $buildForms = new sfPropelBuildFormsTask($this->dispatcher, $this->formatter);
      $buildForms->setCommandApplication($this->commandApplication);
      $buildForms->setConfiguration($this->configuration);
      $ret = $buildForms->run();

      if ($ret)
      {
        return $ret;
      }

      $buildFilters = new sfPropelBuildFiltersTask($this->dispatcher, $this->formatter);
      $buildFilters->setCommandApplication($this->commandApplication);
      $buildFilters->setConfiguration($this->configuration);
      $ret = $buildFilters->run();

      if ($ret)
      {
        return $ret;
      }
    }

    if (!$options['classes-only'])
    {
      $buildSql = new sfPropelBuildSqlTask($this->dispatcher, $this->formatter);
      $buildSql->setCommandApplication($this->commandApplication);
      $buildSql->setConfiguration($this->configuration);
      $ret = $buildSql->run(array(), array(
        'phing-arg' => $options['phing-arg'],
      ));

      if ($ret)
      {
        return $ret;
      }

      $insertSql = new sfPropelInsertSqlTask($this->dispatcher, $this->formatter);
      $insertSql->setCommandApplication($this->commandApplication);
      $insertSql->setConfiguration($this->configuration);
      $ret = $insertSql->run(array(), array(
        'phing-arg' => $options['phing-arg'],
        'connection' => $options['connection'],
        'no-confirmation' => $options['no-confirmation'],
      ));

      if ($ret)
      {
        return $ret;
      }
    }

    $this->reloadAutoload();
  }
}
Something went wrong with that request. Please try again.