| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
pake_desc( 'apply transformations to your data model' ); |
|---|
| 19 |
pake_task( 'transform-schema', 'project_exists' ); |
|---|
| 20 |
|
|---|
| 21 |
function run_transform_schema( $task, $args ) |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
// -- missing params ? |
|---|
| 26 |
if ( !count($args) ) { |
|---|
| 27 |
throw new Exception( 'You must provide a transformation to apply.' ); |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
$transformation_filename = sprintf( '%s/data/transform/%s.xsl', sfConfig::get('sf_root_dir'), $args[0] ); |
|---|
| 32 |
if ( !file_exists($transformation_filename) ) { |
|---|
| 33 |
throw new Exception( "This transformation doesn't exist." ); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
$schema_filename = sprintf( '%s/schema.xml', sfConfig::get('sf_config_dir') ); |
|---|
| 38 |
if ( !file_exists($schema_filename) ) { |
|---|
| 39 |
throw new Exception( "Missing schema.xml" ); |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
pake_copy( $schema_filename, $schema_filename . '.previous', array('override' => true) ); |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
$xslt = new xsltProcessor; |
|---|
| 47 |
$xslt->importStyleSheet( DomDocument::load($transformation_filename) ); |
|---|
| 48 |
$out = $xslt->transformToXML( DomDocument::loadXML(file_get_contents($schema_filename)) ); |
|---|
| 49 |
file_put_contents( $schema_filename, $out ); |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
?> |
|---|