protected function schemaToYML($checkSchema = self::CHECK_SCHEMA, $prefix = '', $verbose = false)
 {
     $finder = sfFinder::type('file')->name('*schema.xml')->prune('doctrine');
     $schemas = array_unique(array_merge($finder->in(sfConfig::get('sf_config_dir')), $finder->in($this->configuration->getPluginSubPaths('/config'))));
     if (self::CHECK_SCHEMA === $checkSchema && !count($schemas)) {
         throw new sfCommandException('You must create a schema.xml file.');
     }
     $dbSchema = new sfPropelDatabaseSchema();
     foreach ($schemas as $schema) {
         $dbSchema->loadXML($schema);
         if ($verbose) {
             $this->logSection('schema', sprintf('  converting "%s" to YML', $schema), null, 'COMMENT');
         }
         $localprefix = $prefix;
         // change prefix for plugins
         if (preg_match('#plugins[/\\\\]([^/\\\\]+)[/\\\\]#', $schema, $match)) {
             $localprefix = $prefix . $match[1] . '-';
         }
         // save converted xml files in original directories
         $yml_file_name = str_replace('.xml', '.yml', basename($schema));
         $file = str_replace(basename($schema), $prefix . $yml_file_name, $schema);
         if ($verbose) {
             $this->logSection('schema', sprintf('  putting %s', $file), null, 'COMMENT');
         }
         file_put_contents($file, $dbSchema->asYAML());
     }
 }
示例#2
0
function _propel_convert_xml_schema($check_schema = true, $prefix = '')
{
    $finder = pakeFinder::type('file')->name('*schema.xml');
    $schemas = array_merge($finder->in('config'), $finder->in(glob(sfConfig::get('sf_root_dir') . '/plugins/*/config')));
    if ($check_schema && !count($schemas)) {
        throw new Exception('You must create a schema.xml file.');
    }
    $db_schema = new sfPropelDatabaseSchema();
    foreach ($schemas as $schema) {
        $db_schema->loadXML($schema);
        $localprefix = $prefix;
        // change prefix for plugins
        if (preg_match('#plugins[/\\\\]([^/\\\\]+)[/\\\\]#', $schema, $match)) {
            $localprefix = $prefix . $match[1] . '-';
        }
        // save converted xml files in original directories
        $yml_file_name = str_replace('.xml', '.yml', basename($schema));
        $file = str_replace(basename($schema), $prefix . $yml_file_name, $schema);
        pake_echo_action('schema', 'putting ' . $file);
        file_put_contents($file, $db_schema->asYAML());
    }
}
$t = new my_lime_test(409);
$t->diag('Classical YAML to XML conversion');
$p = new sfPropelDatabaseSchema();
$p->loadYAML(dirname(__FILE__) . '/fixtures/schema.yml');
$target = file_get_contents(dirname(__FILE__) . '/fixtures/schema.xml');
$t->is_line_by_line($p->asXML(), $target);
$t->diag('New YAML to XML conversion');
$p = new sfPropelDatabaseSchema();
$p->loadYAML(dirname(__FILE__) . '/fixtures/new_schema.yml');
$target = file_get_contents(dirname(__FILE__) . '/fixtures/schema.xml');
$t->is_line_by_line($p->asXML(), $target);
$t->diag('New YAML to Old YAML conversion');
$old_yml_target = sfYaml::load(dirname(__FILE__) . '/fixtures/schema.yml');
$p = new sfPropelDatabaseSchema();
$new_yml_transformed = $p->convertNewToOldYaml(sfYaml::load(dirname(__FILE__) . '/fixtures/new_schema.yml'));
$t->is_array_explicit($new_yml_transformed, $old_yml_target);
$t->diag('Old YAML to New YAML conversion');
$new_yml_target = sfYaml::load(dirname(__FILE__) . '/fixtures/new_schema.yml');
$p = new sfPropelDatabaseSchema();
$old_yml_transformed = $p->convertOldToNewYaml(sfYaml::load(dirname(__FILE__) . '/fixtures/schema.yml'));
$t->is_array_explicit($old_yml_transformed, $new_yml_target);
$t->todo('XML and classical YAML internal representation');
$p1 = new sfPropelDatabaseSchema();
$p1->loadXML(dirname(__FILE__) . '/fixtures/schema.xml');
$p2 = new sfPropelDatabaseSchema();
$p2->loadYAML(dirname(__FILE__) . '/fixtures/schema.yml');
//$t->is_array_explicit($p1->asArray(), $p2->asArray());
$t->todo('XML and classical YAML compared as XML');
//$t->is_line_by_line($p1->asXML(), $p2->asXML());
$t->todo('XML and classical YAML compared as YAML');
//$t->is_line_by_line($p1->asYAML(), $p2->asYAML());