AAAAPK ¥?\»ÿ'1y y changeitemmysql.phpnu W+A„¶ checkStatus = -1; // change status to skipped
$result = null;
// remove any newlines
$this->updateQuery = str_replace("\n", '', $this->updateQuery);
// fix up extra spaces around () and in general
$find = array('#((\s*)\(\s*([^)\s]+)\s*)(\))#', '#(\s)(\s*)#');
$replace = array('($3)', '$1');
$updateQuery = preg_replace($find, $replace, $this->updateQuery);
$wordArray = explode(' ', $updateQuery);
// first, make sure we have an array of at least 6 elements
// if not, we can't make a check query for this one
if (count($wordArray) < 6) {
return; // done with method
}
// we can only make check queries for alter table and create table queries
$command = strtoupper($wordArray[0] . ' ' . $wordArray[1]);
if ($command === 'ALTER TABLE') {
$alterCommand = strtoupper($wordArray[3] . ' ' . $wordArray[4]);
if ($alterCommand == 'ADD COLUMN') {
$result = 'SHOW COLUMNS IN ' . $wordArray[2] .
' WHERE field = ' . $this->fixQuote($wordArray[5]);
$this->queryType = 'ADD_COLUMN';
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]));
}
elseif ($alterCommand == 'ADD INDEX' || $alterCommand == 'ADD UNIQUE') {
if ($pos = strpos($wordArray[5], '(')) {
$index = $this->fixQuote(substr($wordArray[5], 0, $pos));
} else {
$index = $this->fixQuote($wordArray[5]);
}
$result = 'SHOW INDEXES IN ' . $wordArray[2] . ' WHERE Key_name = ' . $index;
$this->queryType = 'ADD_INDEX';
$this->msgElements = array($this->fixQuote($wordArray[2]), $index);
}
elseif ($alterCommand == 'DROP INDEX') {
$index = $this->fixQuote($wordArray[5]);
$result = 'SHOW INDEXES IN ' . $wordArray[2] . ' WHERE Key_name = ' . $index;
$this->queryType = 'DROP_INDEX';
$this->checkQueryExpected = 0;
$this->msgElements = array($this->fixQuote($wordArray[2]), $index);
}
elseif (strtoupper($wordArray[3]) == 'MODIFY') {
// Kludge to fix problem with "integer unsigned"
$type = $this->fixQuote($wordArray[5]);
if (isset($wordArray[6])) {
$type = $this->fixQuote($this->fixInteger($wordArray[5], $wordArray[6]));
}
$result = 'SHOW COLUMNS IN ' . $wordArray[2] . ' WHERE field = '
. $this->fixQuote($wordArray[4]) . ' AND type = ' . $type;
$this->queryType = 'CHANGE_COLUMN_TYPE';
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[4]), $type);
}
elseif (strtoupper($wordArray[3]) == 'CHANGE') {
// Kludge to fix problem with "integer unsigned"
$type = $this->fixQuote($this->fixInteger($wordArray[6], $wordArray[7]));
$result = 'SHOW COLUMNS IN ' . $wordArray[2] . ' WHERE field = ' .
$this->fixQuote($wordArray[4]) . ' AND type = ' . $type;
$this->queryType = 'CHANGE_COLUMN_TYPE';
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[4]), $type);
}
}
if ($command == 'CREATE TABLE') {
if (strtoupper($wordArray[2].$wordArray[3].$wordArray[4]) == 'IFNOTEXISTS') {
$table = $wordArray[5];
}
else {
$table = $wordArray[2];
}
$result = 'SHOW TABLES LIKE ' . $this->fixQuote($table);
$this->queryType = 'CREATE_TABLE';
$this->msgElements = array($this->fixQuote($table));
}
// set fields based on results
if ($this->checkQuery = $result) {
$this->checkStatus = 0; // unchecked status
}
else {
$this->checkStatus = -1; // skipped
}
}
/**
* Fix up integer. Fixes problem with MySQL integer descriptions.
* If you change a column to "integer unsigned" it shows
* as "int(10) unsigned" in the check query.
*
* @param string $type1 the column type
* @param string $type2 the column attributes
*
* @return string The original or changed column type.
*
* @since 2.5
*/
private function fixInteger($type1, $type2)
{
$result = $type1;
if (strtolower($type1) == "integer" && strtolower(substr($type2, 0, 8)) == 'unsigned') {
$result = 'int(10) unsigned';
}
return $result;
}
/**
*
* Fixes up a string for inclusion in a query.
* Replaces name quote character with normal quote for literal.
* Drops trailing semi-colon. Injects the database prefix.
*
* @param string $string The input string to be cleaned up.
* @return string The modified string.
*
* @since 2.5
*/
private function fixQuote($string)
{
$string = str_replace('`', '', $string);
$string = str_replace(';', '', $string);
$string = str_replace('#__', $this->db->getPrefix(), $string);
return $this->db->quote($string);
}
}
PK ¥?\®)ÕÐ .htaccessnu W+A„¶
Order allow,deny
Deny from all
PK ¥?\
óC6i i
changeset.phpnu W+A„¶ .
*
* @param JDatabase $db The current database object
* @param string $folder The full path to the folder containing the update queries
*
* @since 2.5
*/
public function __construct($db, $folder = null)
{
$this->db = $db;
$this->folder = $folder;
$updateFiles = $this->getUpdateFiles();
$updateQueries = $this->getUpdateQueries($updateFiles);
foreach ($updateQueries as $obj)
{
$this->changeItems[] = JSchemaChangeitem::getInstance($db, $obj->file, $obj->updateQuery);
}
}
/**
* Returns the existing JSchemaChangeset object if it exists.
* Otherwise, it creates a new one.
*
* @param JDatabase $db The current database object
* @param string $folder The full path to the folder containing the update queries
*
* @return JSchemaChangeSet The (possibly chached) instance of JSchemaChangeSet
*
* @since 2.5
*/
public static function getInstance($db, $folder)
{
static $instance;
if (!is_object($instance))
{
$instance = new JSchemaChangeSet($db, $folder);
}
return $instance;
}
/**
* 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.
*
* @since 2.5
*/
public function check()
{
$errors = array();
foreach ($this->changeItems as $item)
{
if ($item->check() === -2)
{
// Error found
$errors[] = $item;
}
}
return $errors;
}
/**
* Runs the update query to apply the change to the database
*
* @return void
*
* @since 2.5
*/
public function fix()
{
$this->check();
foreach ($this->changeItems as $item)
{
$item->fix();
}
}
/**
* Returns an array of results for this set
*
* @return array associative array of changeitems grouped by unchecked, ok, error, and skipped
*
* @since 2.5
*/
public function getStatus()
{
$result = array('unchecked' => array(), 'ok' => array(), 'error' => array(), 'skipped' => array());
foreach ($this->changeItems as $item)
{
switch ($item->checkStatus)
{
case 0:
$result['unchecked'][] = $item;
break;
case 1:
$result['ok'][] = $item;
break;
case -2:
$result['error'][] = $item;
break;
case -1:
$result['skipped'][] = $item;
break;
}
}
return $result;
}
/**
* 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
*
* @since 2.5
*/
public function getSchema()
{
$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
*
* @since 2.5
*/
private function getUpdateFiles()
{
// Get the folder from the database name
$sqlFolder = $this->db->name;
if (substr($sqlFolder, 0, 5) == 'mysql')
{
$sqlFolder = 'mysql';
}
// Default folder to core com_admin
if (!$this->folder)
{
$this->folder = JPATH_ADMINISTRATOR . '/components/com_admin/sql/updates/';
}
return JFolder::files($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:
* file=filename,
* update_query = text of SQL update query
*
* @since 2.5
*/
private function getUpdateQueries(array $sqlfiles)
{
// Hold results as array of objects
$result = array();
foreach ($sqlfiles as $file)
{
$buffer = file_get_contents($file);
// Create an array of queries from the sql file
$queries = $this->db->splitSql($buffer);
foreach ($queries as $query)
{
if (trim($query))
{
$fileQueries = new stdClass;
$fileQueries->file = $file;
$fileQueries->updateQuery = $query;
$result[] = $fileQueries;
}
}
}
return $result;
}
}
PK ¥?\Á¨±Ê changeitem.phpnu W+A„¶ .
* 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.
*
* @package CMS.Library
* @subpackage Schema
* @since 2.5
*/
abstract class JSchemaChangeitem extends JObject
{
/**
* Update file: full path file name where query was found
*
* @var string
*/
public $file = null;
/**
* Update query: query used to change the db schema (one line from the file)
*
* @var string
*/
public $updateQuery = null;
/**
* Check query: query used to check the db schema
*
* @var string
*/
public $checkQuery = null;
/**
* Check query result: expected result of check query if database is up to date
*
* @var string
*/
public $checkQueryExpected = 1;
/**
* JDatabase object
*
* @var string
*/
public $db = null;
/**
* 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
*
* @var string
*
*/
public $queryType = null;
/**
* 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
*
* @var array
*/
public $msgElements = array();
/**
* Checked status
*
* @var int 0=not checked, -1=skipped, -2=failed, 1=succeeded
*/
public $checkStatus = 0;
/**
* Rerun status
*
* @var int 0=not rerun, -1=skipped, -2=failed, 1=succeeded
*/
public $rerunStatus = 0;
/**
* Constructor: builds check query and message from $updateQuery
*
* @param JDatabase $db
* @param string $file full path name of the sql file
* @param string $query text of the sql query (one line of the file)
* @param string $checkQuery
*
* @since 2.5
*/
public function __construct($db, $file, $updateQuery)
{
$this->updateQuery = $updateQuery;
$this->file = $file;
$this->db = $db;
$this->buildCheckQuery();
}
/**
*
* Returns an instance of the correct schemachangeitem for the $db
*
* @param JDatabase $db
* @param string $file full path name of the sql file
* @param string $query text of the sql query (one line of the file)
*
* @return JSchemaChangeItem for the $db driver
*
* @since 2.5
*/
public static function getInstance($db, $file, $query)
{
$instance = null;
// Get the class name (mysql and mysqli both use mysql)
$dbname = (substr($db->name, 0, 5) == 'mysql') ? 'mysql' : $db->name;
$path = dirname(__FILE__).'/' . 'changeitem' . $dbname . '.php' ;
$class = 'JSchemaChangeitem' . $dbname;
// If the file exists register the class with our class loader.
if (file_exists($path)) {
JLoader::register($class, $path);
$instance = new $class($db, $file, $query);
}
return $instance;
}
/**
* Runs the check query and checks that 1 row is returned
* If yes, return true, otherwise return false
*
* @return boolean true on success, false otherwise
*
* @since 2.5
*/
public function check()
{
$this->checkStatus = -1;
if ($this->checkQuery) {
$this->db->setQuery($this->checkQuery);
$rows = $this->db->loadObject();
if ($rows !== false) {
if (count($rows) === $this->checkQueryExpected) {
$this->checkStatus = 1;
} else {
$this->checkStatus = -2;
}
}
else {
$this->checkStatus = -2;
}
}
return $this->checkStatus;
}
/**
* Runs the update query to apply the change to the database
*
* @since 2.5
*/
public function fix()
{
if ($this->checkStatus === -2) {
// at this point we have a failed query
$this->db->setQuery($this->updateQuery);
if ($this->db->execute()) {
if ($this->check()) {
$this->checkStatus = 1;
$this->rerunStatus = 1;
} else {
$this->rerunStatus = -2;
}
} else {
$this->rerunStatus = -2;
}
}
}
}
PK ¥?\¦V‰
index.htmlnu W+A„¶
PK ¥?\ýW/j£ £ changeitemsqlazure.phpnu W+A„¶ checkStatus = -1; // change status to skipped
$result = null;
// remove any newlines
$this->updateQuery = str_replace("\n", '', $this->updateQuery);
// fix up extra spaces around () and in general
$find = array('#((\s*)\(\s*([^)\s]+)\s*)(\))#','#(\s)(\s*)#');
$replace = array('($3)', '$1');
$updateQuery = preg_replace($find, $replace, $this->updateQuery);
$wordArray = explode(' ', $updateQuery);
// first, make sure we have an array of at least 6 elements
// if not, we can't make a check query for this one
if (count($wordArray) < 6) {
return; // done with method
}
// we can only make check queries for alter table and create table queries
$command = strtoupper($wordArray[0] . ' ' . $wordArray[1]);
if ($command === 'ALTER TABLE') {
$alterCommand = strtoupper($wordArray[3] . ' ' . $wordArray[4]);//print_r($wordArray[4]);die();
if ($alterCommand == 'ADD') {
$result = 'SELECT * FROM INFORMATION_SCHEMA.Columns ' . $wordArray[2] .
' WHERE COLUMN_NAME = ' . $this->fixQuote($wordArray[5]);
$this->queryType = 'ADD';
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]));
}
elseif ($alterCommand == 'CREATE INDEX') {
$index = $this->fixQuote(substr($wordArray[5], 0, strpos($wordArray[5],'(')));
$result = 'SELECT * FROM SYS.INDEXES ' . $wordArray[2] . ' WHERE name = ' . $index;
$this->queryType = 'CREATE INDEX';
$this->msgElements = array($this->fixQuote($wordArray[2]), $index);
}
elseif (strtoupper($wordArray[3]) == 'MODIFY') {
$type = $this->fixQuote($wordArray[5]);
if (isset($wordArray[6])) {
$type = $this->fixQuote($this->fixInteger($wordArray[5], $wordArray[6]));
}
$result = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = ' .$this->fixQuote($wordArray[2]) ;
$this->queryType = 'ALTER COLUMN COLUMN_NAME =' . $this->fixQuote($wordArray[4]);
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[4]));
}
elseif (strtoupper($wordArray[3]) == 'CHANGE') {
// Kludge to fix problem with "integer unsigned"
$type = $this->fixQuote($this->fixInteger($wordArray[6], $wordArray[7]));
$result = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = ' .$this->fixQuote($wordArray[2]) ;
$this->fixQuote($wordArray[4]) ;
$this->queryType = 'ALTER COLUMN COLUMN_NAME =' . $this->fixQuote($wordArray[4]);
$this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[4]));
}
}
if ($command == 'CREATE TABLE') {
$table = $wordArray[5];
$result = 'SELECT * FROM sys.TABLES WHERE NAME = ' . $this->fixQuote($table);
$this->queryType = 'CREATE_TABLE';
$this->msgElements = array($this->fixQuote($table));
}
// set fields based on results
if ($this->checkQuery = $result) {
$this->checkStatus = 0; // unchecked status
}
else {
$this->checkStatus = -1; // skipped
}
}
/**
* Fix up integer. Fixes problem with MySQL integer descriptions.
* If you change a column to "integer unsigned" it shows
* as "int(10) unsigned" in the check query.
*
* @param string $type1 the column type
* @param string $type2 the column attributes
*
* @return string The original or changed column type.
*
* @since 2.5
*/
private function fixInteger($type1, $type2)
{
$result = $type1;
if (strtolower($type1) == "integer" && strtolower(substr($type2, 0, 8)) == 'unsigned') {
$result = 'int';
}
return $result;
}
/**
*
* Fixes up a string for inclusion in a query.
* Replaces name quote character with normal quote for literal.
* Drops trailing semi-colon. Injects the database prefix.
*
* @param string $string The input string to be cleaned up.
* @return string The modified string.
*
* @since 2.5
*/
private function fixQuote($string)
{
$string = str_replace('`', '', $string);
$string = str_replace(';', '', $string);
$string = str_replace('#__', $this->db->getPrefix(), $string);
return $this->db->quote($string);
}
}
PK ¥?\»ÿ'1y y changeitemmysql.phpnu W+A„¶ PK ¥?\®)ÕÐ ¼ .htaccessnu W+A„¶ PK ¥?\
óC6i i
t changeset.phpnu W+A„¶ PK ¥?\Á¨±Ê / changeitem.phpnu W+A„¶ PK ¥?\¦V‰
aC index.htmlnu W+A„¶ PK ¥?\ýW/j£ £ ºC changeitemsqlazure.phpnu W+A„¶ PK ¥?\&@5öœ œ £I changeitemsqlsrv.phpnu W+A„¶ PK + ƒ_