Source for file changeset.php
Documentation is available at changeset.php
* @package Joomla.Libraries
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
jimport('joomla.filesystem.folder');
* Contains a set of JSchemaChange objects for a particular instance of Joomla.
* Each of these objects contains a DDL query that should have been run against
* the database when this database was created or updated. This enables the
* Installation Manager to check that the current database schema is up to date.
* @package Joomla.Libraries
* Array of JSchemaChangeitem objects
* Folder where SQL update files will be found
* Constructor: builds array of $changeItems by processing the .sql files in a folder.
* The folder for the Joomla core updates is administrator/components/com_admin/sql/updates/<database>.
* @param JDatabaseDriver $db The current database object
* @param string $folder The full path to the folder containing the update queries
$updateFiles =
$this->getUpdateFiles();
$updateQueries =
$this->getUpdateQueries($updateFiles);
foreach ($updateQueries as $obj)
* Returns a reference to the JSchemaChangeset object, only creating it if it doesn't already exist.
* @param JDatabaseDriver $db The current database object
* @param string $folder The full path to the folder containing the update queries
* @return JSchemaChangeset
* Checks the database and returns an array of any errors found.
* Note these are not database errors but rather situations where
* the current schema is not up to date.
* @return array Array of errors if any.
if ($item->check() === -
2)
* Runs the update query to apply the change to the database
* Returns an array of results for this set
* @return array associative array of changeitems grouped by unchecked, ok, error, and skipped
$result =
array('unchecked' =>
array(), 'ok' =>
array(), 'error' =>
array(), 'skipped' =>
array());
switch ($item->checkStatus)
$result['unchecked'][] =
$item;
$result['error'][] =
$item;
$result['skipped'][] =
$item;
* Gets the current database schema, based on the highest version number.
* Note that the .sql files are named based on the version and date, so
* the file name of the last file should match the database schema version
* in the #__schemas table.
* @return string the schema version for the database
$updateFiles =
$this->getUpdateFiles();
$result =
new SplFileInfo(array_pop($updateFiles));
return $result->getBasename('.sql');
* Get list of SQL update files for this database
* @return array list of sql update full-path names
private function getUpdateFiles()
// Get the folder from the database name
$sqlFolder =
$this->db->name;
if ($sqlFolder ==
'mysqli')
elseif ($sqlFolder ==
'sqlsrv')
// Default folder to core com_admin
$this->folder .
'/' .
$sqlFolder, '\.sql$', 1, true, array('.svn', 'CVS', '.DS_Store', '__MACOSX'), array('^\..*', '.*~'), true
* Get array of SQL queries
* @param array $sqlfiles Array of .sql update filenames.
* @return array Array of stdClass objects where:
* update_query = text of SQL update query
private function getUpdateQueries(array $sqlfiles)
// Hold results as array of objects
foreach ($sqlfiles as $file)
// Create an array of queries from the sql file
foreach ($queries as $query)
if ($trimmedQuery =
$this->trimQuery($query))
$fileQueries =
new stdClass;
$fileQueries->file =
$file;
$fileQueries->updateQuery =
$trimmedQuery;
$result[] =
$fileQueries;
* Trim comment and blank lines out of a query string
* @param string $query query string to be trimmed
* @return string String with leading comment lines removed
private function trimQuery($query)
while (substr($query, 0, 1) ==
'#' ||
substr($query, 0, 2) ==
'--' ||
substr($query, 0, 2) ==
'/*')
$endChars =
(substr($query, 0, 1) ==
'#' ||
substr($query, 0, 2) ==
'--') ?
"\n" :
"*/";
if ($position =
strpos($query, $endChars))
// If no newline, the rest of the file is a comment, so return an empty string.
Documentation generated on Tue, 19 Nov 2013 14:55:39 +0100 by phpDocumentor 1.4.3