Created
August 23, 2009 13:08
-
-
Save soh335/173271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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