/**
     * @see sfTask
     */
    protected function configure()
    {
        parent::configure();
        $this->namespace = 'doctrine';
        $this->name = 'mysql-safe-migrate';
        $this->addOptions(array(new sfCommandOption('target', null, sfCommandOption::PARAMETER_OPTIONAL, 'The target filename of the backup file'), new sfCommandOption('no-confirmation', null, sfCommandOption::PARAMETER_NONE, 'Whether to force dropping of the database'), new sfCommandOption('keep-backup', null, sfCommandOption::PARAMETER_NONE, 'Keep the backup file that is generated'), new sfCommandOption('disable-env', null, sfCommandOption::PARAMETER_NONE, 'Disable environment whilst migrating')));
        $this->briefDescription = 'Migrates a mysql database to current/specified version using a backup' . ' to get around lack of transaction support';
        $this->detailedDescription = <<<EOF
The [doctrine:mysql-safe-migrate|INFO] task migrates a MySQL database in a
restorable manner as normal migrations are not able to rollback in the event
of an error:

  [./symfony doctrine:mysql-safe-migrate|INFO]

Provide a version argument to migrate to a specific version:

  [./symfony doctrine:mysql-safe-migrate 10|INFO]

To migrate up or down one migration, use the [--up|COMMENT] or
[--down|COMMENT] options:

  [./symfony doctrine:mysql-safe-migrate --down|INFO]

To test if there are any errors in a migration without applying it you can run
in dry-run mode using the [--dry-run|COMMENT] option, be aware that in this mode
your database will be backed up and then restored so there is possibility for
data loss:

  [./symfony doctrine:mysql-safe-migrate --dry-run|INFO]

To migrate up or down one migration, use the [--up|COMMENT] or
[--down|COMMENT] options:

  [./symfony doctrine:mysql-safe-migrate --down|INFO]

The task dumps the database data in [data/sql/%target%|COMMENT].

You will be prompted for confirmation before any databases are dropped unless
you provide the [--no-confirmation|COMMENT] option:

  [./symfony doctrine:mysql-safe-migrate --no-confirmation|INFO]

If you do not want the backup file to be deleted after the completion of the
task provide the [--keep-backup|COMMENT] option:

  [./symfony doctrine:mysql-safe-migrate --keep-backup|INFO]

Note that because a backup of your database is restored there is the possibility
of data loss from any database changes that happened during the time since the
backup was made. This task is meant primarily for a development environment
to ease in assuring a doctrine migration will work successfully
EOF;
    }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     if (!($mode = $this->calculateMode($options))) {
         throw new InvalidArgumentException(sprintf("You must include one or more of the following build options:\n--%s\n\nSee this task's help page for more information:\n\n  php symfony help doctrine:build", join(', --', array_keys($this->getBuildOptions()))));
     }
     if (self::BUILD_DB == (self::BUILD_DB & $mode)) {
         $task = new sfDoctrineDropDbTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         $ret = $task->run(array(), array('no-confirmation' => $options['no-confirmation']));
         if ($ret) {
             return $ret;
         }
         $task = new sfDoctrineBuildDbTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         $ret = $task->run();
         if ($ret) {
             return $ret;
         }
         // :insert-sql (or :migrate) will also be run, below
     }
     if (self::BUILD_MODEL == (self::BUILD_MODEL & $mode)) {
         $task = new dinDoctrineBuildModelTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         $ret = $task->run();
         if ($ret) {
             return $ret;
         }
     }
     if (self::BUILD_FORMS == (self::BUILD_FORMS & $mode)) {
         $task = new dinDoctrineBuildFormsTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         $ret = $task->run();
         if ($ret) {
             return $ret;
         }
     }
     if (self::BUILD_FILTERS == (self::BUILD_FILTERS & $mode)) {
         $task = new dinDoctrineBuildFiltersTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         $ret = $task->run();
         if ($ret) {
             return $ret;
         }
     }
     if (self::BUILD_SQL == (self::BUILD_SQL & $mode)) {
         $task = new sfDoctrineBuildSqlTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         $ret = $task->run();
         if ($ret) {
             return $ret;
         }
     }
     if ($options['and-migrate']) {
         $task = new sfDoctrineMigrateTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         $ret = $task->run();
         if ($ret) {
             return $ret;
         }
     } else {
         if (self::BUILD_DB == (self::BUILD_DB & $mode)) {
             $task = new sfDoctrineInsertSqlTask($this->dispatcher, $this->formatter);
             $task->setCommandApplication($this->commandApplication);
             $task->setConfiguration($this->configuration);
             $ret = $task->run();
             if ($ret) {
                 return $ret;
             }
         }
     }
     if (count($options['and-load']) || count($options['and-append'])) {
         $task = new sfDoctrineDataLoadTask($this->dispatcher, $this->formatter);
         $task->setCommandApplication($this->commandApplication);
         $task->setConfiguration($this->configuration);
         if (count($options['and-load'])) {
             $ret = $task->run(array('dir_or_file' => in_array(array(), $options['and-load'], true) ? null : $options['and-load']));
             if ($ret) {
                 return $ret;
             }
         }
         if (count($options['and-append'])) {
             $ret = $task->run(array('dir_or_file' => in_array(array(), $options['and-append'], true) ? null : $options['and-append']), array('append' => true));
             if ($ret) {
                 return $ret;
             }
         }
     }
 }