if (file_exists($applicationConfig)) { include $applicationConfig; } if ($hostConfig) { $hostConfigFile = APP_ROOT . DIRECTORY_SEPARATOR . 'cfg' . DIRECTORY_SEPARATOR . $hostConfig . DIRECTORY_SEPARATOR . 'config.php'; if (file_exists($hostConfigFile)) { include $hostConfigFile; } else { stop("`{$hostConfig}` host config does not exist"); } } if (!defined('APP_SLOT_CONFIGURATION')) { define('APP_SLOT_CONFIGURATION', SLOT_PRESET_PRODUCTION); } Autoloader::getInstance()->clearCache(); $domainBuilder = new XmlOrmDomainBuilder($xmlSchema); try { $ormDomain = $domainBuilder->build(); if ($code) { $generator = new OrmGenerator($autoDir, $publicDir); if ($regeneratePublic) { $generator->regeneratePublic(); } $generator->generate($ormDomain); } if ($schema) { if (!$db && $ormDomain->getDbSchema()) { $db = $ormDomain->getDbSchema(); } if ($db) { try {
if (!is_dir($dir)) { mkdir($dir, 0755, true); } if (!$db && $ormDomain->getDbSchema()) { $db = $ormDomain->getDbSchema(); } if ($db) { try { $dbObject = DBPool::get($db); } catch (ArgumentException $e) { stop("Unknown database reference: {$db}"); } } else { stop('You should specify db to use'); } message('Loading diff schema: ' . $diffDomainFile); $domainBuilder = new XmlOrmDomainBuilder($diffDomainFile); $diffOrmDomain = $domainBuilder->build(); message('Writing diff to ' . $diffSqlFile); $dbDiff = new DBDiff(); $schemaBuilderOld = new DBSchemaBuilder($diffOrmDomain); $schemaOld = $schemaBuilderOld->build(); $schemaBuilderNew = new DBSchemaBuilder($ormDomain); $schemaNew = $schemaBuilderNew->build(); $dbDiff->make($schemaOld, $schemaNew); file_put_contents($diffSqlFile, $dbDiff->toDialectString($dbObject->getDialect())); } } catch (OrmModelIntegrityException $e) { stop($e->getMessage()); } echo 'Done', PHP_EOL;