Service
class Service (View source)
Service class for tasks related to Doctrine
Constants
DOCTRINE_MIGRATIONSTABLENAME |
|
DOCTRINE_MIGRATIONSNAMESPACE |
|
Properties
protected EntityManagerInterface | $entityManager | ||
protected PackageManager | $packageManager | ||
protected Environment | $environment | ||
protected BufferedOutput | $logMessages |
Methods
Validates the metadata mapping for Doctrine, using the SchemaValidator of Doctrine.
Creates the needed DB schema using Doctrine's SchemaTool. If tables already exist, this will throw an exception.
Updates the DB schema using Doctrine's SchemaTool. The $safeMode flag is passed to SchemaTool unchanged.
Compiles the Doctrine proxy class code using the Doctrine ProxyFactory.
Returns information about which entities exist and possibly if their mapping information contains errors or not.
Run DQL and return the result as-is.
Return the configuration needed for Migrations.
Returns a formatted string of current database migration status.
Execute all new migrations, up to $version if given.
Execute a single migration in up or down direction. If $path is given, the SQL statements will be written to the file in $path instead of executed.
Add a migration version to the migrations table or remove it.
Returns the current migration status as an array.
Generates a new migration file and returns the path to it.
Get name of current database platform
This serves a rather strange use case: renaming columns used in FK constraints.
Details
array
validateMapping()
Validates the metadata mapping for Doctrine, using the SchemaValidator of Doctrine.
void
createSchema(string $outputPathAndFilename = null)
Creates the needed DB schema using Doctrine's SchemaTool. If tables already exist, this will throw an exception.
void
updateSchema(bool $safeMode = true, string $outputPathAndFilename = null)
Updates the DB schema using Doctrine's SchemaTool. The $safeMode flag is passed to SchemaTool unchanged.
void
compileProxies()
Compiles the Doctrine proxy class code using the Doctrine ProxyFactory.
array
getEntityStatus()
Returns information about which entities exist and possibly if their mapping information contains errors or not.
mixed
runDql(string $dql, int $hydrationMode = \Doctrine\ORM\Query::HYDRATE_OBJECT, int $firstResult = null, int $maxResult = null)
Run DQL and return the result as-is.
protected DependencyFactory
getDependencyFactory()
Return the configuration needed for Migrations.
string
getFormattedMigrationStatus(bool $showMigrations = false)
Returns a formatted string of current database migration status.
string
executeMigrations(string $version = 'latest', string $outputPathAndFilename = null, bool $dryRun = false, bool $quiet = false)
Execute all new migrations, up to $version if given.
If $outputPathAndFilename is given, the SQL statements will be written to the given file instead of executed.
string
executeMigration(string $version, string $direction = 'up', string $outputPathAndFilename = null, bool $dryRun = false)
Execute a single migration in up or down direction. If $path is given, the SQL statements will be written to the file in $path instead of executed.
void
markAsMigrated(string $version, bool $markAsMigrated)
Add a migration version to the migrations table or remove it.
This does not execute any migration code but simply records a version as migrated or not.
array
getMigrationStatus()
Returns the current migration status as an array.
array
generateMigration(bool $diffAgainstCurrent = true, string $filterExpression = null)
Generates a new migration file and returns the path to it.
If $diffAgainstCurrent is true, it generates a migration file with the diff between current DB structure and the found mapping metadata.
Only include tables/sequences matching the $filterExpression regexp when diffing models and existing schema.
Otherwise an empty migration skeleton is generated.
string
getDatabasePlatformName()
Get name of current database platform
static array
getForeignKeyHandlingSql(Schema $schema, AbstractPlatform $platform, array $tableNames, string $search, string $replace)
This serves a rather strange use case: renaming columns used in FK constraints.
For a column that is used in a FK constraint to be renamed, the FK constraint has to be dropped first, then the column can be renamed and last the FK constraint needs to be added back (using the new name, of course).
This method helps with the task of handling the FK constraints during this. Given a list of tables that contain columns to be renamed and a search/replace pair for the column name, it will return an array with arrays with drop and add SQL statements.
Use them like this before and after renaming the affected fields:
// collect foreign keys pointing to "our" tables $tableNames = array(...); $foreignKeyHandlingSql = $this->getForeignKeyHandlingSql($schema, $tableNames, 'old_name', 'new_name');
// drop FK constraints foreach ($foreignKeyHandlingSql['drop'] as $sql) { $this->addSql($sql); }
// rename columns now
// add back FK constraints foreach ($foreignKeyHandlingSql['add'] as $sql) { $this->addSql($sql); }