Heine

  • home
  • drupal
  • drupal core commits
  • about
Home › Drupal Core Commits

Commit 450540 by webchick

#946968 follow-up by Damien Tournoud: Refactor version check for databases.

--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/bootstrap.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/bootstrap.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/bootstrap.inc</a>  2010/11/13 14:08:47     1.435
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/bootstrap.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/bootstrap.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/bootstrap.inc</a>  2010/11/13 23:07:15     1.436
@@ -27,21 +27,6 @@
 define('DRUPAL_MINIMUM_PHP_MEMORY_LIMIT',    '32M');
 
 /**
- * Minimum supported version of MySQL, if it is used.
- */
-define('DRUPAL_MINIMUM_MYSQL',  '5.0.15');
-
-/**
- * Minimum supported version of PostgreSQL, if it is used.
- */
-define('DRUPAL_MINIMUM_PGSQL',  '8.3');
-
-/**
- * Minimum supported version of SQLite, if it is used.
- */
-define('DRUPAL_MINIMUM_SQLITE',  '3.3.7');
-
-/**
  * Indicates that the item should never be removed unless explicitly selected.
  *
  * The item may be removed using cache_clear_all() with a cache ID.

--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/database/mysql/install.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/database/mysql/install.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/database/mysql/insta...</a>      2010/11/13 14:08:47     1.5
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/database/mysql/install.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/database/mysql/install.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/database/mysql/insta...</a>      2010/11/13 23:07:16     1.6
@@ -10,7 +10,6 @@
  * Specifies installation tasks for MySQL and equivalent databases.
  */
 class DatabaseTasks_mysql extends DatabaseTasks {
-
   /**
    * The PDO driver name for MySQL and equivalent databases.
    *
@@ -26,10 +25,10 @@
   }
 
   /**
-   * Returns the minimum version for mysql.
+   * Returns the minimum version for MySQL.
    */
-  protected function minimumVersion() {
-    return DRUPAL_MINIMUM_MYSQL;
+  public function minimumVersion() {
+    return '5.0.15';
   }
 }
 

--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/database/pgsql/install.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/database/pgsql/install.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/database/pgsql/insta...</a>      2010/11/13 14:08:47     1.11
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/database/pgsql/install.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/database/pgsql/install.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/database/pgsql/insta...</a>      2010/11/13 23:07:16     1.12
@@ -31,8 +31,8 @@
     return 'PostgreSQL';
   }
 
-  protected function minimumVersion() {
-    return DRUPAL_MINIMUM_PGSQL;
+  public function minimumVersion() {
+    return '8.3';
   }
 
   /**

--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/database/sqlite/install.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/database/sqlite/install.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/database/sqlite/inst...</a>    2010/11/13 14:08:47     1.3
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/database/sqlite/install.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/database/sqlite/install.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/database/sqlite/inst...</a>    2010/11/13 23:07:16     1.4
@@ -8,11 +8,18 @@
 
 class DatabaseTasks_sqlite extends DatabaseTasks {
   protected $pdoDriver = 'sqlite';
+
   public function name() {
     return 'SQLite';
   }
-  protected function minimumVersion() {
-    return DRUPAL_MINIMUM_SQLITE;
+
+  /**
+   * Minimum engine version.
+   *
+   * @todo: consider upping to 3.6.8 in Drupal 8 to get SAVEPOINT support.
+   */
+  public function minimumVersion() {
+    return '3.3.7';
   }
 }
 

--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/install.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/install.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/install.inc</a>        2010/11/13 14:08:47     1.143
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/install.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/install.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/install.inc</a>        2010/11/13 23:07:15     1.144
@@ -277,6 +277,10 @@
    */
   protected $tasks = array(
     array(
+      'function'    => 'checkEngineVersion',
+      'arguments'   => array(),
+    ),
+    array(
       'arguments'   => array(
         'CREATE TABLE drupal_install_test (id int NULL)',
         'Drupal can use CREATE TABLE database commands.',
@@ -348,8 +352,21 @@
     return $this->hasPdoDriver() && empty($this->error);
   }
 
+  /**
+   * Return the human-readable name of the driver.
+   */
   abstract public function name();
-  abstract protected function minimumVersion();
+
+  /**
+   * Return the minimum required version of the engine.
+   *
+   * @return
+   *   A version string. If not NULL, it will be checked against the version
+   *   reported by the Database engine using version_compare().
+   */
+  public function minimumVersion() {
+    return NULL;
+  }
 
   /**
    * Run database tasks and tests to see if Drupal can run on the database.
@@ -357,9 +374,6 @@
   public function runTasks() {
     // We need to establish a connection before we can run tests.
     if ($this->connect()) {
-      if (version_compare(Database::getConnection()->version(), $this->minimumVersion()) < 0) {
-        throw new DatabaseTaskException(st("The database version %version is less than the minimum required version %minimum_version.", array('%version' => Database::getConnection()->version(), '%minimum_version' => $this->minimumVersion())));
-      }
       foreach ($this->tasks as $task) {
         if (!isset($task['function'])) {
           $task['function'] = 'runTestQuery';
@@ -419,6 +433,15 @@
       return !$fatal;
     }
   }
+
+  /**
+   * Check the engine version.
+   */
+  protected function checkEngineVersion() {
+    if ($this->minimumVersion() && version_compare(Database::getConnection()->version(), $this->minimumVersion(), '<')) {
+      $this->fail(st("The database version %version is less than the minimum required version %minimum_version.", array('%version' => Database::getConnection()->version(), '%minimum_version' => $this->minimumVersion())));
+    }
+  }
 }
 /**
  * @class Exception class used to throw error if the DatabaseInstaller fails.

No votes yet
  • Drupal Core
  • Download patch

Recent posts

  • Aan: prorail - Hekwerk langs tunnel onvoldoende - kinderen op spoordijk
  • Unserializing user-supplied data, a bad idea
  • Planet Drupal past and current
  • Help! - Cannot access a global variable.
  • Why is my module's update hook not listed on update.php's selection form?
more

Security reviews

  • Afraid custom code makes your site vulnerable?
  • You don't really trust that module you just downloaded from Drupal.org?

Sleep better after a security review.

Tags

Captcha CSRF Drupal embed Input Format modx OpenID Performance Planet Drupal rants Security Varnish
more tags
  • home
  • drupal
  • drupal core commits
  • about

Copyright © 2010 by Heine Deelstra. All rights reserved.