Вход Регистрация
Файл: concrete5.7.5.6/concrete/src/Database/Schema/Schema.php
Строк: 93
<?php
namespace ConcreteCoreDatabaseSchema;

class 
Schema
{

    public static function 
loadFromXMLFile($file, ConcreteCoreDatabaseConnectionConnection $connection)
    {
        
$sx = simplexml_load_file($file);
        return static::
loadFromXMLElement($sx, $connection);
    }

    public static function 
loadFromXMLElement(
        
SimpleXMLElement $sx,
        
ConcreteCoreDatabaseConnectionConnection $connection
    
) {
        
$parser = static::getSchemaParser($sx);
        return 
$parser->parse($connection);
    }

    public static function 
loadFromArray($array, ConcreteCoreDatabaseConnectionConnection $connection)
    {
        
$parser = new ConcreteCoreDatabaseSchemaParserArrayParser();
        return 
$parser->parse($array, $connection);
    }

    public static function 
getSchemaParser(SimpleXMLElement $sx)
    {
        
$sx->registerXPathNamespace('dx0.5', 'http://www.concrete5.org/doctrine-xml/0.5');
        if (
$sx->xpath('/dx0.5:schema')) {
            
$parser = new ConcreteCoreDatabaseSchemaParserDoctrineXml05($sx);
        } else {
            switch (
$sx['version']) {
                case 
'0.3':
                    
$parser = new ConcreteCoreDatabaseSchemaParserAxmls($sx);
                    break;
                default:
                    throw new 
Exception(t('Invalid schema version found. Expecting 0.3'));
            }
        }
        return 
$parser;
    }

    public static function 
refreshCoreXMLSchema($tables)
    {

        
$xml = simplexml_load_file(DIR_BASE_CORE . '/config/db.xml');
        
$output = new SimpleXMLElement('<schema xmlns="http://www.concrete5.org/doctrine-xml/0.5" />');
        
$th = Core::make('helper/text');
        foreach(
$xml->table as $t) {
            
$name = (string) $t['name'];
            if (
in_array($name, $tables)) {
                
$th->appendXML($output, $t);
            }
        }

        
$db = Database::get();

        
$parser = static::getSchemaParser($output);
        
$parser->setIgnoreExistingTables(false);
        
$toSchema = $parser->parse($db);
        
$fromSchema = $db->getSchemaManager()->createSchema();
        
$comparator = new DoctrineDBALSchemaComparator();
        
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
        
$saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform());

        foreach(
$saveQueries as $query) {
            
$db->query($query);
        }
    }
}
Онлайн: 5
Реклама