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

Changeset 12334


Ignore:
Timestamp:
Jul 21, 2009, 9:42:13 PM (11 years ago)
Author:
ebihara
Message:

#4144:added support for loading fixtures when running openpne:migrate task after the installing plugins

Location:
OpenPNE3/trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/plugin/opPluginManager.class.php

    r11004 r12334  
    8989    return (bool)$this->getPluginInfo($plugin);
    9090  }
     91
     92  public function ListenToPluginPostUninstall($event)
     93  {
     94    parent::ListenToPluginPostUninstall($event);
     95
     96    $this->uninstallModelFiles($event['plugin']);
     97  }
     98
     99  public function uninstallModelFiles($plugin)
     100  {
     101    $filesystem = new sfFilesystem();
     102
     103    $baseDir = sfConfig::get('sf_lib_dir');
     104    $subpackages = array('model', 'form', 'filter');
     105
     106    foreach ($subpackages as $subpackage)
     107    {
     108      $targetDir = $baseDir.DIRECTORY_SEPARATOR.$subpackage.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR.$plugin;
     109      if (is_dir($targetDir))
     110      {
     111        $filesystem->remove(sfFinder::type('any')->in($targetDir));
     112        $filesystem->remove($targetDir);
     113      }
     114    }
     115  }
    91116}
  • OpenPNE3/trunk/lib/task/opPluginInstallTask.class.php

    r11538 r12334  
    3838  }
    3939
     40  // copied from sfDoctrineBaseTask
     41  protected function createConfiguration($application, $env)
     42  {
     43    $configuration = parent::createConfiguration($application, $env);
     44
     45    $autoloader = sfSimpleAutoload::getInstance();
     46    $config = new sfAutoloadConfigHandler();
     47    $mapping = $config->evaluate($configuration->getConfigPaths('config/autoload.yml'));
     48    foreach ($mapping as $class => $file)
     49    {
     50      $autoloader->setClassPath($class, $file);
     51    }
     52    $autoloader->register();
     53
     54    return $configuration;
     55  }
     56
    4057  protected function execute($arguments = array(), $options = array())
    4158  {
     
    5673    try
    5774    {
     75      $isExists = $this->isPluginExists($arguments['name']);
    5876      parent::execute($arguments, $options);
     77
     78      if (!$isExists)
     79      {
     80        $databaseManager = new sfDatabaseManager($this->configuration);
     81        Doctrine::getTable('SnsConfig')->set($arguments['name'].'_needs_data_load', '1');
     82      }
    5983    }
    6084    catch (sfPluginException $e)
  • OpenPNE3/trunk/lib/task/opPluginUninstallTask.class.php

    r10003 r12334  
    3232EOF;
    3333  }
     34
     35  public function getPluginManager()
     36  {
     37    $oldPluginManager = parent::getPluginManager();
     38    $pluginManager = new opPluginManager($this->dispatcher, $oldPluginManager->getEnvironment());
     39
     40    return $pluginManager;
     41  }
    3442}
  • OpenPNE3/trunk/lib/task/openpneMigrateTask.class.php

    r12284 r12334  
    1111class openpneMigrateTask extends sfDoctrineBaseTask
    1212{
     13  protected $migrationException = null;
     14
    1315  protected function configure()
    1416  {
     
    7476
    7577    $this->migrateFromDiff();
     78
     79    foreach ($targets as $target)
     80    {
     81      $this->dataLoadForInitializePlugin($target);
     82    }
     83
     84    if ($this->migrationException)
     85    {
     86      throw $this->migrationException;
     87    }
    7688  }
    7789
     
    96108  }
    97109
     110  protected function dataLoadForInitializePlugin($pluginName)
     111  {
     112    if ('OpenPNE' === $pluginName)
     113    {
     114      return null;
     115    }
     116
     117    $fixturesDir = sfConfig::get('sf_plugins_dir').'/'.$pluginName.'/data/fixtures';
     118    if ((bool)Doctrine::getTable('SnsConfig')->get($pluginName.'_needs_data_load', false)
     119      && is_readable($fixturesDir))
     120    {
     121      $this->logSection('doctrine', sprintf('loading data fixtures for "%s"', $pluginName));
     122
     123      $config = $this->getCliConfig();
     124
     125      Doctrine::loadModels($config['models_path']);
     126      Doctrine::loadData(array($fixturesDir), true);
     127    }
     128
     129    Doctrine::getTable('SnsConfig')->set($pluginName.'_needs_data_load', '0');
     130  }
     131
    98132  protected function throwSpecifiedException(Exception $e)
    99133  {
     
    118152
    119153    $migrationsPath = sfConfig::get('sf_data_dir').'/migrations/generated';
    120     $this->callDoctrineCli('migrate', array('migrations_path' => $migrationsPath));
     154
     155    try
     156    {
     157      $this->callDoctrineCli('migrate', array('migrations_path' => $migrationsPath));
     158    }
     159    catch (Exception $e)
     160    {
     161      $this->migrationException = $e;
     162    }
    121163  }
    122164
Note: See TracChangeset for help on using the changeset viewer.