PHP Class Neos\Flow\Persistence\Doctrine\Service

Mostra file Open project: neos/flow-development-collection Class Usage Examples

Public Properties

Property Type Description
$output array

Protected Properties

Property Type Description
$entityManager Doctrine\Common\Persistence\ObjectManager
$environment Neos\Flow\Utility\Environment
$packageManager Neos\Flow\Package\PackageManagerInterface
$settings array

Public Methods

Method Description
compileProxies ( ) : void Compiles the Doctrine proxy class code using the Doctrine ProxyFactory.
createSchema ( string $outputPathAndFilename = null ) : string Creates the needed DB schema using Doctrine's SchemaTool. If tables already exist, this will throw an exception.
executeMigration ( string $version, string $direction = 'up', string $outputPathAndFilename = null, boolean $dryRun = false ) : string 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.
executeMigrations ( string $version = null, string $outputPathAndFilename = null, boolean $dryRun = false, boolean $quiet = false ) : string Execute all new migrations, up to $version if given.
generateMigration ( boolean $diffAgainstCurrent = true, string $filterExpression = null ) : string Generates a new migration file and returns the path to it.
getDatabasePlatformName ( ) : string Get name of current database platform
getEntityStatus ( ) : array Returns information about which entities exist and possibly if their mapping information contains errors or not.
getForeignKeyHandlingSql ( Doctrine\DBAL\Schema\Schema $schema, Doctrine\DBAL\Platforms\AbstractPlatform $platform, array $tableNames, string $search, string $replace ) : array This serves a rather strange use case: renaming columns used in FK constraints.
getMigrationStatus ( boolean $showMigrations = false, boolean $showDescriptions = false ) : string Returns the current migration status formatted as plain text.
markAsMigrated ( string $version, boolean $markAsMigrated ) : void Add a migration version to the migrations table or remove it.
runDql ( string $dql, integer $hydrationMode = Doctrine\ORM\Query::HYDRATE_OBJECT, integer $firstResult = null, integer $maxResult = null ) : mixed Run DQL and return the result as-is.
updateSchema ( boolean $safeMode = true, string $outputPathAndFilename = null ) : string Updates the DB schema using Doctrine's SchemaTool. The $safeMode flag is passed to SchemaTool unchanged.
validateMapping ( ) : array Validates the metadata mapping for Doctrine, using the SchemaValidator of Doctrine.

Protected Methods

Method Description
buildCodeFromSql ( Configuration $configuration, array $sql ) : string Returns PHP code for a migration file that "executes" the given array of SQL statements.
getFormattedVersionAlias ( string $alias, Configuration $configuration ) : string Returns a formatted version string for the alias.
getMigrationConfiguration ( ) : Configuration Return the configuration needed for Migrations.
getMigrationDescription ( Version $version, DocCommentParser $parser ) : string Returns the description of a migration.
getPackageKeyFromMigrationVersion ( Version $version ) : string Tries to find out a package key which the Version belongs to. If no package could be found, an empty string is returned.
writeMigrationClassToFile ( Configuration $configuration, string $up, string $down ) : string

Private Methods

Method Description
resolveTableName ( string $name ) : string 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.

Method Details

buildCodeFromSql() protected method

Returns PHP code for a migration file that "executes" the given array of SQL statements.
protected buildCodeFromSql ( Configuration $configuration, array $sql ) : string
$configuration Doctrine\DBAL\Migrations\Configuration\Configuration
$sql array
return string

compileProxies() public method

Compiles the Doctrine proxy class code using the Doctrine ProxyFactory.
public compileProxies ( ) : void
return void

createSchema() public method

Creates the needed DB schema using Doctrine's SchemaTool. If tables already exist, this will throw an exception.
public createSchema ( string $outputPathAndFilename = null ) : string
$outputPathAndFilename string A file to write SQL to, instead of executing it
return string

executeMigration() public method

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.
public executeMigration ( string $version, string $direction = 'up', string $outputPathAndFilename = null, boolean $dryRun = false ) : string
$version string The version to migrate to
$direction string
$outputPathAndFilename string A file to write SQL to, instead of executing it
$dryRun boolean Whether to do a dry run or not
return string

executeMigrations() public method

If $outputPathAndFilename is given, the SQL statements will be written to the given file instead of executed.
public executeMigrations ( string $version = null, string $outputPathAndFilename = null, boolean $dryRun = false, boolean $quiet = false ) : string
$version string The version to migrate to
$outputPathAndFilename string A file to write SQL to, instead of executing it
$dryRun boolean Whether to do a dry run or not
$quiet boolean Whether to do a quiet run or not
return string

generateMigration() public method

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.
public generateMigration ( boolean $diffAgainstCurrent = true, string $filterExpression = null ) : string
$diffAgainstCurrent boolean
$filterExpression string
return string Path to the new file

getDatabasePlatformName() public method

Get name of current database platform
public getDatabasePlatformName ( ) : string
return string

getEntityStatus() public method

Returns information about which entities exist and possibly if their mapping information contains errors or not.
public getEntityStatus ( ) : array
return array

getForeignKeyHandlingSql() public static method

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); }
public static getForeignKeyHandlingSql ( Doctrine\DBAL\Schema\Schema $schema, Doctrine\DBAL\Platforms\AbstractPlatform $platform, array $tableNames, string $search, string $replace ) : array
$schema Doctrine\DBAL\Schema\Schema
$platform Doctrine\DBAL\Platforms\AbstractPlatform
$tableNames array
$search string
$replace string
return array

getFormattedVersionAlias() protected method

Returns a formatted version string for the alias.
protected getFormattedVersionAlias ( string $alias, Configuration $configuration ) : string
$alias string
$configuration Doctrine\DBAL\Migrations\Configuration\Configuration
return string

getMigrationConfiguration() protected method

Return the configuration needed for Migrations.
protected getMigrationConfiguration ( ) : Configuration
return Doctrine\DBAL\Migrations\Configuration\Configuration

getMigrationDescription() protected method

If available it is fetched from the getDescription() method, if that returns an empty value the class docblock is used instead.
protected getMigrationDescription ( Version $version, DocCommentParser $parser ) : string
$version Doctrine\DBAL\Migrations\Version
$parser Neos\Flow\Reflection\DocCommentParser
return string

getMigrationStatus() public method

Returns the current migration status formatted as plain text.
public getMigrationStatus ( boolean $showMigrations = false, boolean $showDescriptions = false ) : string
$showMigrations boolean
$showDescriptions boolean
return string

getPackageKeyFromMigrationVersion() protected method

Tries to find out a package key which the Version belongs to. If no package could be found, an empty string is returned.
protected getPackageKeyFromMigrationVersion ( Version $version ) : string
$version Doctrine\DBAL\Migrations\Version
return string

markAsMigrated() public method

This does not execute any migration code but simply records a version as migrated or not.
public markAsMigrated ( string $version, boolean $markAsMigrated ) : void
$version string The version to add or remove
$markAsMigrated boolean
return void

runDql() public method

Run DQL and return the result as-is.
public runDql ( string $dql, integer $hydrationMode = Doctrine\ORM\Query::HYDRATE_OBJECT, integer $firstResult = null, integer $maxResult = null ) : mixed
$dql string
$hydrationMode integer
$firstResult integer
$maxResult integer
return mixed

updateSchema() public method

Updates the DB schema using Doctrine's SchemaTool. The $safeMode flag is passed to SchemaTool unchanged.
public updateSchema ( boolean $safeMode = true, string $outputPathAndFilename = null ) : string
$safeMode boolean
$outputPathAndFilename string A file to write SQL to, instead of executing it
return string

validateMapping() public method

Validates the metadata mapping for Doctrine, using the SchemaValidator of Doctrine.
public validateMapping ( ) : array
return array

writeMigrationClassToFile() protected method

protected writeMigrationClassToFile ( Configuration $configuration, string $up, string $down ) : string
$configuration Doctrine\DBAL\Migrations\Configuration\Configuration
$up string
$down string
return string

Property Details

$entityManager protected_oe property

protected ObjectManager,Doctrine\Common\Persistence $entityManager
return Doctrine\Common\Persistence\ObjectManager

$environment protected_oe property

protected Environment,Neos\Flow\Utility $environment
return Neos\Flow\Utility\Environment

$output public_oe property

public array $output
return array

$packageManager protected_oe property

protected PackageManagerInterface,Neos\Flow\Package $packageManager
return Neos\Flow\Package\PackageManagerInterface

$settings protected_oe property

protected array $settings
return array