ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 10833


Ignore:
Timestamp:
Feb 23, 2009, 8:04:33 PM (13 years ago)
Author:
ebihara
Message:

#3502:changed the openpne:migrate task to migrate OpenPNE and all plugins when the target option isn't specified. This task warns when the when the user specifies the revision / the version option without the target option now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/task/openpneMigrateTask.class.php

    r10830 r10833  
    1818    require sfConfig::get('sf_data_dir').'/version.php';
    1919
    20     $this->addArguments(array(
    21       new sfCommandArgument('name', sfCommandArgument::OPTIONAL, 'The plugin name or "OpenPNE"', 'OpenPNE'),
    22     ));
    23 
    2420    $this->addOptions(array(
     21      new sfCommandOption('target', null, sfCommandOption::PARAMETER_OPTIONAL, 'The target of migration'),
    2522      new sfCommandOption('to-version', 'v', sfCommandOption::PARAMETER_OPTIONAL, 'To version'),
    2623      new sfCommandOption('to-revision', 'r', sfCommandOption::PARAMETER_OPTIONAL, 'To revision'),
     
    4441    }
    4542
     43    if (!$options['target'] && ($options['to-version'] || $options['to-revision']))
     44    {
     45      throw new sfCommandException("You can't specify the to-version option or the to-revision option without the target option");
     46    }
     47
    4648    if (!$options['no-build-model'])
    4749    {
     
    5052
    5153    $databaseManager = new sfDatabaseManager($this->configuration);
    52     $migration = new opMigration($this->dispatcher, $databaseManager, $arguments['name'], null, $options['to-version']);
    53     $migration->migrate();
     54
     55    if (!empty($options['target']))
     56    {
     57      $targets = array($options['target']);
     58    }
     59    else
     60    {
     61      $targets = array_merge(array('OpenPNE'), $this->getEnabledOpenPNEPlugin());
     62    }
     63
     64    foreach ($targets as $target)
     65    {
     66      $migration = new opMigration($this->dispatcher, $databaseManager, $target, null, $options['to-version']);
     67
     68      try
     69      {
     70        $migration->migrate();
     71      }
     72      catch (Doctrine_Migration_Exception $e)
     73      {
     74        if (0 !== strpos($e->getMessage(), 'Already at version #'))
     75        {
     76          throw $e;
     77        }
     78      }
     79
     80      $this->logSection('migrate', sprintf('%s is now at revision %d.', $target, $migration->getCurrentVersion()));
     81    }
    5482  }
    5583
     
    6593    $task->run();
    6694  }
     95
     96  protected function getEnabledOpenPNEPlugin()
     97  {
     98    $list = $this->configuration->getPlugins();
     99    $result = array();
     100
     101    foreach ($list as $value)
     102    {
     103      if (!strncmp($value, 'op', 2))
     104      {
     105        $result[] = $value;
     106      }
     107    }
     108
     109    return $result;
     110  }
    67111}
Note: See TracChangeset for help on using the changeset viewer.