Permalink
Browse files

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

  • Loading branch information...
1 parent 1cc30b2 commit 704b92f9cf3b1ae38213540e65a0677b3d50d28f @mbabker mbabker committed with dextercowley Sep 22, 2012
@@ -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',
@@ -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
@@ -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
@@ -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
*
@@ -0,0 +1 @@
+<!DOCTYPE html><title></title>
Oops, something went wrong.

0 comments on commit 704b92f

Please sign in to comment.