PostgresqlChangeItem
Extends \Joomla\CMS\Schema\ChangeItemChecks the database schema against one PostgreSQL DDL query to see if it has been run.
This class is used to check the site's database to see if the DDL query has been run.
If not, it provides the ability to fix the database by re-running the DDL query.
The queries are parsed from the update files in the folder
administrator/components/com_admin/sql/updates/<database>
.
These updates are run automatically if the site was updated using com_installer.
However, it is possible that the program files could be updated without udpating
the database (for example, if a user just copies the new files over the top of an
existing installation).
This is an abstract class. We need to extend it for each database and add a buildCheckQuery() method that creates the query to check that a DDL query has been run.
since |
3.0 |
---|
Methods
__construct
Constructor: builds check query and message from $updateQuery
__construct(\JDatabaseDriver $db, string $file, string $query)
since |
2.5 |
---|
Arguments
- $db
\JDatabaseDriver
Database connector object- $file
string
Full path name of the sql file- $query
string
Text of the sql query (one line of the file)
buildCheckQuery
Checks a DDL query to see if it is a known type If yes, build a check query to see if the DDL has been run on the database.
buildCheckQuery() : void
If successful, the $msgElements, $queryType, $checkStatus and $checkQuery fields are populated. The $msgElements contains the text to create the user message. The $checkQuery contains the SQL query to check whether the schema change has been run against the current database. The $queryType contains the type of DDL query that was run (for example, CREATE_TABLE, ADD_COLUMN, CHANGE_COLUMN_TYPE, ADD_INDEX). The $checkStatus field is set to zero if the query is created
If not successful, $checkQuery is empty and , and $checkStatus is -1. For example, this will happen if the current line is a non-DDL statement.
since |
2.5 |
---|
check
Runs the check query and checks that 1 row is returned If yes, return true, otherwise return false
check() : boolean
since |
2.5 |
---|
Response
boolean
true on success, false otherwise
fix
Runs the update query to apply the change to the database
fix() : void
since |
2.5 |
---|
fixInteger
Fix up integer. Fixes problem with PostgreSQL integer descriptions.
fixInteger(string $type1, string $type2) : string
If you change a column to "integer unsigned" it shows as "int(10) unsigned" in the check query.
since |
3.0 |
---|
Arguments
- $type1
string
the column type- $type2
string
the column attributes
Response
string
The original or changed column type.
fixQuote
Fixes up a string for inclusion in a query.
fixQuote(string $string) : string
Replaces name quote character with normal quote for literal. Drops trailing semicolon. Injects the database prefix.
since |
3.0 |
---|
Arguments
- $string
string
The input string to be cleaned up.
Response
string
The modified string.
getInstance
Returns a reference to the ChangeItem object.
getInstance(\JDatabaseDriver $db, string $file, string $query) : \Joomla\CMS\Schema\ChangeItem
since |
2.5 |
---|---|
throws |
|
Arguments
- $db
\JDatabaseDriver
Database connector object- $file
string
Full path name of the sql file- $query
string
Text of the sql query (one line of the file)
Response
\Joomla\CMS\Schema\ChangeItem
instance based on the database driver
Properties
file
Update file: full path file name where query was found
since |
2.5 |
---|
Type(s)
string
updateQuery
Update query: query used to change the db schema (one line from the file)
since |
2.5 |
---|
Type(s)
string
checkQuery
Check query: query used to check the db schema
since |
2.5 |
---|
Type(s)
string
checkQueryExpected
Check query result: expected result of check query if database is up to date
since |
2.5 |
---|
Type(s)
string
queryType
Query type: To be used in building a language key for a message to tell user what was checked / changed Possible values: ADD_TABLE, ADD_COLUMN, CHANGE_COLUMN_TYPE, ADD_INDEX
since |
2.5 |
---|
Type(s)
string
msgElements
Array with values for use in a \JText::sprintf statment indicating what was checked
Tells you what the message should be, based on which elements are defined, as follows: For ADD_TABLE: table For ADD_COLUMN: table, column For CHANGE_COLUMN_TYPE: table, column, type For ADD_INDEX: table, index
since |
2.5 |
---|
Type(s)
array
checkStatus
Checked status
since |
2.5 |
---|
Type(s)
integer
rerunStatus
Rerun status
since |
2.5 |
---|
Type(s)
integer