Skip to content

Commit a4d0be1

Browse files
Merge pull request #2 from A5sys/evo-update-require
Evo update require
2 parents 5ad8e5d + 829c348 commit a4d0be1

File tree

2 files changed

+49
-31
lines changed

2 files changed

+49
-31
lines changed

Command/DiffFileCommand.php

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,67 @@ protected function saveCurrentSchema($configuration, $schema, $version)
121121
file_put_contents($filepath, serialize($schema));
122122
}
123123

124+
/**
125+
*
126+
* @return type
127+
*/
128+
protected function getSchemaProvider()
129+
{
130+
if (!$this->schemaProvider) {
131+
$this->schemaProvider = new OrmSchemaProvider($this->getHelper('entityManager')->getEntityManager());
132+
}
133+
134+
return $this->schemaProvider;
135+
}
136+
137+
/**
138+
* Resolve a table name from its fully qualified name. The `$name` argument
139+
* comes from Doctrine\DBAL\Schema\Table#getName which can sometimes return
140+
* a namespaced name with the form `{namespace}.{tableName}`. This extracts
141+
* the table name from that.
142+
*
143+
* @param string $name
144+
* @return string
145+
*/
146+
protected function resolveTableName($name)
147+
{
148+
$pos = strpos($name, '.');
149+
150+
return false === $pos ? $name : substr($name, $pos + 1);
151+
}
152+
124153
/**
125154
*
126155
* @param Configuration $configuration
127156
* @param array $sql
157+
* @param type $formatted
158+
* @param type $lineLength
128159
* @return type
160+
* @throws \InvalidArgumentException
129161
*/
130-
protected function buildCodeFromSql(Configuration $configuration, array $sql)
162+
private function buildCodeFromSql(Configuration $configuration, array $sql, $formatted = false, $lineLength = 120)
131163
{
132164
$currentPlatform = $configuration->getConnection()->getDatabasePlatform()->getName();
133165
$code = [];
134166
foreach ($sql as $query) {
135167
if (stripos($query, $configuration->getMigrationsTableName()) !== false) {
136168
continue;
137169
}
170+
171+
if ($formatted) {
172+
if (!class_exists('\SqlFormatter')) {
173+
throw new \InvalidArgumentException(
174+
'The "--formatted" option can only be used if the sql formatter is installed.'.'Please run "composer require jdorn/sql-formatter".'
175+
);
176+
}
177+
178+
$maxLength = $lineLength - 18 - 8; // max - php code length - indentation
179+
180+
if (strlen($query) > $maxLength) {
181+
$query = \SqlFormatter::format($query, false);
182+
}
183+
}
184+
138185
$code[] = sprintf("\$this->addSql(%s);", var_export($query, true));
139186
}
140187

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

153200
return implode("\n", $code);
154201
}
155-
156-
/**
157-
*
158-
* @return type
159-
*/
160-
protected function getSchemaProvider()
161-
{
162-
if (!$this->schemaProvider) {
163-
$this->schemaProvider = new OrmSchemaProvider($this->getHelper('entityManager')->getEntityManager());
164-
}
165-
166-
return $this->schemaProvider;
167-
}
168-
169-
/**
170-
* Resolve a table name from its fully qualified name. The `$name` argument
171-
* comes from Doctrine\DBAL\Schema\Table#getName which can sometimes return
172-
* a namespaced name with the form `{namespace}.{tableName}`. This extracts
173-
* the table name from that.
174-
*
175-
* @param string $name
176-
* @return string
177-
*/
178-
protected function resolveTableName($name)
179-
{
180-
$pos = strpos($name, '.');
181-
182-
return false === $pos ? $name : substr($name, $pos + 1);
183-
}
184202
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"php": ">=5.4.0",
1010
"symfony/framework-bundle": "~2.3|~3.0",
1111
"doctrine/doctrine-bundle": "~1.0",
12-
"doctrine/migrations": "~1.0"
12+
"doctrine/migrations": "~1.4"
1313
}
1414
}

0 commit comments

Comments
 (0)