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());
    }
}
 /**
  * Update plugin schema
  *
  * @param string $schema_path 
  * @param sfPropelDatabaseSchema $dbSchema 
  * @param string $prefix 
  * @author Sergey Startsev
  */
 private function updatePluginSchema($schema_path, sfPropelDatabaseSchema $dbSchema, $prefix = '')
 {
     $schema_structure_updated = $schema_structure = $this->getSchemaStructure($schema_path);
     $current_schema = $dbSchema->asArray();
     foreach ($schema_structure as $connection => $tables) {
         foreach ($tables as $table_name => $table_structure) {
             if (isset($current_schema[$connection]) && in_array($table_name, $current_schema[$connection])) {
                 $schema_structure_updated[$connection][$table_name] = $table_description;
             }
         }
     }
     if (!empty($prefix)) {
         $schema_path = dirname($schema_path) . "/{$prefix}schema.yml";
     }
     $oSchema = new sfPropelDatabaseSchema();
     $oSchema->loadArray($schema_structure_updated);
     $this->logSection('schema', sprintf('putting %s', $schema_path));
     file_put_contents($schema_path, $oSchema->asYAML());
 }