Development

Changeset 3385

You must first sign up to be able to contribute.

Changeset 3385

Show
Ignore:
Timestamp:
02/01/07 10:24:33 (6 years ago)
Author:
fabien
Message:

added propel-dump-data task

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/data/tasks/sfPakePropel.php

    r3157 r3385  
    2727pake_task('propel-load-data', 'project_exists'); 
    2828 
     29pake_desc('dump data to fixtures directory'); 
     30pake_task('propel-dump-data', 'project_exists'); 
     31 
    2932pake_desc('create database for current model'); 
    3033pake_task('propel-build-db', 'project_exists'); 
     
    218221 
    219222/** 
    220  * loads yml data from fixtures directory and inserts into database 
     223 * Dumps yml database data to fixtures directory. 
     224 * 
     225 * @example symfony dump-data frontend data.yml 
     226 * @example symfony dump-data frontend data.yml dev 
     227 * 
     228 * @param object $task 
     229 * @param array $args 
     230 */ 
     231function run_propel_dump_data($task, $args) 
     232
     233  if (!count($args)) 
     234  { 
     235    throw new Exception('You must provide the app.'); 
     236  } 
     237 
     238  $app = $args[0]; 
     239 
     240  if (!is_dir(sfConfig::get('sf_app_dir').DIRECTORY_SEPARATOR.$app)) 
     241  { 
     242    throw new Exception('The app "'.$app.'" does not exist.'); 
     243  } 
     244 
     245  if (!isset($args[1])) 
     246  { 
     247    throw new Exception('You must provide a filename.'); 
     248  } 
     249 
     250  $filename = $args[1]; 
     251 
     252  $env = empty($args[2]) ? 'dev' : $args[2]; 
     253 
     254  // define constants 
     255  define('SF_ROOT_DIR',    sfConfig::get('sf_root_dir')); 
     256  define('SF_APP',         $app); 
     257  define('SF_ENVIRONMENT', $env); 
     258  define('SF_DEBUG',       true); 
     259 
     260  // get configuration 
     261  require_once SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'; 
     262 
     263  $databaseManager = new sfDatabaseManager(); 
     264  $databaseManager->initialize(); 
     265 
     266  if (!sfToolkit::isPathAbsolute($filename)) 
     267  { 
     268    $dir = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures'; 
     269    pake_mkdirs($dir); 
     270    $filename = $dir.DIRECTORY_SEPARATOR.$filename; 
     271  } 
     272 
     273  pake_echo_action('propel', sprintf('dumping data to "%s"', $filename)); 
     274 
     275  $data = new sfPropelData(); 
     276  $data->dumpData($filename); 
     277
     278 
     279/** 
     280 * Loads yml data from fixtures directory and inserts into database. 
    221281 * 
    222282 * @example symfony load-data frontend