Implements the abstract loadDataFromArray method and loads the data using the generated data model.
public loadDataFromArray ( array $data ) | ||
$data | array | The data to be loaded into the data source |
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); } }
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;