Browse files

Use a sha1 hash of the db_version and config params for version check.

  • Loading branch information...
1 parent e49dea1 commit 0db11272b36ce62ade4f920ed4f9ca87efa2a971 @gcorne gcorne committed Jun 30, 2012
Showing with 34 additions and 6 deletions.
  1. +8 −6 bin/install.php
  2. +26 −0 lib/functions.php
View
14 bin/install.php
@@ -8,8 +8,11 @@
$config_file_path = $argv[1];
+$config_dir = dirname( $config_file_path );
+
define( 'WP_INSTALLING', true );
require_once $config_file_path;
+require_once $config_dir . '/lib/functions.php';
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
@@ -20,16 +23,15 @@
require_once ABSPATH . '/wp-admin/includes/upgrade.php';
require_once ABSPATH . '/wp-includes/wp-db.php';
-define( 'WP_TESTS_DB_VERSION_FILE', ABSPATH . '.wp-tests-db-version' );
+define( 'WP_TESTS_VERSION_FILE', ABSPATH . '.wp-tests-version' );
$wpdb->suppress_errors();
$wpdb->hide_errors();
$installed = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'" );
-if ( $installed && file_exists( WP_TESTS_DB_VERSION_FILE ) ) {
- $install_db_version = file_get_contents( WP_TESTS_DB_VERSION_FILE );
- $db_version = get_option( 'db_version' );
- if ( $db_version == $install_db_version ) {
+if ( $installed && file_exists( WP_TESTS_VERSION_FILE ) ) {
+ $installed_version_hash = file_get_contents( WP_TESTS_VERSION_FILE );
+ if ( $installed_version_hash == test_version_check_hash() ) {
return;
}
}
@@ -56,4 +58,4 @@
}
-file_put_contents( WP_TESTS_DB_VERSION_FILE, get_option('db_version') );
+file_put_contents( WP_TESTS_VERSION_FILE, test_version_check_hash() );
View
26 lib/functions.php
@@ -1,4 +1,30 @@
<?php
+/**
+ * Generate a hash to be used when comparing installed version against
+ * codebase and current configuration
+ * @return string $hash sha1 hash
+ **/
+function test_version_check_hash() {
+ $hash = '';
+ $db_version = get_option( 'db_version' );
+ if ( defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE ) {
+ $version = $db_version;
+ if( defined( 'WP_TESTS_BLOGS' ) ) {
+ $version .= WP_TESTS_BLOGS;
+ }
+ if( defined( 'WP_TESTS_SUBDOMAIN_INSTALL' ) ) {
+ $version .= WP_TESTS_SUBDOMAIN_INSTALL;
+ }
+ if( defined( 'WP_TESTS_DOMAIN' ) ) {
+ $version .= WP_TESTS_DOMAIN;
+ }
+
+ } else {
+ $version = $db_version;
+ }
+
+ return sha1($version);
+}
// For adding hooks before loading WP
function tests_add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {

0 comments on commit 0db1127

Please sign in to comment.