/** * 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); 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']); } }
/** * 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); }
<?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'));