class CopyDataSourceCommand extends CommandBase

Copies one or all data sources from another instance of G6K.

Only internal databases will be copied with this command.

Traits

This class implements common functions needed in G6KBundle controllers.

Properties

protected string $name from CommandBase
protected string $version from CommandBase
protected array|false $parameters from CommandBase
protected string $projectDir from CommandBase
protected string $publicDir from CommandBase
protected Translator $translator from CommandBase
protected bool $initialized from CommandBase
protected bool $html from CommandBase
protected array $datatypes from DatasourcesTrait
private int $maxDataSourceId
private int $maxDatabaseId

Methods

__construct(string $projectDir)

No description

void
doInitialization()

Realizes the initialization this command

array|false
getParameters()

This function parses the '.env' file and returns an array of parameters

string
getParameterValue(string $parameter)

Returns the value of a parameter

string
getConfigParameter(string $parameter)

Gets a parameter with its name.

void
configure()

Configures the current command.

void
initialize(InputInterface $input, OutputInterface $output)

initializes the current command.

void
askArgument(InputInterface $input, OutputInterface $output, string $argumentName, string $questionText)

Asks an argument if it's not supplied in the command line.

int|null
execute(InputInterface $input, OutputInterface $output)

No description

bool
runEmbeddedCommand(array $command, InputInterface $input, OutputInterface $output)

Run an embedded console command.

DOMElement|null
castDOMElement(DOMNode $node)

Casts a DOMNode to DOMElement

DOMElement|null
getDOMElementItem(DOMNodeList $nodes, int $index)

Retuns the DOMElement at position $index of the DOMNodeList

string
resolvePath(string $path, string $base)

Converts a relative path of a file to an absolute path

array
findFile(string $in, string $name, InputInterface $input, OutputInterface $output, array $filters = [])

Finds files in the subdirectories of a giving directory

string|int
findAssetsDirectory(string $in, InputInterface $input, OutputInterface $output)

Finds the assets directory

string|int
findTemplatesDirectory(string $in, InputInterface $input, OutputInterface $output)

Finds the templates directory

string|int
findPDFFormsDirectory(string $in, InputInterface $input, OutputInterface $output)

Finds the pdf forms directory

string|int
findSimulatorsDirectory(string $in, InputInterface $input, OutputInterface $output)

Finds the simulators directory

bool
isHtml()

Returns true, if the message are displayed in HTML, false if not.

void
message(OutputInterface $output, string $message, array $parameters = [], string $start = 'info', string $end = 'info', int $verbosity = OutputInterface::VERBOSITY_NORMAL)

Displays an message

void
info(OutputInterface $output, string $message, array $parameters = [])

Displays an info message

void
warning(OutputInterface $output, string $message, array $parameters = [])

Displays a warning message

void
success(OutputInterface $output, string $message, array $parameters = [])

Displays a success message

void
failure(OutputInterface $output, string $message, array $parameters = [])

Displays a failure message

void
fatal(OutputInterface $output, string $message, array $parameters = [])

Displays an fatal error message

void
error(OutputInterface $output, string $message, array $parameters = [])

Displays an error message

void
debug(OutputInterface $output, string $message, array $parameters = [])

Displays a debug message

void
comment(OutputInterface $output, string $message, array $parameters = [])

Displays a comment

string
getCommandName()

No description

string
getCommandDescription()

No description

string
getCommandHelp()

No description

array
getCommandArguments()

No description

array
getCommandOptions()

No description

getDatabase(int $dsid, SimpleXMLElement $datasources, string|null $databasesDir = null, bool $withDbName = true)

Constructs a Database object

array|string|bool|null
tablesList(Database $database)

Returns the list of tables of a database

array|string|bool|null
tableInfos(Database $database, string $table)

Returns informations about a table of a database

array
infosColumns(SimpleXMLElement $datasources, Database $database, string $table)

Returns informations about the columns of a table

array
infosColumnsToForm(string $table, array $infosColumns)

Constructs a form fields with informations about the columns of a table

array
getChoicesFromSource(SimpleXMLElement $source, array|null $result)

Retrieves the choice values of a data in the result list of a query on a data source

array|string|null
executeSource(SimpleXMLElement $source, SimpleXMLElement $datasources, string|null $databasesDir = null)

Executes the query from a source

array|null
filterResult(array|string $result, SimpleXMLElement $source)

Filters the result set of a query on the source return path

array
filterResultByLines(array $result, string $filter)

Filters the result set of a query on the source return path

string|bool
insertRowIntoTable(array $row, string $table, array $infosColumns, Database $database, TranslatorInterface $translator = null, bool $restore = false, bool $fromOtherTable = false)

Inserts a row into a table

bool|string
updateRowInTable(array $row, string $table, SimpleXMLElement $datasources, Database $database, TranslatorInterface $translator = null, bool $fromOtherTable = false)

Updates a table row

string|true
deleteRowFromTable(array $row, string $table, Database $database, TranslatorInterface $translator = null)

Deletes a row from a table

string|bool
checkColumnValue(array $info, string|null $value, TranslatorInterface $translator = null, bool $fromOtherTable = false)

Checks the value of a column

string|true
migrateDatabase(int $dsid, string $dbtype, SimpleXMLElement $datasources, SimpleXMLElement $fromDatasources, Database $fromDatabase, string|null $databasesDir = null, TranslatorInterface $translator = null, callable|null $fprogress = null)

Does the migration of data from a database to another.

string|true
createDatabase(int $dsid, string $dbtype, SimpleXMLElement $datasources, string|null $databasesDir = null, TranslatorInterface $translator = null)

Creates a database

string|true
createDatabaseTable(array $form, Database $database, TranslatorInterface $translator = null)

Creates a database table

string|true
dropDatabaseTable(string $table, Database $database, TranslatorInterface $translator = null)

Drops a table

string|true
editTableStructure(array $form, string $table, Database $database, SimpleXMLElement $datasources, TranslatorInterface $translator = null)

Edits a table structure

bool
alterSQLiteTable(string $table, string $alterdefs, Database $database, TranslatorInterface $translator = null)

Emulates a 'ALTER TABLE' for columns of a SQLite database.

void
interact(InputInterface $input, OutputInterface $output)

Checks the argument of the current command (g6k:datasource:copy).

false|true
copy(mixed $datasourcename, string $anotherg6kpath, DOMXPath $xpath1, mixed $databasesDir1, DOMXPath $xpath2, mixed $databasesDir2, OutputInterface $output)

function copy

Details

at line 61
__construct(string $projectDir)

Parameters

string $projectDir The project directory

in CommandBase at line 111
private void doInitialization()

Realizes the initialization this command

Return Value

void

in CommandBase at line 136
private array|false getParameters()

This function parses the '.env' file and returns an array of parameters

Return Value

array|false parameters array or false in case of error

in CommandBase at line 169
private string getParameterValue(string $parameter)

Returns the value of a parameter

Parameters

string $parameter The given parameter

Return Value

string The value of the parameter

in CommandBase at line 184
protected string getConfigParameter(string $parameter)

Gets a parameter with its name.

Parameters

string $parameter The parameter name

Return Value

string The parameter value

in CommandBase at line 194
protected void configure()

Configures the current command.

Return Value

void

in CommandBase at line 228
protected void initialize(InputInterface $input, OutputInterface $output)

initializes the current command.

Parameters

InputInterface $input The input interface
OutputInterface $output The output interface

Return Value

void

Exceptions

LogicException

in CommandBase at line 259
protected void askArgument(InputInterface $input, OutputInterface $output, string $argumentName, string $questionText)

Asks an argument if it's not supplied in the command line.

Parameters

InputInterface $input The input interface
OutputInterface $output The output interface
string $argumentName The argument name
string $questionText The question text

Return Value

void

at line 146
protected int|null execute(InputInterface $input, OutputInterface $output)

Parameters

InputInterface $input The input interface
OutputInterface $output The output interface

Return Value

int|null null or 0 if everything went fine, or an error code

in CommandBase at line 307
protected bool runEmbeddedCommand(array $command, InputInterface $input, OutputInterface $output)

Run an embedded console command.

Parameters

array $command The command
InputInterface $input The input interface
OutputInterface $output The output interface

Return Value

bool

in CommandBase at line 325
protected DOMElement|null castDOMElement(DOMNode $node)

Casts a DOMNode to DOMElement

Parameters

DOMNode $node The DOMNodeList

Return Value

DOMElement|null The DOMElement.

in CommandBase at line 341
protected DOMElement|null getDOMElementItem(DOMNodeList $nodes, int $index)

Retuns the DOMElement at position $index of the DOMNodeList

Parameters

DOMNodeList $nodes The DOMNodeList
int $index The position in the DOMNodeList

Return Value

DOMElement|null The DOMElement.

in CommandBase at line 357
protected string resolvePath(string $path, string $base)

Converts a relative path of a file to an absolute path

Parameters

string $path The relative path name of the file
string $base The base path

Return Value

string

in CommandBase at line 385
protected array findFile(string $in, string $name, InputInterface $input, OutputInterface $output, array $filters = [])

Finds files in the subdirectories of a giving directory

Parameters

string $in The start directory of the search
string $name The base name of the searched file
InputInterface $input The input interface
OutputInterface $output The output interface
array $filters Optional, filters to apply to the search

Return Value

array The full path of the files or an empty array if none has been found

in CommandBase at line 438
protected string|int findAssetsDirectory(string $in, InputInterface $input, OutputInterface $output)

Finds the assets directory

Parameters

string $in The start directory of the search
InputInterface $input The input interface
OutputInterface $output The output interface

Return Value

string|int The full path of the directory or an error code (1: not found, 2: multiple found)

in CommandBase at line 482
protected string|int findTemplatesDirectory(string $in, InputInterface $input, OutputInterface $output)

Finds the templates directory

Parameters

string $in The start directory of the search
InputInterface $input The input interface
OutputInterface $output The output interface

Return Value

string|int The full path of the directory or an error code (1: not found, 2: multiple found)

in CommandBase at line 526
protected string|int findPDFFormsDirectory(string $in, InputInterface $input, OutputInterface $output)

Finds the pdf forms directory

Parameters

string $in The start directory of the search
InputInterface $input The input interface
OutputInterface $output The output interface

Return Value

string|int The full path of the directory or an error code (1: not found, 2: multiple found)

in CommandBase at line 570
protected string|int findSimulatorsDirectory(string $in, InputInterface $input, OutputInterface $output)

Finds the simulators directory

Parameters

string $in The start directory of the search
InputInterface $input The input interface
OutputInterface $output The output interface

Return Value

string|int The full path of the directory or an error code (1: not found, 2: multiple found)

in CommandBase at line 611
protected bool isHtml()

Returns true, if the message are displayed in HTML, false if not.

Return Value

bool

in CommandBase at line 627
private void message(OutputInterface $output, string $message, array $parameters = [], string $start = 'info', string $end = 'info', int $verbosity = OutputInterface::VERBOSITY_NORMAL)

Displays an message

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters for translation
string $start The start tag
string $end The end tag
int $verbosity The verbosity option (default: OutputInterface::VERBOSITY_NORMAL), values : VERBOSITY_QUIET, VERBOSITY_NORMAL, VERBOSITY_VERBOSE, VERBOSITY_VERY_VERBOSE, VERBOSITY_DEBUG

Return Value

void

in CommandBase at line 647
protected void info(OutputInterface $output, string $message, array $parameters = [])

Displays an info message

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters

Return Value

void

in CommandBase at line 664
protected void warning(OutputInterface $output, string $message, array $parameters = [])

Displays a warning message

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters

Return Value

void

in CommandBase at line 681
protected void success(OutputInterface $output, string $message, array $parameters = [])

Displays a success message

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters

Return Value

void

in CommandBase at line 698
protected void failure(OutputInterface $output, string $message, array $parameters = [])

Displays a failure message

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters

Return Value

void

in CommandBase at line 715
protected void fatal(OutputInterface $output, string $message, array $parameters = [])

Displays an fatal error message

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters

Return Value

void

in CommandBase at line 732
protected void error(OutputInterface $output, string $message, array $parameters = [])

Displays an error message

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters

Return Value

void

in CommandBase at line 749
protected void debug(OutputInterface $output, string $message, array $parameters = [])

Displays a debug message

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters

Return Value

void

in CommandBase at line 762
protected void comment(OutputInterface $output, string $message, array $parameters = [])

Displays a comment

Parameters

OutputInterface $output The output interface
string $message The message to display
array $parameters Optional, message parameters

Return Value

void

at line 68
protected string getCommandName()

Return Value

string The name

at line 75
protected string getCommandDescription()

Return Value

string The description

at line 82
protected string getCommandHelp()

Return Value

string The help text

at line 100
protected array getCommandArguments()

Return Value

array The help text

at line 118
protected array getCommandOptions()

Return Value

array The help text

in DatasourcesTrait at line 192
protected Database getDatabase(int $dsid, SimpleXMLElement $datasources, string|null $databasesDir = null, bool $withDbName = true)

Constructs a Database object

Parameters

int $dsid The datasource ID
SimpleXMLElement $datasources DataSources.xml content
string|null $databasesDir The database directory ID
bool $withDbName (default: true) if false, the name of the database will not be inserted in the dsn string.

Return Value

Database The Database object

in DatasourcesTrait at line 211
protected array|string|bool|null tablesList(Database $database)

Returns the list of tables of a database

Parameters

Database $database The Database object

Return Value

array|string|bool|null The list of tables

in DatasourcesTrait at line 249
protected array|string|bool|null tableInfos(Database $database, string $table)

Returns informations about a table of a database

Parameters

Database $database The Database object
string $table The table name

Return Value

array|string|bool|null Informations about a table

in DatasourcesTrait at line 302
protected array infosColumns(SimpleXMLElement $datasources, Database $database, string $table)

Returns informations about the columns of a table

Parameters

SimpleXMLElement $datasources The DataSources.xml content
Database $database The Database object
string $table The table name

Return Value

array Informations about the columns

in DatasourcesTrait at line 361
protected array infosColumnsToForm(string $table, array $infosColumns)

Constructs a form fields with informations about the columns of a table

Parameters

string $table The table name
array $infosColumns Informations about the columns

Return Value

array

in DatasourcesTrait at line 398
protected array getChoicesFromSource(SimpleXMLElement $source, array|null $result)

Retrieves the choice values of a data in the result list of a query on a data source

Parameters

SimpleXMLElement $source The source definition extracted from DataSources.xml
array|null $result The result list of a query

Return Value

array The choices list

in DatasourcesTrait at line 461
protected array|string|null executeSource(SimpleXMLElement $source, SimpleXMLElement $datasources, string|null $databasesDir = null)

Executes the query from a source

Parameters

SimpleXMLElement $source The source definition extracted from DataSources.xml
SimpleXMLElement $datasources The DataSources.xml content
string|null $databasesDir The database directory

Return Value

array|string|null The result set of the query

in DatasourcesTrait at line 523
protected array|null filterResult(array|string $result, SimpleXMLElement $source)

Filters the result set of a query on the source return path

Parameters

array|string $result The result set of a query
SimpleXMLElement $source The source definition extracted from DataSources.xml

Return Value

array|null The filtered result set

in DatasourcesTrait at line 548
protected array filterResultByLines(array $result, string $filter)

Filters the result set of a query on the source return path

Parameters

array $result The result set of a query
string $filter The filter

Return Value

array The filtered result set

in DatasourcesTrait at line 589
protected string|bool insertRowIntoTable(array $row, string $table, array $infosColumns, Database $database, TranslatorInterface $translator = null, bool $restore = false, bool $fromOtherTable = false)

Inserts a row into a table

Parameters

array $row The row to insert
string $table The table name
array $infosColumns The informations about the columns
Database $database The Database object
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise
bool $restore (default: false) true if the row is to be restored, false otherwise
bool $fromOtherTable (default: false) true if the row comes from another table

Return Value

string|bool

in DatasourcesTrait at line 638
protected bool|string updateRowInTable(array $row, string $table, SimpleXMLElement $datasources, Database $database, TranslatorInterface $translator = null, bool $fromOtherTable = false)

Updates a table row

Parameters

array $row The row
string $table The table name
SimpleXMLElement $datasources The DataSources.xml content
Database $database The Database object
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise
bool $fromOtherTable (default: false) true if the row comes from another table

Return Value

bool|string

in DatasourcesTrait at line 685
protected string|true deleteRowFromTable(array $row, string $table, Database $database, TranslatorInterface $translator = null)

Deletes a row from a table

Parameters

array $row The row
string $table The table name
Database $database The Database object
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise

Return Value

string|true

in DatasourcesTrait at line 709
protected string|bool checkColumnValue(array $info, string|null $value, TranslatorInterface $translator = null, bool $fromOtherTable = false)

Checks the value of a column

Parameters

array $info Informations about the column
string|null $value The value to check
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise
bool $fromOtherTable (default: false) true if the row comes from another table

Return Value

string|bool An error message or true if no error.

in DatasourcesTrait at line 847
protected string|true migrateDatabase(int $dsid, string $dbtype, SimpleXMLElement $datasources, SimpleXMLElement $fromDatasources, Database $fromDatabase, string|null $databasesDir = null, TranslatorInterface $translator = null, callable|null $fprogress = null)

Does the migration of data from a database to another.

Parameters

int $dsid The datasource ID
string $dbtype The target database type
SimpleXMLElement $datasources The origin DataSources.xml content
SimpleXMLElement $fromDatasources The origin DataSources.xml content
Database $fromDatabase The origin Database object
string|null $databasesDir The database directory
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise
callable|null $fprogress a function receiving the row number that's inserted

Return Value

string|true

in DatasourcesTrait at line 895
protected string|true createDatabase(int $dsid, string $dbtype, SimpleXMLElement $datasources, string|null $databasesDir = null, TranslatorInterface $translator = null)

Creates a database

Parameters

int $dsid The datasource ID
string $dbtype The target database type
SimpleXMLElement $datasources The DataSources.xml content
string|null $databasesDir The database directory
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise

Return Value

string|true

in DatasourcesTrait at line 953
protected string|true createDatabaseTable(array $form, Database $database, TranslatorInterface $translator = null)

Creates a database table

Parameters

array $form The form fields
Database $database The Database object
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise

Return Value

string|true

in DatasourcesTrait at line 1032
protected string|true dropDatabaseTable(string $table, Database $database, TranslatorInterface $translator = null)

Drops a table

Parameters

string $table The table name
Database $database The Database object
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise

Return Value

string|true

in DatasourcesTrait at line 1057
protected string|true editTableStructure(array $form, string $table, Database $database, SimpleXMLElement $datasources, TranslatorInterface $translator = null)

Edits a table structure

Parameters

array $form The form fields
string $table The table name
Database $database The Database object
SimpleXMLElement $datasources The DataSources.xml content
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise

Return Value

string|true

in DatasourcesTrait at line 1277
protected bool alterSQLiteTable(string $table, string $alterdefs, Database $database, TranslatorInterface $translator = null)

Emulates a 'ALTER TABLE' for columns of a SQLite database.

ALTER TABLE tbl_name alter_specification [, alter_specification] ...

alter_specification: ADD column_definition | DROP column_definition | CHANGE old_col_name column_definition

column_definition: same as for create table statements

Parameters

string $table The table name
string $alterdefs Comma separated alter specifications
Database $database The Database object
TranslatorInterface $translator (default: null) true if the row is to be restored, false otherwise

Return Value

bool Always true

at line 137
protected void interact(InputInterface $input, OutputInterface $output)

Checks the argument of the current command (g6k:datasource:copy).

Parameters

InputInterface $input The input interface
OutputInterface $output The output interface

Return Value

void

at line 235
private false|true copy(mixed $datasourcename, string $anotherg6kpath, DOMXPath $xpath1, mixed $databasesDir1, DOMXPath $xpath2, mixed $databasesDir2, OutputInterface $output)

function copy

Parameters

mixed $datasourcename
string $anotherg6kpath
DOMXPath $xpath1
mixed $databasesDir1
DOMXPath $xpath2
mixed $databasesDir2
OutputInterface $output

Return Value

false|true