Skip to content

Commit

Permalink
Merge pull request #2 from A5sys/evo-update-require
Browse files Browse the repository at this point in the history
Evo update require
  • Loading branch information
thomasbeaujean committed May 2, 2016
2 parents 5ad8e5d + 829c348 commit a4d0be1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
78 changes: 48 additions & 30 deletions Command/DiffFileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,67 @@ protected function saveCurrentSchema($configuration, $schema, $version)
file_put_contents($filepath, serialize($schema));
}

/**
*
* @return type
*/
protected function getSchemaProvider()
{
if (!$this->schemaProvider) {
$this->schemaProvider = new OrmSchemaProvider($this->getHelper('entityManager')->getEntityManager());
}

return $this->schemaProvider;
}

/**
* Resolve a table name from its fully qualified name. The `$name` argument
* comes from Doctrine\DBAL\Schema\Table#getName which can sometimes return
* a namespaced name with the form `{namespace}.{tableName}`. This extracts
* the table name from that.
*
* @param string $name
* @return string
*/
protected function resolveTableName($name)
{
$pos = strpos($name, '.');

return false === $pos ? $name : substr($name, $pos + 1);
}

/**
*
* @param Configuration $configuration
* @param array $sql
* @param type $formatted
* @param type $lineLength
* @return type
* @throws \InvalidArgumentException
*/
protected function buildCodeFromSql(Configuration $configuration, array $sql)
private function buildCodeFromSql(Configuration $configuration, array $sql, $formatted = false, $lineLength = 120)
{
$currentPlatform = $configuration->getConnection()->getDatabasePlatform()->getName();
$code = [];
foreach ($sql as $query) {
if (stripos($query, $configuration->getMigrationsTableName()) !== false) {
continue;
}

if ($formatted) {
if (!class_exists('\SqlFormatter')) {
throw new \InvalidArgumentException(
'The "--formatted" option can only be used if the sql formatter is installed.'.'Please run "composer require jdorn/sql-formatter".'
);
}

$maxLength = $lineLength - 18 - 8; // max - php code length - indentation

if (strlen($query) > $maxLength) {
$query = \SqlFormatter::format($query, false);
}
}

$code[] = sprintf("\$this->addSql(%s);", var_export($query, true));
}

Expand All @@ -152,33 +199,4 @@ protected function buildCodeFromSql(Configuration $configuration, array $sql)

return implode("\n", $code);
}

/**
*
* @return type
*/
protected function getSchemaProvider()
{
if (!$this->schemaProvider) {
$this->schemaProvider = new OrmSchemaProvider($this->getHelper('entityManager')->getEntityManager());
}

return $this->schemaProvider;
}

/**
* Resolve a table name from its fully qualified name. The `$name` argument
* comes from Doctrine\DBAL\Schema\Table#getName which can sometimes return
* a namespaced name with the form `{namespace}.{tableName}`. This extracts
* the table name from that.
*
* @param string $name
* @return string
*/
protected function resolveTableName($name)
{
$pos = strpos($name, '.');

return false === $pos ? $name : substr($name, $pos + 1);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"php": ">=5.4.0",
"symfony/framework-bundle": "~2.3|~3.0",
"doctrine/doctrine-bundle": "~1.0",
"doctrine/migrations": "~1.0"
"doctrine/migrations": "~1.4"
}
}

0 comments on commit a4d0be1

Please sign in to comment.