class DatabaseCommandController extends CommandController (View source)

Command controller for tasks related to database handling

Properties

protected Request $request from  CommandController
protected Response $response from  CommandController
protected Arguments $arguments from  CommandController
protected string $commandMethodName

Name of the command method

from  CommandController
protected ObjectManagerInterface $objectManager from  CommandController
protected CommandManager $commandManager from  CommandController
protected ConsoleOutput $output from  CommandController
protected array $persistenceSettings
protected Connection $connection

Methods

__construct()

Constructs the command controller

void
injectCommandManager(CommandManager $commandManager)

No description

void
injectObjectManager(ObjectManagerInterface $objectManager)

Injects the reflection service

void
processRequest(Request $request, Response $response)

Processes a command line request.

string
resolveCommandMethodName()

Resolves and checks the current command method name

void
initializeCommandMethodArguments()

Initializes the arguments array of this controller by creating an empty argument object for each of the method arguments found in the designated command method.

void
mapRequestArgumentsToControllerArguments()

Maps arguments delivered by the request object to the local controller arguments.

void
forward(string $commandName, string $controllerObjectName = null, array $arguments = [])

Forwards the request to another command and / or CommandController.

void
callCommandMethod()

Calls the specified command method and passes the arguments.

string
getFlowInvocationString()

Returns the CLI Flow command depending on the environment

void
output(string $text, array $arguments = [])

Outputs specified text to the console window You can specify arguments that will be passed to the text via sprintf

void
outputLine(string $text = '', array $arguments = [])

Outputs specified text to the console window and appends a line break

void
outputFormatted(string $text = '', array $arguments = [], int $leftPadding = 0)

Formats the given text to fit into MAXIMUM_LINE_LENGTH and outputs it to the console window

never
quit(int $exitCode = 0)

Exits the CLI through the dispatcher and makes sure that Flow is properly shut down.

never
sendAndExit(int $exitCode = 0)

Sends the response and exits the CLI without any further code execution Should be used for commands that flush code caches.

void
initializeConnection()

Create a Doctrine DBAL Connection with the configured settings.

setCharsetCommand(string $characterSet = 'utf8mb4', string $collation = 'utf8mb4_unicode_ci', string $output = null, bool $verbose = false)

Convert the database schema to use the given character set and collation (defaults to utf8mb4 and utf8mb4_unicode_ci).

convertToCharacterSetAndCollation(string $characterSet, string $collation, string $outputPathAndFilename = null, bool $verbose = false)

Convert the tables in the current database to use given character set and collation.

Details

__construct()

Constructs the command controller

void injectCommandManager(CommandManager $commandManager)

No description

Parameters

CommandManager $commandManager

Return Value

void

void injectObjectManager(ObjectManagerInterface $objectManager)

Injects the reflection service

Parameters

ObjectManagerInterface $objectManager

Return Value

void

void processRequest(Request $request, Response $response)

Processes a command line request.

Parameters

Request $request

The request object

Response $response

The response, modified by the controller

Return Value

void

Exceptions

InvalidArgumentTypeException
NoSuchCommandException

protected string resolveCommandMethodName()

Resolves and checks the current command method name

Note: The resulting command method name might not have the correct case, which isn't a problem because PHP is case insensitive regarding method names.

Return Value

string

Method name of the current command

Exceptions

NoSuchCommandException

protected void initializeCommandMethodArguments()

Initializes the arguments array of this controller by creating an empty argument object for each of the method arguments found in the designated command method.

Return Value

void

Exceptions

InvalidArgumentTypeException

protected void mapRequestArgumentsToControllerArguments()

Maps arguments delivered by the request object to the local controller arguments.

Return Value

void

protected void forward(string $commandName, string $controllerObjectName = null, array $arguments = [])

Forwards the request to another command and / or CommandController.

Request is directly transferred to the other command / controller without the need for a new request.

Parameters

string $commandName
string $controllerObjectName
array $arguments

Return Value

void

Exceptions

StopCommandException

protected void callCommandMethod()

Calls the specified command method and passes the arguments.

If the command returns a string, it is appended to the content in the response object. If the command doesn't return anything and a valid view exists, the view is rendered automatically.

Return Value

void

string getFlowInvocationString()

Returns the CLI Flow command depending on the environment

Return Value

string

protected void output(string $text, array $arguments = [])

Outputs specified text to the console window You can specify arguments that will be passed to the text via sprintf

Parameters

string $text

Text to output

array $arguments

Optional arguments to use for sprintf

Return Value

void

See also

http://www.php.net/sprintf

protected void outputLine(string $text = '', array $arguments = [])

Outputs specified text to the console window and appends a line break

Parameters

string $text

Text to output

array $arguments

Optional arguments to use for sprintf

Return Value

void

See also

output()
outputLines()

protected void outputFormatted(string $text = '', array $arguments = [], int $leftPadding = 0)

Formats the given text to fit into MAXIMUM_LINE_LENGTH and outputs it to the console window

Parameters

string $text

Text to output

array $arguments

Optional arguments to use for sprintf

int $leftPadding

The number of spaces to use for indentation

Return Value

void

See also

outputLine()

protected never quit(int $exitCode = 0)

Exits the CLI through the dispatcher and makes sure that Flow is properly shut down.

If your command relies on functionality which is triggered through the Bootstrap shutdown (such as the persistence framework), you must use quit() instead of exit().

Parameters

int $exitCode

Exit code to return on exit (see http://www.php.net/exit)

Return Value

never

Exceptions

StopCommandException

protected never sendAndExit(int $exitCode = 0)

Sends the response and exits the CLI without any further code execution Should be used for commands that flush code caches.

Parameters

int $exitCode

Exit code to return on exit

Return Value

never

protected void initializeConnection()

Create a Doctrine DBAL Connection with the configured settings.

Return Value

void

Exceptions

DBALException

setCharsetCommand(string $characterSet = 'utf8mb4', string $collation = 'utf8mb4_unicode_ci', string $output = null, bool $verbose = false)

Convert the database schema to use the given character set and collation (defaults to utf8mb4 and utf8mb4_unicode_ci).

This command can be used to convert the database configured in the Flow settings to the utf8mb4 character set and the utf8mb4_unicode_ci collation (by default, a custom collation can be given). It will only work when using the pdo_mysql driver.

Make a backup before using it, to be on the safe side. If you want to inspect the statements used for conversion, you can use the $output parameter to write them into a file. This file can be used to do the conversion manually.

For background information on this, see:

The main purpose of this is to fix setups that were created with Flow before version 5.0. In those cases, the tables will have a collation that does not match the default collation of later Flow versions, potentially leading to problems when creating foreign key constraints (among others, potentially).

If you have special needs regarding the charset and collation, you can override the defaults with different ones.

Note: This command is not a general purpose conversion tool. It will specifically not fix cases of actual utf8 stored in latin1 columns. For this a conversion to BLOB followed by a conversion to the proper type, charset and collation is needed instead.

Parameters

string $characterSet

Character set, defaults to utf8mb4

string $collation

Collation to use, defaults to utf8mb4_unicode_ci

string $output

A file to write SQL to, instead of executing it

bool $verbose

If set, the statements will be shown as they are executed

Exceptions

ConnectionException
DBALException
StopActionException

protected convertToCharacterSetAndCollation(string $characterSet, string $collation, string $outputPathAndFilename = null, bool $verbose = false)

Convert the tables in the current database to use given character set and collation.

Parameters

string $characterSet

Character set to convert to

string $collation

Collation to set, must be compatible with the character set

string $outputPathAndFilename
bool $verbose

Exceptions

ConnectionException
DBALException