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, 'and-migrate' => $options['migrate']));
     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, '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;
 }
 public function run()
 {
     opApplicationConfiguration::unregisterZend();
     $task = new sfDoctrineBuildTask(clone $this->options['dispatcher'], clone $this->options['formatter']);
     $task->run(array(), array('no-confirmation' => true, 'model' => true, 'forms' => true, 'filters' => true, 'application' => 'pc_frontend', 'env' => sfConfig::get('sf_environment', 'prod')));
     $task = new sfCacheClearTask(clone $this->options['dispatcher'], clone $this->options['formatter']);
     $task->run(array(), array('application' => null, 'env' => sfConfig::get('sf_environment', 'prod')));
     opApplicationConfiguration::registerZend();
 }
 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);
 }
Esempio n. 6
0
 /**
  * SetUp
  */
 public function setUp()
 {
     $dir = getcwd();
     chdir(sfConfig::get('sf_root_dir'));
     // Clear logs
     sfToolkit::clearDirectory(sfConfig::get('sf_log_dir'));
     // Remove cache
     sfToolkit::clearDirectory(sfConfig::get('sf_cache_dir'));
     // Rebuild DB
     $task = new sfDoctrineBuildTask(new sfEventDispatcher(), new sfFormatter());
     $task->run($args = array(), $options = array('env' => 'test', 'no-confirmation' => true, 'db' => true, 'and-migrate' => true, 'application' => 'frontend'));
     // Таск создает свой конфиг, после чего в изоляции может молча умереть
     ProjectConfiguration::getApplicationConfiguration('frontend', 'test', $debug = true);
     chdir($dir);
 }
 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);
 }
 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();
 }
Esempio n. 9
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'));
}
Esempio n. 10
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.
 */
$configuration = ProjectConfiguration::getApplicationConfiguration('pc_frontend', 'test', true);
new sfDatabaseManager($configuration);
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->setConfiguration($configuration);
$task->run(array(), array('no-confirmation' => true, 'db' => true, 'and-load' => dirname(__FILE__) . '/../fixtures'));
Esempio n. 11
0
<?php

$_app = 'pc_frontend';
$_env = 'test';
if (!isset($fixture)) {
    $fixture = 'common';
}
$configuration = ProjectConfiguration::getApplicationConfiguration($_app, $_env, true);
new sfDatabaseManager($configuration);
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->setConfiguration($configuration);
$task->run(array(), array('no-confirmation' => true, 'db' => true, 'and-load' => dirname(__FILE__) . '/../fixtures/' . $fixture, 'application' => $_app, 'env' => $_env));
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
$conn->clear();
<?php

$app = 'frontend';
include dirname(__FILE__) . '/../bootstrap/functional.php';
new sfDatabaseManager($configuration);
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->run(array(), array('sql', 'db', 'and-load', 'no-confirmation', 'application' => $app));
$conn = Doctrine::getConnectionByTableName('Author');
$conn->beginTransaction();
$browser = new sfTestFunctional(new sfBrowser());
$browser->test()->info('Updating first author');
$firstAuthor = Doctrine::getTable('Author')->findOneBySlug('niko');
$browser->get('/author/' . $firstAuthor->slug . '/view')->with('response')->begin()->checkElement('h1', '/niko/')->checkElement('ul#comments li', 1)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$browser->getContext(true)->switchTo('backend');
$firstAuthor->name = 'n1k0';
$firstAuthor->save($conn);
$browser->get('/author/' . $firstAuthor->slug . '/view')->with('response')->begin()->checkElement('h1', '/n1k0/')->checkElement('ul#comments li', 1)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$conn->rollback();
 protected function _buildAllClasses()
 {
     $this->logSection('sympal', '...building all classes', null, 'COMMENT');
     chdir(sfConfig::get('sf_root_dir'));
     $task = new sfDoctrineBuildTask($this->_dispatcher, $this->_formatter);
     $task->run(array(), array('all-classes', '--application=' . sfConfig::get('sf_app')));
 }
Esempio n. 14
0
 /**
  * This method performs the following tasks:
  *   * Creates the database
  *   * Builds the tables
  */
 protected function _setupDatabase()
 {
     $this->logSection('database', 'Testing the database connection...');
     try {
         $conn = Doctrine_Manager::getInstance()->getCurrentConnection();
         if (!$conn) {
             throw Exception();
         }
         /*
          * Try to create the database.
          * 
          * It may already exist (which is ok), so swallow the error. If the
          * error was something other than the database already existing,
          * the error will rethrow in ->connect()
          */
         try {
             $conn->createDatabase();
         } catch (Exception $e) {
         }
         $conn->connect();
     } catch (Exception $e) {
         if ($this->_trace) {
             throw $e;
         } else {
             throw new InvalidArgumentException('Could not make database connection: database connection not setup properly in databases.yml');
         }
     }
     $this->logSection('database', '...Database connection is setup correctly');
     $task = new sfDoctrineBuildTask($this->_dispatcher, $this->_formatter);
     $options = array('db' => true, 'no-confirmation' => true, 'and-load' => false, 'application' => $this->_application);
     $this->logTaskCall('database', 'Building database and tables', sprintf('doctrine:build --db --and-load=false --application=%s', $this->_application));
     $this->_disableOutput();
     $task->run(array(), $options);
     $this->_enableOutput();
     $this->logSection('database', '...database and tables built successfully');
 }
 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);
 }
Esempio n. 16
0
<?php

$executeLoader = false;
$app = 'api';
include dirname(__FILE__) . '/../../bootstrap/functional.php';
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->setConfiguration($configuration);
$task->run(array(), array('no-confirmation' => true, 'db' => true, 'and-load' => dirname(__FILE__) . '/fixtures/member_search.yml', 'application' => $app, 'env' => 'test'));
$browser = new opTestFunctional(new opBrowser(), new lime_test(null, new lime_output_color()));
Doctrine::getTable('SnsConfig')->set('enable_jsonapi', true);
$key = Doctrine::getTable('Member')->find(1)->getApiKey();
$browser->get('member/search.json', array('apiKey' => $key, 'target' => 'friend', 'target_id' => 1))->with('request')->begin()->isParameter('module', 'member')->isParameter('action', 'search')->end()->with('response')->isStatusCode(200);
$json = $browser->getResponse()->getContent();
$data = json_decode($json, true);
$t = $browser->test();
$t->is($data['status'], 'success', 'status is "success".');
$t->is(count($data['data']), 1, 'returned member count is 1(NOT including blocking_member and prefriend_member).');
$t->is($data['data'][0]['name'], 'Already-friend', 'only including friend member');
Esempio n. 17
0
 /**
  * Method called during a fresh install (or a force reload)
  * 
  * This method performs the following tasks:
  *   * Writes the database dsn to databases.yml
  *   * Creates the database
  *   * Loads the install fixtures
  */
 protected function _setupDatabase()
 {
     if (isset($this->_params['db_dsn']) && isset($this->_params['db_username'])) {
         $task = new sfDoctrineConfigureDatabaseTask($this->_dispatcher, $this->_formatter);
         $task->run(array('dsn' => $this->_params['db_dsn'], 'username' => $this->_params['db_username'], 'password' => $this->_params['db_password']));
         try {
             $conn = Doctrine_Manager::getInstance()->openConnection($this->_params['db_dsn'], 'test', false);
             $conn->setOption('username', $this->_params['db_username']);
             $conn->setOption('password', $this->_params['db_password']);
             try {
                 $conn->createDatabase();
             } catch (Exception $e) {
             }
             $conn->connect();
         } catch (Exception $e) {
             throw new InvalidArgumentException('Database credentials are not valid!');
         }
     }
     $task = new sfDoctrineBuildTask($this->_dispatcher, $this->_formatter);
     $options = array('db' => true, 'no-confirmation' => true, 'and-load' => false, 'application' => $this->_application);
     $task->run(array(), $options);
 }