Skip to content

Instantly share code, notes, and snippets.

@b00gizm
Created May 26, 2010 22:18
Show Gist options
  • Save b00gizm/415157 to your computer and use it in GitHub Desktop.
Save b00gizm/415157 to your computer and use it in GitHub Desktop.
<?php
class sfPropelBuildTestSqlTask extends sfPropelBaseTask
{
protected function configure()
{
$this->addOptions(array(
new sfCommandOption('propel-ini', null, sfCommandOption::PARAMETER_OPTIONAL, 'The path to dedicated propel.ini', sfConfig::get('sf_test_dir').'/bootstrap/propel/propel.ini'),
new sfCommandOption('phing-arg', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'Arbitrary phing argument'),
));
$this->namespace = 'propel';
$this->name = 'build-test-sql';
$this->briefDescription = 'Creates SQL for the current model to be used for testing';
$this->detailedDescription = <<<EOF
The [propel:build-test-sql|INFO] task creates SQL statements for testing table creation:
[./symfony propel:build-test-sql|INFO]
The generated SQL is optimized for the database configured in the dedicated [propel.ini|COMMENT]:
[propel.database = sqlite|INFO]
EOF;
}
protected function execute($arguments = array(), $options = array())
{
if (($pos = strrpos($options['propel-ini'], DIRECTORY_SEPARATOR)) === false)
{
$this->logSection('propel', sprintf("Invalid path to propel.ini: '%s'", $options['propel-ini']));
$this->logSection('propel', 'Task abborted');
return 1;
}
$iniDir = substr($options['propel-ini'], 0, $pos);
$iniName = substr($options['propel-ini'], $pos+1);
$properties = array(
'build.properties' => $iniName,
'project.dir' => $iniDir,
);
$this->schemaToXML(self::DO_NOT_CHECK_SCHEMA, 'generated-');
$this->copyXmlSchemaFromPlugins('generated-');
$ret = $this->callPhing('sql', self::CHECK_SCHEMA, $properties);
$this->cleanup();
return !$ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment