Development

ClayToSchema: sfPakeTransform.php

You must first sign up to be able to contribute.

ClayToSchema: sfPakeTransform.php

File sfPakeTransform.php, 1.6 kB (added by mbertier, 12 years ago)

Pake task used to perform transformations on schema.xml

Line 
1 <?php
2 /**
3  * This task is used to apply XSL transformations to schema.xml
4  *
5  * It will look for transformations in <project_dir>/data/transform/*.xsl
6  * The schema.xml file will be backuped before transformation.
7  *
8  * @author  <trivoallan@clever-age.com>
9  *
10  * usage :
11  *   symfony transform-schema transformation
12  *
13  * installation :
14  *   Just drop it in SF_DATA_DIR/tasks/
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     // Check params
25     // -- missing params ?
26     if ( !count($args) ) {
27         throw new Exception( 'You must provide a transformation to apply.' );
28     }
29
30     // -- tranformation exists ?
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     // -- schema exists ?
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     // Backup schema
43     pake_copy( $schema_filename, $schema_filename . '.previous', array('override' => true) );
44     
45     // Transform schema
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 ?>