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

Changeset 8921


Ignore:
Timestamp:
Nov 1, 2008, 9:25:20 PM (11 years ago)
Author:
ebihara
Message:

#3114:openpneInstallTask is now initializing database, loading datas and clearing caches

File:
1 edited

Legend:

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

    r8920 r8921  
    11<?php
    22
    3 class openpneInstallTask extends sfBaseTask
     3class openpneInstallTask extends sfPropelBaseTask
    44{
    55  protected function configure()
     
    77    $this->namespace        = 'openpne';
    88    $this->name             = 'install';
    9     $this->briefDescription = '';
     9
     10    $this->addArguments(array(
     11      new sfCommandArgument('dsn', sfCommandArgument::REQUIRED, 'The database dsn'),
     12    ));
     13
     14    $this->briefDescription = 'Install OpenPNE';
    1015    $this->detailedDescription = <<<EOF
    11 The [openpne:install|INFO] task does things.
     16The [openpne:install|INFO] task installs and configures OpenPNE.
    1217Call it with:
    1318
    14   [php symfony openpne:install|INFO]
     19  [./symfony openpne:install|INFO]
    1520EOF;
    16     // add arguments here, like the following:
    17     //$this->addArgument('application', sfCommandArgument::REQUIRED, 'The application name');
    18     // add options here, like the following:
    19     //$this->addOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev');
    2021  }
    2122
    2223  protected function execute($arguments = array(), $options = array())
    2324  {
    24     // add code here
     25    $this->clearCache();
     26    $this->configureDatabase($arguments['dsn']);
     27    $this->buildDb();
     28    $this->clearCache();
     29  }
     30
     31  protected function configureDatabase($dsn)
     32  {
     33    $file = sfConfig::get('sf_config_dir').'/databases.yml';
     34    $config = array();
     35
     36    if (file_exists($file))
     37    {
     38      $config = sfYaml::load($file);
     39    }
     40
     41    $config['all']['propel'] = array(
     42      'class' => 'sfPropelDatabase',
     43      'param' => array('dsn' => $dsn, 'encoding' => 'utf8'),
     44    );
     45
     46    file_put_contents($file, sfYaml::dump($config, 4));
     47
     48    // update propel.ini
     49    $propelini = sfConfig::get('sf_config_dir').'/propel.ini';
     50    if (file_exists($propelini))
     51    {
     52      $content = file_get_contents($propelini);
     53      if (preg_match('/^(.+?):\/\//', $dsn, $match))
     54      {
     55        $content = preg_replace('/^propel\.database(\s*)=(\s*)(.+?)$/m', 'propel.database$1=$2'.$match[1], $content);
     56        $content = preg_replace('/^propel\.database\.createUrl(\s*)=(\s*)(.+?)$/m', 'propel.database.createUrl$1=$2'.$dsn, $content);
     57        $content = preg_replace('/^propel\.database\.url(\s*)=(\s*)(.+?)$/m', 'propel.database.url$1=$2'.$dsn, $content);
     58
     59        file_put_contents($propelini, $content);
     60      }
     61    }
     62  }
     63
     64  protected function clearCache()
     65  {
     66    $cc = new sfCacheClearTask($this->dispatcher, $this->formatter);
     67    $cc->run();
     68  }
     69
     70  protected function buildDb()
     71  {
     72    $this->schemaToXML(self::DO_NOT_CHECK_SCHEMA, 'generated-');
     73    $this->copyXmlSchemaFromPlugins('generated-');
     74
     75/*
     76    $buildDb = new sfPropelBuildDbTask($this->dispatcher, $this->formatter);
     77    $buildDb->run();
     78    */
     79
     80    $buildAllLoad = new sfPropelBuildAllLoadTask($this->dispatcher, $this->formatter);
     81    $buildAllLoad->run(array('application' => 'pc_frontend'));
    2582  }
    2683}
Note: See TracChangeset for help on using the changeset viewer.