Skip to content

Instantly share code, notes, and snippets.

@soh335
Created August 23, 2009 13:08
Show Gist options
  • Save soh335/173271 to your computer and use it in GitHub Desktop.
Save soh335/173271 to your computer and use it in GitHub Desktop.
<?php
pake_desc('my load data');
pake_task('my_load_data','project_exists');
define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/../..'));
function run_my_load_data($task,$args){
define('SF_APP', array_shift($args));
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
require_once('mysfPropelData.class.php');
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
$database = array_shift($args);
$path = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.$database;
$data = new mysfPropelData();
$is_append = false;
if($args[count($args)-1] == "append"){
$is_append = true;array_pop($args);
}
if(count($args) == 0){
$data->loadData($path, $database, $is_append);
}else{
foreach($args as $filename){
$data->loadData($path.DIRECTORY_SEPARATOR.$filename, $database, $is_append);
}
}
}
?>
<?php
class mysfPropelData extends sfPropelData {
public function loadData($directory_or_file = null, $connectionName = 'propel', $is_append=false)
{
$fixture_files = $this->getFiles($directory_or_file);
// wrap all database operations in a single transaction
$this->con = Propel::getConnection($connectionName);
try
{
$this->con->begin();
if(!$is_append)
$this->doDeleteCurrentData($fixture_files);
$this->doLoadData($fixture_files);
$this->con->commit();
}
catch (Exception $e)
{
$this->con->rollback();
throw $e;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment