Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[#28900] Improvements to Schema package. Thanks Michael.

  • Loading branch information...
commit 704b92f9cf3b1ae38213540e65a0677b3d50d28f 1 parent 1cc30b2
@mbabker mbabker authored dextercowley committed
View
3  administrator/components/com_admin/script.php
@@ -320,6 +320,9 @@ public function deleteUnexistingFiles()
'/libraries/cms/controller/legacy.php',
'/libraries/cms/model/index.html',
'/libraries/cms/model/legacy.php',
+ '/libraries/cms/schema/changeitemmysql.php',
+ '/libraries/cms/schema/changeitemsqlazure.php',
+ '/libraries/cms/schema/changeitemsqlsrv.php',
'/libraries/cms/view/index.html',
'/libraries/cms/view/legacy.php',
'/libraries/joomla/application/application.php',
View
16 administrator/components/com_installer/models/database.php
@@ -46,7 +46,10 @@ protected function populateState($ordering = null, $direction = null)
*/
public function fix()
{
- $changeSet = $this->getItems();
+ if (!$changeSet = $this->getItems())
+ {
+ return false;
+ }
$changeSet->fix();
$this->fixSchemaVersion($changeSet);
$this->fixUpdateVersion();
@@ -64,7 +67,16 @@ public function fix()
public function getItems()
{
$folder = JPATH_ADMINISTRATOR . '/components/com_admin/sql/updates/';
- $changeSet = JSchemaChangeset::getInstance(JFactory::getDbo(), $folder);
+
+ try
+ {
+ $changeSet = JSchemaChangeset::getInstance(JFactory::getDbo(), $folder);
+ }
+ catch (RuntimeException $e)
+ {
+ JFactory::getApplication()->enqueueMessage($e->getMessage(), 'warning');
+ return false;
+ }
return $changeSet;
}
View
1  installation/CHANGELOG
@@ -29,6 +29,7 @@ $ -> Language fix or change
22-Sep-2012 Mark Dexter
# [#28764] user notes category is not properly nested in the assets table. Thanks Elin.
# [#29116] Parse error on initializing installation if server does not meet PHP requirements . Thanks Jean-Marie.
+ # [#28900] Improvements to Schema package. Thanks Michael.
22-Sep-2012 Jean-Marie Simonet
+$ Adding installation languages: ar-AA, az-AZ, ckb-IQ, fi-FI
View
51 libraries/cms/schema/changeitem.php
@@ -10,7 +10,7 @@
defined('JPATH_PLATFORM') or die;
/**
- * Each object represents one query, which is one line from a DDS SQL query.
+ * 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
@@ -27,7 +27,7 @@
* @subpackage Schema
* @since 2.5
*/
-abstract class JSchemaChangeitem extends JObject
+abstract class JSchemaChangeitem
{
/**
* Update file: full path file name where query was found
@@ -136,26 +136,53 @@ public function __construct($db, $file, $query)
* @return JSchemaChangeitem instance based on the database driver
*
* @since 2.5
+ * @throws RuntimeException if class for database driver not found
*/
public static function getInstance($db, $file, $query)
{
- $instance = null;
+ // Get the class name
+ $dbname = $db->name;
- // Get the class name (mysql and mysqli both use mysql)
- $dbname = (substr($db->name, 0, 5) == 'mysql') ? 'mysql' : $db->name;
- $path = __DIR__ . '/' . 'changeitem' . $dbname . '.php';
- $class = 'JSchemaChangeitem' . $dbname;
+ if ($dbname == 'mysqli')
+ {
+ $dbname = 'mysql';
+ }
+ elseif ($dbname == 'sqlazure')
+ {
+ $dbname = 'sqlsrv';
+ }
- // If the file exists register the class with our class loader.
- if (file_exists($path))
+ $class = 'JSchemaChangeitem' . ucfirst($dbname);
+
+ // If the class exists, return it.
+ if (class_exists($class))
{
- JLoader::register($class, $path);
- $instance = new $class($db, $file, $query);
+ return new $class($db, $file, $query);
}
- return $instance;
+
+ throw new RuntimeException(sprintf('JSchemaChangeitem child class not found for the %s database driver', $dbname), 500);
}
/**
+ * 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.
+ * 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.
+ *
+ * @return void
+ *
+ * @since 2.5
+ */
+ abstract protected function buildCheckQuery();
+
+ /**
* Runs the check query and checks that 1 row is returned
* If yes, return true, otherwise return false
*
View
1  libraries/cms/schema/changeitem/index.html
@@ -0,0 +1 @@
+<!DOCTYPE html><title></title>
View
384 libraries/cms/schema/changeitemmysql.php → libraries/cms/schema/changeitem/mysql.php
@@ -1,192 +1,192 @@
-<?php
-/**
- * @package Joomla.Libraries
- * @subpackage Schema
- *
- * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE
- */
-
-defined('_JEXEC') or die;
-
-/**
- * Checks the database schema against one MySQL DDL query to see if it has been run.
- *
- * @package Joomla.Libraries
- * @subpackage Schema
- * @since 2.5
- */
-class JSchemaChangeitemmysql extends JSchemaChangeitem
-{
- /**
- * 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.
- * 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.
- *
- * @return void
- *
- * @since 2.5
- */
- protected function buildCheckQuery()
- {
- // Initialize fields in case we can't create a check query
- $this->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)
- {
- // Done with method
- return;
- }
-
- // 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 ($alterCommand == 'DROP COLUMN')
- {
- $index = $this->fixQuote($wordArray[5]);
- $result = 'SHOW COLUMNS IN ' . $wordArray[2] . ' WHERE Field = ' . $index;
- $this->queryType = 'DROP_COLUMN';
- $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)
- {
- // Unchecked status
- $this->checkStatus = 0;
- }
- else
- {
- // Skipped
- $this->checkStatus = -1;
- }
- }
-
- /**
- * 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);
- }
-}
+<?php
+/**
+ * @package Joomla.Libraries
+ * @subpackage Schema
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('_JEXEC') or die;
+
+/**
+ * Checks the database schema against one MySQL DDL query to see if it has been run.
+ *
+ * @package Joomla.Libraries
+ * @subpackage Schema
+ * @since 2.5
+ */
+class JSchemaChangeitemMysql extends JSchemaChangeitem
+{
+ /**
+ * 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.
+ * 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.
+ *
+ * @return void
+ *
+ * @since 2.5
+ */
+ protected function buildCheckQuery()
+ {
+ // Initialize fields in case we can't create a check query
+ $this->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)
+ {
+ // Done with method
+ return;
+ }
+
+ // 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 ($alterCommand == 'DROP COLUMN')
+ {
+ $index = $this->fixQuote($wordArray[5]);
+ $result = 'SHOW COLUMNS IN ' . $wordArray[2] . ' WHERE Field = ' . $index;
+ $this->queryType = 'DROP_COLUMN';
+ $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)
+ {
+ // Unchecked status
+ $this->checkStatus = 0;
+ }
+ else
+ {
+ // Skipped
+ $this->checkStatus = -1;
+ }
+ }
+
+ /**
+ * 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);
+ }
+}
View
492 libraries/cms/schema/changeitempostgresql.php → libraries/cms/schema/changeitem/postgresql.php
@@ -1,246 +1,246 @@
-<?php
-/**
- * @package Joomla.Libraries
- * @subpackage Schema
- *
- * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE
- */
-
-defined('_JEXEC') or die;
-
-/**
- * Checks the database schema against one PostgreSQL DDL query to see if it has been run.
- *
- * @package Joomla.Libraries
- * @subpackage Schema
- * @since 3.0
- */
-class JSchemaChangeitempostgresql extends JSchemaChangeitem
-{
- /**
- * 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.
- * 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.
- *
- * @return void
- *
- * @since 3.0
- */
- protected function buildCheckQuery()
- {
- // Initialize fields in case we can't create a check query
- $this->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)
- {
- // Done with method
- return;
- }
-
- // 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 = 'SELECT column_name FROM information_schema.columns WHERE table_name=' .
- $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5]);
-
- $this->queryType = 'ADD_COLUMN';
- $this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]));
- }
- elseif ($alterCommand === 'ALTER COLUMN')
- {
- if (strtoupper($wordArray[6]) == 'TYPE')
- {
- $type = '';
- for ($i = 7; $i < count($wordArray); $i++)
- {
- $type .= $wordArray[$i] . ' ';
- }
-
- if ($pos = strpos($type, '('))
- {
- $type = substr($type, 0, $pos);
- }
-
- if ($pos = strpos($type, ';'))
- {
- $type = substr($type, 0, $pos);
- }
-
- $result = 'SELECT column_name, data_type FROM information_schema.columns WHERE table_name=' .
- $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5]) .
- ' AND data_type=' . $this->fixQuote($type);
-
- $this->queryType = 'CHANGE_COLUMN_TYPE';
- $this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $type);
- }
- elseif(strtoupper($wordArray[7] . ' ' . $wordArray[8]) == 'NOT NULL')
- {
- if ( strtoupper($wordArray[6]) == 'SET' )
- {
- // SET NOT NULL
- $isNullable = $this->fixQuote('NO');
- }
- else
- {
- // DROP NOT NULL
- $isNullable = $this->fixQuote('YES');
- }
- $result = 'SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name=' .
- $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5]) .
- ' AND is_nullable=' . $isNullable;
-
- $this->queryType = 'CHANGE_COLUMN_TYPE';
- $this->checkQueryExpected = 1;
- $this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $isNullable);
- }
- elseif(strtoupper($wordArray[7]) === 'DEFAULT')
- {
- if ( strtoupper($wordArray[6]) == 'SET' )
- {
- $isNullDef = 'IS NOT NULL';
- }
- else
- {
- // DROP DEFAULT
- $isNullDef = 'IS NULL';
- }
- $result = 'SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_name=' .
- $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5]) .
- ' AND column_default ' . $isNullDef;
-
- $this->queryType = 'CHANGE_COLUMN_TYPE';
- $this->checkQueryExpected = 1;
- $this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $isNullDef);
- }
- }
- }
- elseif ($command === 'DROP INDEX')
- {
- if (strtoupper($wordArray[2] . $wordArray[3]) == 'IFEXISTS')
- {
- $idx = $this->fixQuote($wordArray[4]);
- }
- else
- {
- $idx = $this->fixQuote($wordArray[2]);
- }
-
- $result = 'SELECT * FROM pg_indexes WHERE indexname=' . $idx;
- $this->queryType = 'DROP_INDEX';
- $this->checkQueryExpected = 0;
- $this->msgElements = array($this->fixQuote($idx));
- }
- elseif ($alterCommand == 'CREATE INDEX' || (strtoupper($alterCommand . $wordArray[2]) == 'CREATE UNIQUE INDEX'))
- {
- if ( $wordArray[1] === 'UNIQUE' )
- {
- $idx = $this->fixQuote($wordArray[3]);
- $table = $this->fixQuote($wordArray[5]);
- }
- else
- {
- $idx = $this->fixQuote($wordArray[2]);
- $table = $this->fixQuote($wordArray[4]);
- }
-
- $result = 'SELECT * FROM pg_indexes WHERE indexname=' . $idx . ' AND tablename=' . $table;
- $this->queryType = 'ADD_INDEX';
- $this->checkQueryExpected = 1;
- $this->msgElements = array($table, $idx);
- }
-
- if ($command == 'CREATE TABLE')
- {
- if (strtoupper($wordArray[2] . $wordArray[3] . $wordArray[4]) == 'IFNOTEXISTS')
- {
- $table = $this->fixQuote($wordArray[5]);
- }
- else
- {
- $table = $this->fixQuote($wordArray[2]);
- }
- $result = 'SELECT table_name FROM information_schema.tables WHERE table_name=' . $table;
- $this->queryType = 'CREATE_TABLE';
- $this->checkQueryExpected = 1;
- $this->msgElements = array($table);
- }
-
- // Set fields based on results
- if ($this->checkQuery = $result)
- {
- // Unchecked status
- $this->checkStatus = 0;
- }
- else
- {
- // Skipped
- $this->checkStatus = -1;
- }
- }
-
- /**
- * Fix up integer. Fixes problem with PostgreSQL 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 3.0
- */
- private function fixInteger($type1, $type2)
- {
- $result = $type1;
- if (strtolower($type1) == "integer" && strtolower(substr($type2, 0, 8)) == 'unsigned')
- {
- $result = 'unsigned int(10)';
- }
- 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 3.0
- */
- private function fixQuote($string)
- {
- $string = str_replace('"', '', $string);
- $string = str_replace(';', '', $string);
- $string = str_replace('#__', $this->db->getPrefix(), $string);
- return $this->db->quote($string);
- }
-}
+<?php
+/**
+ * @package Joomla.Libraries
+ * @subpackage Schema
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('_JEXEC') or die;
+
+/**
+ * Checks the database schema against one PostgreSQL DDL query to see if it has been run.
+ *
+ * @package Joomla.Libraries
+ * @subpackage Schema
+ * @since 3.0
+ */
+class JSchemaChangeitemPostgresql extends JSchemaChangeitem
+{
+ /**
+ * 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.
+ * 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.
+ *
+ * @return void
+ *
+ * @since 3.0
+ */
+ protected function buildCheckQuery()
+ {
+ // Initialize fields in case we can't create a check query
+ $this->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)
+ {
+ // Done with method
+ return;
+ }
+
+ // 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 = 'SELECT column_name FROM information_schema.columns WHERE table_name=' .
+ $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5]);
+
+ $this->queryType = 'ADD_COLUMN';
+ $this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]));
+ }
+ elseif ($alterCommand === 'ALTER COLUMN')
+ {
+ if (strtoupper($wordArray[6]) == 'TYPE')
+ {
+ $type = '';
+ for ($i = 7; $i < count($wordArray); $i++)
+ {
+ $type .= $wordArray[$i] . ' ';
+ }
+
+ if ($pos = strpos($type, '('))
+ {
+ $type = substr($type, 0, $pos);
+ }
+
+ if ($pos = strpos($type, ';'))
+ {
+ $type = substr($type, 0, $pos);
+ }
+
+ $result = 'SELECT column_name, data_type FROM information_schema.columns WHERE table_name=' .
+ $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5]) .
+ ' AND data_type=' . $this->fixQuote($type);
+
+ $this->queryType = 'CHANGE_COLUMN_TYPE';
+ $this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $type);
+ }
+ elseif (strtoupper($wordArray[7] . ' ' . $wordArray[8]) == 'NOT NULL')
+ {
+ if (strtoupper($wordArray[6]) == 'SET')
+ {
+ // SET NOT NULL
+ $isNullable = $this->fixQuote('NO');
+ }
+ else
+ {
+ // DROP NOT NULL
+ $isNullable = $this->fixQuote('YES');
+ }
+ $result = 'SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name=' .
+ $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5]) .
+ ' AND is_nullable=' . $isNullable;
+
+ $this->queryType = 'CHANGE_COLUMN_TYPE';
+ $this->checkQueryExpected = 1;
+ $this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $isNullable);
+ }
+ elseif (strtoupper($wordArray[7]) === 'DEFAULT')
+ {
+ if (strtoupper($wordArray[6]) == 'SET')
+ {
+ $isNullDef = 'IS NOT NULL';
+ }
+ else
+ {
+ // DROP DEFAULT
+ $isNullDef = 'IS NULL';
+ }
+ $result = 'SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_name=' .
+ $this->fixQuote($wordArray[2]) . ' AND column_name=' . $this->fixQuote($wordArray[5]) .
+ ' AND column_default ' . $isNullDef;
+
+ $this->queryType = 'CHANGE_COLUMN_TYPE';
+ $this->checkQueryExpected = 1;
+ $this->msgElements = array($this->fixQuote($wordArray[2]), $this->fixQuote($wordArray[5]), $isNullDef);
+ }
+ }
+ }
+ elseif ($command === 'DROP INDEX')
+ {
+ if (strtoupper($wordArray[2] . $wordArray[3]) == 'IFEXISTS')
+ {
+ $idx = $this->fixQuote($wordArray[4]);
+ }
+ else
+ {
+ $idx = $this->fixQuote($wordArray[2]);
+ }
+
+ $result = 'SELECT * FROM pg_indexes WHERE indexname=' . $idx;
+ $this->queryType = 'DROP_INDEX';
+ $this->checkQueryExpected = 0;
+ $this->msgElements = array($this->fixQuote($idx));
+ }
+ elseif ($alterCommand == 'CREATE INDEX' || (strtoupper($alterCommand . $wordArray[2]) == 'CREATE UNIQUE INDEX'))
+ {
+ if ($wordArray[1] === 'UNIQUE')
+ {
+ $idx = $this->fixQuote($wordArray[3]);
+ $table = $this->fixQuote($wordArray[5]);
+ }
+ else
+ {
+ $idx = $this->fixQuote($wordArray[2]);
+ $table = $this->fixQuote($wordArray[4]);
+ }
+
+ $result = 'SELECT * FROM pg_indexes WHERE indexname=' . $idx . ' AND tablename=' . $table;
+ $this->queryType = 'ADD_INDEX';
+ $this->checkQueryExpected = 1;
+ $this->msgElements = array($table, $idx);
+ }
+
+ if ($command == 'CREATE TABLE')
+ {
+ if (strtoupper($wordArray[2] . $wordArray[3] . $wordArray[4]) == 'IFNOTEXISTS')
+ {
+ $table = $this->fixQuote($wordArray[5]);
+ }
+ else
+ {
+ $table = $this->fixQuote($wordArray[2]);
+ }
+ $result = 'SELECT table_name FROM information_schema.tables WHERE table_name=' . $table;
+ $this->queryType = 'CREATE_TABLE';
+ $this->checkQueryExpected = 1;
+ $this->msgElements = array($table);
+ }
+
+ // Set fields based on results
+ if ($this->checkQuery = $result)
+ {
+ // Unchecked status
+ $this->checkStatus = 0;
+ }
+ else
+ {
+ // Skipped
+ $this->checkStatus = -1;
+ }
+ }
+
+ /**
+ * Fix up integer. Fixes problem with PostgreSQL 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 3.0
+ */
+ private function fixInteger($type1, $type2)
+ {
+ $result = $type1;
+ if (strtolower($type1) == 'integer' && strtolower(substr($type2, 0, 8)) == 'unsigned')
+ {
+ $result = 'unsigned int(10)';
+ }
+ 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 3.0
+ */
+ private function fixQuote($string)
+ {
+ $string = str_replace('"', '', $string);
+ $string = str_replace(';', '', $string);
+ $string = str_replace('#__', $this->db->getPrefix(), $string);
+ return $this->db->quote($string);
+ }
+}
View
324 libraries/cms/schema/changeitemsqlsrv.php → libraries/cms/schema/changeitem/sqlsrv.php
@@ -1,162 +1,162 @@
-<?php
-/**
- * @package Joomla.Libraries
- * @subpackage Schema
- *
- * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE
- */
-
-defined('_JEXEC') or die;
-
-/**
- * Checks the database schema against one SQL Server DDL query to see if it has been run.
- *
- * @package Joomla.Libraries
- * @subpackage Schema
- * @since 2.5
- */
-class JSchemaChangeitemsqlsrv extends JSchemaChangeitem
-{
- /**
- * 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.
- * 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.
- *
- * @return void
- *
- * @since 2.5
- */
- protected function buildCheckQuery()
- {
- // Initialize fields in case we can't create a check query
- $this->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)
- {
- // Done with method
- return;
- }
-
- // 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')
- {
- $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)
- {
- // Unchecked status
- $this->checkStatus = 0;
- }
- else
- {
- // Skipped
- $this->checkStatus = -1;
- }
- }
-
- /**
- * 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);
- }
-}
+<?php
+/**
+ * @package Joomla.Libraries
+ * @subpackage Schema
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('_JEXEC') or die;
+
+/**
+ * Checks the database schema against one SQL Server DDL query to see if it has been run.
+ *
+ * @package Joomla.Libraries
+ * @subpackage Schema
+ * @since 2.5
+ */
+class JSchemaChangeitemSqlsrv extends JSchemaChangeitem
+{
+ /**
+ * 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.
+ * 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.
+ *
+ * @return void
+ *
+ * @since 2.5
+ */
+ protected function buildCheckQuery()
+ {
+ // Initialize fields in case we can't create a check query
+ $this->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)
+ {
+ // Done with method
+ return;
+ }
+
+ // 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')
+ {
+ $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)
+ {
+ // Unchecked status
+ $this->checkStatus = 0;
+ }
+ else
+ {
+ // Skipped
+ $this->checkStatus = -1;
+ }
+ }
+
+ /**
+ * 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);
+ }
+}
View
22 libraries/cms/schema/changeitemsqlazure.php
@@ -1,22 +0,0 @@
-<?php
-/**
- * @package Joomla.Libraries
- * @subpackage Schema
- *
- * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE
- */
-
-defined('_JEXEC') or die;
-
-/**
- * Checks the database schema against one SQL Azure DDL query to see if it has been run.
- *
- * @package Joomla.Libraries
- * @subpackage Schema
- * @since 2.5
- */
-class JSchemaChangeitemsqlazure extends JSchemaChangeitemsqlsrv
-{
- public $name = 'sqlazure';
-}
View
10 libraries/cms/schema/changeset.php
@@ -21,7 +21,7 @@
* @subpackage Schema
* @since 2.5
*/
-class JSchemaChangeset extends JObject
+class JSchemaChangeset
{
/**
* Array of JSchemaChangeitem objects
@@ -80,10 +80,12 @@ public function __construct($db, $folder = null)
public static function getInstance($db, $folder)
{
static $instance;
+
if (!is_object($instance))
{
$instance = new JSchemaChangeset($db, $folder);
}
+
return $instance;
}
@@ -185,13 +187,13 @@ private function getUpdateFiles()
{
// Get the folder from the database name
$sqlFolder = $this->db->name;
- if (substr($sqlFolder, 0, 5) == 'mysql')
+ if ($sqlFolder == 'mysqli')
{
$sqlFolder = 'mysql';
}
- elseif (substr($sqlFolder, 0, 10) == 'postgresql')
+ elseif ($sqlFolder == 'sqlsrv')
{
- $sqlFolder = 'postgresql';
+ $sqlFolder = 'sqlazure';
}
// Default folder to core com_admin
View
46 tests/unit/suites/libraries/schema/JSchemaChangeitemSqlazureTest.php
@@ -1,46 +0,0 @@
-<?php
-/**
- * @package Joomla.UnitTest
- * @subpackage Schema
- *
- * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE
- */
-
-/**
- * Test class for JSchemaChangeitemSqlazure.
- * Generated by PHPUnit on 2012-07-26 at 20:42:22.
- */
-class JSchemaChangeitemSqlazureTest extends PHPUnit_Framework_TestCase
-{
- /**
- * @var JSchemaChangeitemSqlazure
- */
- protected $object;
-
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
- //$this->object = new JSchemaChangeitemSqlazure;
- }
-
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
- }
-
- /**
- * Dummy method to prevent failures due to no tests in a class
- */
- public function testDummy()
- {
- // Remove the following lines when you implement this test.
- $this->markTestSkipped('This class does not yet have any valid tests.');
- }
-}
View
0  ...s/libraries/schema/JSchemaChangeitemMysqlTest.php → .../schema/changeitem/JSchemaChangeitemMysqlTest.php
File renamed without changes
View
0  ...raries/schema/JSchemaChangeitemPostgresqlTest.php → ...ma/changeitem/JSchemaChangeitemPostgresqlTest.php
File renamed without changes
View
2  .../libraries/schema/JSchemaChangeitemSqlsrvTest.php → ...schema/changeitem/JSchemaChangeitemSqlsrvTest.php
@@ -43,4 +43,4 @@ public function testDummy()
// Remove the following lines when you implement this test.
$this->markTestSkipped('This class does not yet have any valid tests.');
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.