class DataSourcesAdminController extends BaseAdminController

The DataSourcesAdminController class is the controller that handles all actions of the datasources management interface.

These actions are:

  • Creation of a data source
  • Modification of a data source
  • Deletion of a data source
  • Creation of a data source table
  • Modification of a data source table structure
  • Dropping a data source table
  • Adding a row in a data source table
  • Updating a row in a data source table
  • Deletion of a row in a data source table
  • Restoring a row in a data source table
  • Import / Export of a data source

Constants

SQL_SELECT_KEYWORD

SQL_FROM_KEYWORD

SQL_WHERE_KEYWORD

SQL_ORDER_BY_KEYWORD

SQL_LIMIT_KEYWORD

SQL_UPDATE_KEYWORD

SQL_CREATE_KEYWORD

SQL_DELETE_KEYWORD

Properties

ControllersHelper $helper from BaseAdminController
string $databasesDir from BaseAdminController
string $simulatorsDir from BaseAdminController
string $publicDir from BaseAdminController
string $viewsDir from BaseAdminController
private SimpleXMLElement $datasources
private Request $request
private int $script
private array $datatypes

Methods

Response
errorResponse(array $form, string $error)

Returns a JSON response formed with the data of a form and an error message.

zip(array $contents)

Zip file creation function.

int
unix2DosTime(int $unixtime)

Converts unix time to MS DOS time

Response|RedirectResponse
indexAction(Request $request, int|null $dsid = null, string|null $table = null, string|null $crud = null)

Entry point for the route paths begining by /admin/datasources

Response|RedirectResponse
runIndex(Request $request, int|null $dsid, string|null $table, string|null $crud)

Processes the index action

Response|RedirectResponse
dispatch(Request $request, int|null $dsid, string|null $table, string|null $crud, array $form)

Dispatches the index action to the appropriate processing based on the value of the crud parameter.

Response
showDatasources(int|null $dsid, string|null $table = null, string $action = 'show')

Shows the data sources management interface.

Response
doExportDatasource(int $dsid)

Exports a data source

RedirectResponse
doImportDatasource(array $files)

Imports a data source from a JSON data file and a JSON schema file

RedirectResponse|mixed
doImportTable(array $form, int $dsid, string|null $table, Database $database, array $files)

Imports a delimited text file into a table of a data source

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|null
processSource(SimpleXMLElement $source)

Executes the query from a source

array|null
filterResult(array $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

getDatabase(int $dsid, bool $withDbName = true)

Constructs a Database object

string|bool
checkValue(string $name, array $info, string|null $value)

Checks the value of a column

array|null
tablesList(Database $database)

Returns the list of tables of a database

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

Returns informations about a table of a database

array
infosColumns(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

RedirectResponse
createDatasource(array $form)

Creates a data source

string|true
migrateDB(int $dsid, string $dbtype, Database $fromDatabase)

Migrates data from a database to another.

string|true
createDB(int $dsid, string $dbtype)

Creates a database

string|true
createDBTable(array $form, Database $database)

Creates a table

string|true
editDBTable(array $form, string $table, Database $database)

Edits a table structure

bool
alterSQLiteTable(string $table, string $alterdefs, Database $database)

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

string|bool
addDBTableRow(array $form, string $table, Database $database, bool $restore = false)

Inserts a row into a table

bool
updateDBTableRow(array $form, string $table, Database $database)

Updates a table row

string|true
deleteDBTableRow(array $form, string $table, Database $database)

Deletes a row from a table

string|true
dropDBTable(string $table, Database $database)

Drops a table

RedirectResponse
createTable(array $form, Database $database)

Creates a table

void
saveDatasources(DOMDocument $dom)

Saves DataSources.xml from a DOM document

Response
addTableRow(array $form, string $table, Database $database)

Adds a table row

Response
restoreTableRow(array $form, string $table, Database $database)

Restores a table row

Response
updateTableRow(array $form, string $table, Database $database)

Updates a table row

Response
deleteTableRow(array $form, string $table, Database $database)

Deletes a table row

RedirectResponse
doEditTable(array $form, string $table, Database $database)

Edits a table structure

void
addColumnsToTable(DOMDocument $dom, array $form, DOMElement $table)

Adds columns to a table

RedirectResponse
dropTable(string $table, Database $database)

Drops a table

RedirectResponse
doEditDatasource(int $dsid, array $form)

Edits a data source

RedirectResponse
dropDatasource(int $dsid)

Drops a data source

Details

in BaseAdminController at line 93
protected Response errorResponse(array $form, string $error)

Returns a JSON response formed with the data of a form and an error message.

Parameters

array $form The form fields
string $error The error message

Return Value

Response

in BaseAdminController at line 113
protected zip(array $contents)

Zip file creation function.

Makes zip files. Derivated from PhpMyAdmin package The $contents parameter is an array of associative array where keys are : - name: name of the zip - modtime: modification time - data: data to compress

Parameters

array $contents The array of contents to be compressed

See also

Official ZIP file format: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

in BaseAdminController at line 188
protected int unix2DosTime(int $unixtime)

Converts unix time to MS DOS time

Parameters

int $unixtime (default: 0) The unix time

Return Value

int The MS DOS time

at line 259
Response|RedirectResponse indexAction(Request $request, int|null $dsid = null, string|null $table = null, string|null $crud = null)

Entry point for the route paths begining by /admin/datasources

These route paths are :

  • /admin/datasources
  • /admin/datasources/{dsid}
  • /admin/datasources/{dsid}/{table}
  • /admin/datasources/{dsid}/{table}/{crud}

Parameters

Request $request The request
int|null $dsid (default: null) The datasource ID
string|null $table (default: null) The table name
string|null $crud (default: null) operation to execute on the data source (create-datasource, import-datasource, doimport-datasource, export-datasource, edit-datasource, doedit-datasource, drop-datasource, edit, import, add, update, delete, create, doedit, doimport, drop, restore)

Return Value

Response|RedirectResponse

at line 277
protected Response|RedirectResponse runIndex(Request $request, int|null $dsid, string|null $table, string|null $crud)

Processes the index action

Parameters

Request $request The request
int|null $dsid The datasource ID
string|null $table The table name
string|null $crud (default: null) operation to execute on the data source (create-datasource, import-datasource, doimport-datasource, export-datasource, edit-datasource, doedit-datasource, drop-datasource, edit, import, add, update, delete, create, doedit, doimport, drop, restore)

Return Value

Response|RedirectResponse

at line 310
protected Response|RedirectResponse dispatch(Request $request, int|null $dsid, string|null $table, string|null $crud, array $form)

Dispatches the index action to the appropriate processing based on the value of the crud parameter.

Parameters

Request $request The request
int|null $dsid The datasource ID
string|null $table The table name
string|null $crud (default: null) operation to execute on the data source (create-datasource, import-datasource, doimport-datasource, export-datasource, edit-datasource, doedit-datasource, drop-datasource, edit, import, add, update, delete, create, doedit, doimport, drop, restore)
array $form The form fields

Return Value

Response|RedirectResponse

at line 364
protected Response showDatasources(int|null $dsid, string|null $table = null, string $action = 'show')

Shows the data sources management interface.

Parameters

int|null $dsid The datasource ID
string|null $table (default: null) The table name
string $action (default: 'show')

Return Value

Response

at line 643
protected Response doExportDatasource(int $dsid)

Exports a data source

Route path : /admin/datasources/{dsid}/dummy/export-datasource

Creates a JSON data file and a JSON schema file from the source database. Compresses these two files into one for its download.

Parameters

int $dsid The datasource ID

Return Value

Response

at line 700
protected RedirectResponse doImportDatasource(array $files)

Imports a data source from a JSON data file and a JSON schema file

These files must have been exported from a G6K instance and must conform to the jsonschema.org specification.

Route path : /admin/datasources/0/dummy/doimport-datasource

Parameters

array $files JSON data file and a JSON schema file

Return Value

RedirectResponse

at line 768
protected RedirectResponse|mixed doImportTable(array $form, int $dsid, string|null $table, Database $database, array $files)

Imports a delimited text file into a table of a data source

Route path : /admin/datasources/{dsid}/{table}/doimport

Parameters

array $form The form fields
int $dsid The datasource ID
string|null $table The table name
Database $database The database object
array $files The delimited text file

Return Value

RedirectResponse|mixed

Exceptions

Exception

at line 826
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

at line 887
protected array|null processSource(SimpleXMLElement $source)

Executes the query from a source

Parameters

SimpleXMLElement $source The source definition extracted from DataSources.xml

Return Value

array|null The result set of the query

at line 948
protected array|null filterResult(array $result, SimpleXMLElement $source)

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

Parameters

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

Return Value

array|null The filtered result set

at line 973
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

at line 1009
protected Database getDatabase(int $dsid, bool $withDbName = true)

Constructs a Database object

Parameters

int $dsid The datasource 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

at line 1030
protected string|bool checkValue(string $name, array $info, string|null $value)

Checks the value of a column

Parameters

string $name The column name
array $info Informations about the column
string|null $value The value to check

Return Value

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

at line 1109
protected array|null tablesList(Database $database)

Returns the list of tables of a database

Parameters

Database $database The Database object

Return Value

array|null The list of tables

at line 1147
protected array|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|null Informations about a table

at line 1196
protected array infosColumns(Database $database, string $table)

Returns informations about the columns of a table

Parameters

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

Return Value

array Informations about the columns

at line 1253
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

at line 1283
protected RedirectResponse createDatasource(array $form)

Creates a data source

Parameters

array $form The form fields

Return Value

RedirectResponse

at line 1307
protected string|true migrateDB(int $dsid, string $dbtype, Database $fromDatabase)

Migrates data from a database to another.

Parameters

int $dsid The datasource ID
string $dbtype The target database type
Database $fromDatabase The origin Database object

Return Value

string|true

at line 1360
protected string|true createDB(int $dsid, string $dbtype)

Creates a database

Parameters

int $dsid The datasource ID
string $dbtype The target database type

Return Value

string|true

at line 1405
protected string|true createDBTable(array $form, Database $database)

Creates a table

Parameters

array $form The form fields
Database $database The Database object

Return Value

string|true

at line 1480
protected string|true editDBTable(array $form, string $table, Database $database)

Edits a table structure

Parameters

array $form The form fields
string $table The table name
Database $database The Database object

Return Value

string|true

at line 1667
protected bool alterSQLiteTable(string $table, string $alterdefs, Database $database)

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

Return Value

bool Always true

at line 1786
protected string|bool addDBTableRow(array $form, string $table, Database $database, bool $restore = false)

Inserts a row into a table

Parameters

array $form The form fields
string $table The table name
Database $database The Database object
bool $restore (default: false) true if the row is to be restored, false otherwise

Return Value

string|bool

at line 1829
protected bool updateDBTableRow(array $form, string $table, Database $database)

Updates a table row

Parameters

array $form The form fields
string $table The table name
Database $database The Database object

Return Value

bool

at line 1871
protected string|true deleteDBTableRow(array $form, string $table, Database $database)

Deletes a row from a table

Parameters

array $form The form fields
string $table The table name
Database $database The Database object

Return Value

string|true

at line 1889
protected string|true dropDBTable(string $table, Database $database)

Drops a table

Parameters

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

Return Value

string|true

at line 1909
protected RedirectResponse createTable(array $form, Database $database)

Creates a table

Route path : /admin/datasources/{dsid}/new/create

Parameters

array $form The form fields
Database $database The Database object

Return Value

RedirectResponse

at line 1946
protected void saveDatasources(DOMDocument $dom)

Saves DataSources.xml from a DOM document

Parameters

DOMDocument $dom The DOM document of DataSources.xml

Return Value

void

at line 1970
protected Response addTableRow(array $form, string $table, Database $database)

Adds a table row

Route path : /admin/datasources/{dsid}/{table}/add

Parameters

array $form The form fields
string $table The table name
Database $database The Database object

Return Value

Response

at line 1996
protected Response restoreTableRow(array $form, string $table, Database $database)

Restores a table row

Route path : /admin/datasources/{dsid}/{table}/restore

Parameters

array $form The form fields
string $table The table name
Database $database The Database object

Return Value

Response

at line 2018
protected Response updateTableRow(array $form, string $table, Database $database)

Updates a table row

Route path : /admin/datasources/{dsid}/{table}/update

Parameters

array $form The form fields
string $table The table name
Database $database The Database object

Return Value

Response

at line 2043
protected Response deleteTableRow(array $form, string $table, Database $database)

Deletes a table row

Route path : /admin/datasources/{dsid}/{table}/delete

Parameters

array $form The form fields
string $table The table name
Database $database The Database object

Return Value

Response

at line 2068
protected RedirectResponse doEditTable(array $form, string $table, Database $database)

Edits a table structure

Route path : /admin/datasources/{dsid}/{table}/doedit

Parameters

array $form The form fields
string $table The table name
Database $database The Database object

Return Value

RedirectResponse

at line 2123
protected void addColumnsToTable(DOMDocument $dom, array $form, DOMElement $table)

Adds columns to a table

Parameters

DOMDocument $dom The DOM document of DataSources.xml
array $form The form fields
DOMElement $table &$table The table element in DataSources.xml

Return Value

void

at line 2186
protected RedirectResponse dropTable(string $table, Database $database)

Drops a table

Route path : /admin/datasources/{dsid}/{table}/drop

Parameters

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

Return Value

RedirectResponse

at line 2217
protected RedirectResponse doEditDatasource(int $dsid, array $form)

Edits a data source

Route path : /admin/datasources/{dsid}/dummy/doedit-datasource

Parameters

int $dsid The datasource ID
array $form The form fields

Return Value

RedirectResponse

at line 2346
protected RedirectResponse dropDatasource(int $dsid)

Drops a data source

Route path : /admin/datasources/{dsid}/dummy/drop-datasource

Parameters

int $dsid The datasource ID

Return Value

RedirectResponse