public function initializeDoctrine()
 {
     chdir(sfConfig::get('sf_root_dir'));
     $task = new sfDoctrineBuildTask($this->dispatcher, new sfFormatter());
     $task->setConfiguration($this);
     $task->run(array(), array('no-confirmation' => true, 'db' => true, 'model' => true, 'forms' => true, 'filters' => true));
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $task = new sfDoctrineBuildTask($this->dispatcher, $this->formatter);
     $task->setCommandApplication($this->commandApplication);
     $task->setConfiguration($this->configuration);
     $ret = $task->run(array(), array('no-confirmation' => $options['no-confirmation'], 'db' => true, 'model' => true, 'forms' => !$options['skip-forms'], 'filters' => !$options['skip-forms'], 'sql' => true, 'and-migrate' => $options['migrate'], 'and-load' => $options['append'] ? false : (count($options['dir']) ? $options['dir'] : true), 'and-append' => $options['append'] ? count($options['dir']) ? $options['dir'] : true : false));
     return $ret;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $task = new sfDoctrineBuildTask($this->dispatcher, $this->formatter);
     $task->setCommandApplication($this->commandApplication);
     $task->setConfiguration($this->configuration);
     $ret = $task->run(array(), array('no-confirmation' => $options['no-confirmation'], 'db' => true, 'and-migrate' => $options['migrate']));
     return $ret;
 }
 public function initializeDoctrine($fixtures = false)
 {
     chdir(sfConfig::get('sf_root_dir'));
     $task = new sfDoctrineBuildTask($this->dispatcher, new sfFormatter());
     $task->setConfiguration($this);
     $options = array('db', 'no-confirmation');
     if ($fixtures) {
         $options[] = 'and-load';
     }
     $task->run(array(), $options);
 }
 protected function buildDb($options)
 {
     $tmpdir = sfConfig::get('sf_data_dir') . '/fixtures_tmp';
     $this->getFilesystem()->mkdirs($tmpdir);
     $this->getFilesystem()->remove(sfFinder::type('file')->in(array($tmpdir)));
     $pluginDirs = sfFinder::type('dir')->name('data')->in(sfFinder::type('dir')->name('op*Plugin')->maxdepth(1)->in(sfConfig::get('sf_plugins_dir')));
     $fixturesDirs = sfFinder::type('dir')->name('fixtures')->prune('migrations', 'upgrade')->in(array_merge(array(sfConfig::get('sf_data_dir')), $this->configuration->getPluginSubPaths('/data'), $pluginDirs));
     $i = 0;
     foreach ($fixturesDirs as $fixturesDir) {
         $files = sfFinder::type('file')->name('*.yml')->sort_by_name()->in(array($fixturesDir));
         foreach ($files as $file) {
             $this->getFilesystem()->copy($file, $tmpdir . '/' . sprintf('%03d_%s_%s.yml', $i, basename($file, '.yml'), md5(uniqid(rand(), true))));
         }
         $i++;
     }
     $task = new sfDoctrineBuildTask($this->dispatcher, $this->formatter);
     $task->setCommandApplication($this->commandApplication);
     $task->setConfiguration($this->configuration);
     $task->run(array(), array('no-confirmation' => true, 'db' => true, 'model' => true, 'forms' => true, 'filters' => true, 'sql' => true, 'and-load' => $tmpdir, 'application' => $options['application'], 'env' => $options['env']));
     $this->getFilesystem()->remove(sfFinder::type('file')->in(array($tmpdir)));
     $this->getFilesystem()->remove($tmpdir);
 }
Esempio n. 6
0
<?php

/**
 * This file is part of the OpenPNE package.
 * (c) OpenPNE Project (http://www.openpne.jp/)
 *
 * For the full copyright and license information, please view the LICENSE
 * file and the NOTICE file that were distributed with this source code.
 */
if (empty($_app)) {
    $_app = 'pc_frontend';
}
$_env = 'test';
$configuration = ProjectConfiguration::getApplicationConfiguration($_app, $_env, true);
new sfDatabaseManager($configuration);
try {
    if (3 > (int) Doctrine::getTable('SnsConfig')->get('opDiaryPlugin_test_revision')) {
        throw new Exception();
    }
} catch (Exception $e) {
    $task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
    $task->setConfiguration($configuration);
    $task->run(array(), array('no-confirmation' => true, 'db' => true, 'and-load' => false, 'application' => $_app, 'env' => $_env));
    $task = new sfDoctrineDataLoadTask($configuration->getEventDispatcher(), new sfFormatter());
    $task->setConfiguration($configuration);
    $task->run(array(dirname(__FILE__) . '/../../../../data/fixtures/010_import_sns_terms.yml', dirname(__FILE__) . '/../../../../data/fixtures/003_import_admin_user.yml', dirname(__FILE__) . '/../fixtures'));
}
 protected function buildDb($options)
 {
     $tmpdir = sfConfig::get('sf_data_dir') . '/fixtures_tmp';
     $this->getFilesystem()->mkdirs($tmpdir);
     $this->getFilesystem()->remove(sfFinder::type('file')->in(array($tmpdir)));
     $pluginDirs = sfFinder::type('dir')->name('data')->in(sfFinder::type('dir')->name('op*Plugin')->maxdepth(1)->in(sfConfig::get('sf_plugins_dir')));
     $fixturesDirs = sfFinder::type('dir')->name('fixtures')->prune('migrations', 'upgrade')->in(array_merge(array(sfConfig::get('sf_data_dir')), $this->configuration->getPluginSubPaths('/data'), $pluginDirs));
     $i = 0;
     foreach ($fixturesDirs as $fixturesDir) {
         $files = sfFinder::type('file')->name('*.yml')->sort_by_name()->in(array($fixturesDir));
         foreach ($files as $file) {
             $this->getFilesystem()->copy($file, $tmpdir . '/' . sprintf('%03d_%s_%s.yml', $i, basename($file, '.yml'), md5(uniqid(rand(), true))));
         }
         $i++;
     }
     $task = new sfDoctrineBuildTask($this->dispatcher, $this->formatter);
     $task->setCommandApplication($this->commandApplication);
     $task->setConfiguration($this->configuration);
     $task->run(array(), array('no-confirmation' => true, 'db' => !$options['non-recreate-db'], 'model' => true, 'forms' => true, 'filters' => true, 'sql' => !$options['non-recreate-db'], 'and-load' => $options['non-recreate-db'] ? null : $tmpdir, 'application' => $options['application'], 'env' => $options['env']));
     if ($options['non-recreate-db']) {
         $connection = Doctrine_Manager::connection();
         $config = $this->getCliConfig();
         Doctrine_Core::loadModels($config['models_path'], Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
         $tables = array();
         $relatedTables = array();
         $droppedTables = array();
         $models = Doctrine_Core::getLoadedModels();
         foreach ($models as $model) {
             $table = Doctrine::getTable($model)->getTableName();
             $tables[] = $table;
             $relations = $connection->import->listTableRelations($table);
             foreach ($relations as $relation) {
                 if (empty($relatedTables[$relation['table']])) {
                     $relatedTables[$relation['table']] = array();
                 }
                 $relatedTables[$relation['table']][] = $table;
             }
         }
         // first, non-related tables can be removed
         $nonRelatedTables = array_diff($tables, array_keys($relatedTables));
         foreach ($nonRelatedTables as $targetTable) {
             $droppedTables[] = $targetTable;
             if ($connection->import->tableExists($targetTable)) {
                 $connection->export->dropTable($targetTable);
             }
         }
         // second, related tables
         uasort($relatedTables, create_function('$a, $b', '$_a = count($a); $_b = count($b); if ($_a == $_b) return 0; return ($_a < $_b) ? -1 : 1;'));
         foreach ($relatedTables as $relatedTable => &$relation) {
             $this->dropRelations($relatedTable, $relatedTables, $droppedTables);
         }
         $this->initDb($tmpdir);
     }
     $this->getFilesystem()->remove(sfFinder::type('file')->in(array($tmpdir)));
     $this->getFilesystem()->remove($tmpdir);
 }
 protected function buildModel($options)
 {
     $task = new sfDoctrineBuildTask($this->dispatcher, $this->formatter);
     $task->setCommandApplication($this->commandApplication);
     $task->setConfiguration($this->configuration);
     $task->run(array(), array('no-confirmation' => true, 'model' => true, 'forms' => true, 'filters' => true, 'application' => $options['application'], 'env' => $options['env']));
     $task = new sfCacheClearTask($this->dispatcher, $this->formatter);
     @$task->run();
     $task = new openpnePermissionTask($this->dispatcher, $this->formatter);
     @$task->run();
 }