class ChangeItem

Each object represents one query, which is one line from a DDL SQL query.

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.

Properties

string $file Update file: full path file name where query was found
string $updateQuery Update query: query used to change the db schema (one line from the file)
string $checkQuery Check query: query used to check the db schema
string $checkQueryExpected Check query result: expected result of check query if database is up to date
JDatabaseDriver $db \JDatabaseDriver object
string $queryType Query type: To be used in building a language key for a message to tell user what was checked / changed Possible values: ADDTABLE, ADDCOLUMN, CHANGECOLUMNTYPE, ADD_INDEX
array $msgElements Array with values for use in a \JText::sprintf statment indicating what was checked
integer $checkStatus Checked status
int $rerunStatus Rerun status

Methods

__construct( JDatabaseDriver $db, string $file, string $query)

Constructor: builds check query and message from $updateQuery

static  ChangeItem
getInstance( JDatabaseDriver $db, string $file, string $query)

Returns a reference to the ChangeItem object.

boolean
check()

Runs the check query and checks that 1 row is returned If yes, return true, otherwise return false

void
fix()

Runs the update query to apply the change to the database

Details

__construct( JDatabaseDriver $db, string $file, string $query)

Constructor: builds check query and message from $updateQuery

Parameters

JDatabaseDriver $db Database connector object
string $file Full path name of the sql file
string $query Text of the sql query (one line of the file)

static ChangeItem getInstance( JDatabaseDriver $db, string $file, string $query)

Returns a reference to the ChangeItem object.

Parameters

JDatabaseDriver $db Database connector object
string $file Full path name of the sql file
string $query Text of the sql query (one line of the file)

Return Value

ChangeItem instance based on the database driver

Exceptions

RuntimeException if class for database driver not found

boolean check()

Runs the check query and checks that 1 row is returned If yes, return true, otherwise return false

Return Value

boolean true on success, false otherwise

void fix()

Runs the update query to apply the change to the database

Return Value

void