public function loadFixtures($fixtures) { // initialize database manager $databaseManager = new sfDatabaseManager($this); // cleanup database $db = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . '/database.sqlite'; if (file_exists($db)) { unlink($db); } // initialize database $sql = file_get_contents(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . 'lib.model.schema.sql'); $sql = preg_replace('/^\\s*\\-\\-.+$/m', '', $sql); $sql = preg_replace('/^\\s*DROP TABLE .+?$/m', '', $sql); $con = Propel::getConnection(); $tables = preg_split('/CREATE TABLE/', $sql); foreach ($tables as $table) { $table = trim($table); if (!$table) { continue; } $con->executeQuery('CREATE TABLE ' . $table); } // load fixtures $data = new sfPropelData(); if (is_array($fixtures)) { $data->loadDataFromArray($fixtures); } else { $data->loadData(sfConfig::get('sf_data_dir') . '/' . $fixtures); } }
protected function loadData($fixtures = null) { if (empty($fixtures)) { $fixtures = sfConfig::get('sf_test_dir') . '/phpunit/fixtures/testing.yml'; } $data = new sfPropelData(); $data->loadData($fixtures); }
public function __construct($app, $load_fixtures = true) { $configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', true); new sfDatabaseManager($configuration); if ($load_fixtures) { $loader = new sfPropelData(); $loader->loadData(sfConfig::get('sf_test_dir') . '/fixtures'); } }
/** * Overrides base method, uses the Symfony mechanism to read, validate and insert data. * @see importer/BaseImporter::insertData() */ public function insertData() { $path = func_get_arg(0); try { if ($this->properties->verify) { $this->validateData($path); } $data = new sfPropelData(); $data->setDeleteCurrentData(!$this->properties->append); $data->loadData($path); } catch (Exception $e) { $this->properties->errors[] = "<b>File</b>: " . $path . "<br /><br /><b>Error</b>: " . $e->getMessage() . "<br/>"; } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $filename = $arguments['target']; if (!is_null($filename) && !sfToolkit::isPathAbsolute($filename)) { $dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures'; $this->getFilesystem()->mkdirs($dir); $filename = $dir . DIRECTORY_SEPARATOR . $filename; $this->logSection('propel', sprintf('dumping data to "%s"', $filename)); } $data = new sfPropelData(); $classes = is_null($options['classes']) ? 'all' : explode(',', $options['classes']); if (!is_null($filename)) { $data->dumpData($filename, $classes, $options['connection']); } else { fwrite(STDOUT, sfYaml::dump($data->getData($classes, $options['connection']), 3)); } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); if (count($arguments['dir_or_file'])) { $fixturesDirs = $arguments['dir_or_file']; } else { $fixturesDirs = array_merge(array(sfConfig::get('sf_data_dir') . '/fixtures'), $this->configuration->getPluginSubPaths('/data/fixtures')); } $data = new sfPropelData(); $data->setDeleteCurrentData(!$options['append']); $dirs = array(); foreach ($fixturesDirs as $fixturesDir) { if (!is_readable($fixturesDir)) { continue; } $this->logSection('propel', sprintf('load data from "%s"', $fixturesDir)); $dirs[] = $fixturesDir; } $data->loadData($dirs, $options['connection']); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { if (count($options['dir'])) { $fixturesDirs = $options['dir']; } else { if (!($pluginDirs = glob(sfConfig::get('sf_plugins_dir') . '/*/data'))) { $pluginDirs = array(); } $fixturesDirs = sfFinder::type('dir')->name('fixtures')->in(array_merge($pluginDirs, array(sfConfig::get('sf_data_dir')))); } $databaseManager = new sfDatabaseManager($this->configuration); $data = new sfPropelData(); $data->setDeleteCurrentData(isset($options['append']) ? $options['append'] ? false : true : true); foreach ($fixturesDirs as $fixturesDir) { if (!is_readable($fixturesDir)) { continue; } $this->logSection('propel', sprintf('load data from "%s"', $fixturesDir)); $data->loadData($fixturesDir, $options['connection']); } }
<?php define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'dev'); define('SF_DEBUG', true); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; // initialize database manager $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); $data = new sfPropelData(); $data->loadData(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures'); // run Init data functions /*$initFile = SF_ROOT_DIR.DIRECTORY_SEPARATOR.'batch/init_data.php'; if (file_exists($initFile)) { include $initFile; InitData(); }*/
<?php include dirname(__FILE__) . '/unit.php'; $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true); new sfDatabaseManager($configuration); $loader = new sfPropelData(); $loader->loadData(sfConfig::get('sf_test_dir') . '/fixtures');
/** * Loads yml data from fixtures directory and inserts into database. * * @example symfony load-data frontend * @example symfony load-data frontend dev fixtures append * * @todo replace delete argument with flag -d * * @param object $task * @param array $args */ function run_propel_load_data($task, $args) { if (!count($args)) { throw new Exception('You must provide the app.'); } $app = $args[0]; if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) { throw new Exception('The app "' . $app . '" does not exist.'); } if (count($args) > 1 && $args[count($args) - 1] == 'append') { array_pop($args); $delete = false; } else { $delete = true; } $env = empty($args[1]) ? 'dev' : $args[1]; // define constants define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', $app); define('SF_ENVIRONMENT', $env); define('SF_DEBUG', true); // get configuration require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; if (count($args) == 1) { if (!($pluginDirs = glob(sfConfig::get('sf_root_dir') . '/plugins/*/data'))) { $pluginDirs = array(); } $fixtures_dirs = pakeFinder::type('dir')->name('fixtures')->in(array_merge($pluginDirs, array(sfConfig::get('sf_data_dir')))); } else { $fixtures_dirs = array_slice($args, 1); } $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); $data = new sfPropelData(); $data->setDeleteCurrentData($delete); foreach ($fixtures_dirs as $fixtures_dir) { if (!is_readable($fixtures_dir)) { continue; } pake_echo_action('propel', sprintf('load data from "%s"', $fixtures_dir)); $data->loadData($fixtures_dir); } }
/** * Loads the fixture files of the migration. * * Has to be called manually. * * Be careful. Due to the nature Propel and fixture-loading works you'll * probably get problems when you change the definitions of affected tables * in later migrations. * * @param boolean $deleteOldRecords Whether the affected tables' content should be deleted prior to loading the fixtures, default: false * @param string $con Propel connection identifier, as defined in the database.yml file */ protected function loadFixtures($deleteOldRecords = false, $con = 'symfony') { $fixturesDir = $this->getMigrator()->getMigrationsFixturesDir().DIRECTORY_SEPARATOR.$this->getMigrationNumber(); if (!is_dir($fixturesDir)) { throw new sfException('No fixtures exist for migration '.$this->getMigrationNumber()); } $data = new sfPropelData(); $data->setDeleteCurrentData($deleteOldRecords); $data->loadData($fixturesDir, $con); }
public function loadData() { $loader = new sfPropelData(); $loader->loadData(sfConfig::get('sf_test_dir') . '/fixtures'); return $this; }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ // guess current application if (!isset($app)) { $traces = debug_backtrace(); $caller = $traces[0]; $dirPieces = explode(DIRECTORY_SEPARATOR, dirname($caller['file'])); $app = array_pop($dirPieces); } require_once dirname(__FILE__) . '/../../config/ProjectConfiguration.class.php'; $configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', isset($debug) ? $debug : true); sfContext::createInstance($configuration); if (!isset($executeLoader) || $executeLoader) { $loader = new sfPropelData(); $loader->setDeleteCurrentData(true); $loader->loadData(dirname(__FILE__) . '/../fixtures'); } // remove all cache sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir'));
<?php /* * This file is part of the sfPropelActAsRatableBehavior package. * * (c) 2009 Kasper Garnæs <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ $_test_dir = realpath(dirname(__FILE__) . '/..'); require_once dirname(__FILE__) . '/../../../../config/ProjectConfiguration.class.php'; $configuration = new ProjectConfiguration(realpath($_test_dir . '/..')); $appConfiguration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true); sfContext::createInstance($appConfiguration); new sfDatabaseManager($appConfiguration); $loader = new sfPropelData(); $loader->loadData(dirname(__FILE__) . '/fixtures.yml'); include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
<?php // guess current application if (!isset($app)) { $app = 'backend'; } require_once dirname(__FILE__) . '/../../../../config/ProjectConfiguration.class.php'; $configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', isset($debug) ? $debug : true); sfContext::createInstance($configuration); // remove all cache sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir')); // cp data files - why are they deleted during tests? :-| copy(dirname(__FILE__) . '/../data/demo1.png', dirname(__FILE__) . '/../data/demo.png'); copy(dirname(__FILE__) . '/../data/propel1.gif', dirname(__FILE__) . '/../data/propel.gif'); copy(dirname(__FILE__) . '/../data/demo1.png', dirname(__FILE__) . '/../data/demo2.png'); copy(dirname(__FILE__) . '/../data/propel1.gif', dirname(__FILE__) . '/../data/propel2.gif'); // load fixtures $data = new sfPropelData(); $data->loadData(dirname(__FILE__) . '/../data/fixtures/');
public function initialize($hostname = null, $remote = null, $options = array()) { parent::initialize($hostname, $remote, $options); $loader = new sfPropelData(); $loader->loadData($sf_symfony_lib_dir . '/data/fixtures/'); }
if (isset($fixtures)) { // initialize database manager $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); // cleanup database $db = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . '/database.sqlite'; if (file_exists($db)) { unlink($db); } // initialize database $sql = file_get_contents(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . 'lib.model.schema.sql'); $sql = preg_replace('/^\\s*\\-\\-.+$/m', '', $sql); $sql = preg_replace('/^\\s*DROP TABLE .+?$/m', '', $sql); $con = Propel::getConnection(); $tables = preg_split('/CREATE TABLE/', $sql); foreach ($tables as $table) { $table = trim($table); if (!$table) { continue; } $con->executeQuery('CREATE TABLE ' . $table); } // load fixtures $data = new sfPropelData(); if (is_array($fixtures)) { $data->loadDataFromArray($fixtures); } else { $data->loadData(sfConfig::get('sf_data_dir') . '/' . $fixtures); } } return true;