Service
class Service (View source)
Service class for tasks related to Doctrine
Constants
DOCTRINE_MIGRATIONSTABLENAME |
|
Properties
array | $output | ||
protected EntityManagerInterface | $entityManager | ||
protected PackageManager | $packageManager | ||
protected Environment | $environment |
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 the current migration status as an array.
Returns a formatted string of current database migration status.
Tries to find out a package key which the Version belongs to. If no package could be found, an empty string is returned.
Returns a formatted version string for the alias.
Returns the description of a migration.
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.
Generates a new migration file and returns the path to it.
No description
Returns PHP code for a migration file that "executes" the given array of SQL statements.
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.
string
createSchema(string $outputPathAndFilename = null)
Creates the needed DB schema using Doctrine's SchemaTool. If tables already exist, this will throw an exception.
string
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 Configuration
getMigrationConfiguration()
Return the configuration needed for Migrations.
array
getMigrationStatus()
Returns the current migration status as an array.
string
getFormattedMigrationStatus(bool $showMigrations = false, bool $showDescriptions = false)
Returns a formatted string of current database migration status.
protected string
getPackageKeyFromMigrationVersion(Version $version)
Tries to find out a package key which the Version belongs to. If no package could be found, an empty string is returned.
protected string
getFormattedVersionAlias(string $alias, Configuration $configuration)
Returns a formatted version string for the alias.
protected string
getMigrationDescription(Version $version, DocCommentParser $parser)
Returns the description of a migration.
If available it is fetched from the getDescription() method, if that returns an empty value the class docblock is used instead.
string
executeMigrations(string $version = null, 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
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.
protected string
writeMigrationClassToFile(Configuration $configuration, string|null $up, string|null $down)
No description
protected string
buildCodeFromSql(Configuration $configuration, array $sql)
Returns PHP code for a migration file that "executes" the given array of SQL statements.
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); }