All pastes #374749 Raw Edit

doctrine-load-data

public php v1 · immutable
#374749 ·published 2007-02-27 20:19 UTC
rendered paste body
function run_doctrine_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);  }    $context = sfContext::getInstance();    $data = new sfDoctrineData();  $data->setDeleteCurrentData($delete);    foreach ($fixtures_dirs as $fixtures_dir)  {     if (!is_readable($fixtures_dir))    {       continue;    }        pake_echo_action('doctrine', sprintf('load data from "%s"', $fixtures_dir));    $data->loadData($fixtures_dir);  }}