diff --git a/README.md b/README.md index 39a8c5ff3d4961deb5a4113c362db9982de10ea7..2d53f128afa56865ba481c71c0a493dca1b484b5 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,8 @@ Some rough ideas on how the situation could be improved: - the ```upstream``` branch should disappear. We should not have to care ourselves on keeping a sync of Wordpress source code - we should really just keep the patches and our contributions - we need to be able to build a docker container in the end + +## About drop-in plugins + +Drop-in plugins, such as ```Hyperdb```, do not have to be installed in the plugins directory, but we have instead to place files directly into wp-content. +We have to thus manually specify where they have to go. diff --git a/composer.json b/composer.json index 47fa55488e7ad6e47c01b1991f51310f0886f09c..0530a08553a11a9a3cdabfba688c06b9ab799b61 100644 --- a/composer.json +++ b/composer.json @@ -23,11 +23,14 @@ "johnpbloch/wordpress": "^5.4", "bjornjohansen/wplang": "^0.1.1", "lkwdwrd/wp-muplugin-loader": "^1.0", - "wpackagist-theme/minimalism": "1.0.3" + "wpackagist-theme/minimalism": "1.0.3", + "koodimonni/composer-dropin-installer": "^1.2", + "wpackagist-plugin/hyperdb": "^1.6" }, "extra": { "wordpress-install-dir": "web/wp", - "installer-paths": { + "installer-paths": { + "vendor/{$name}": ["wpackagist-plugin/hyperdb"], "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"], "web/app/plugins/{$name}/": ["type:wordpress-plugin"], "web/app/themes/{$name}/": ["type:wordpress-theme"] @@ -37,6 +40,9 @@ "patches-file": "composer.patches.json", "force-mu": [ "disable-wordpress-updates" - ] + ], + "dropin-paths": { + "web/app": ["package:wpackagist-plugin/hyperdb:db.php"] + } } } diff --git a/composer.lock b/composer.lock index ff49fa34ab1bfd39bdc7aff0a74c0c9b50fb7055..c8767f34c8ea2117436b704b14fdbe22c6de55b9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "6f5c67e11208010e0856439723cf37c1", + "content-hash": "7857809a1c2b51ea4d9581f6e2bcc2c3", "packages": [ { "name": "bjornjohansen/wplang", @@ -344,6 +344,49 @@ ], "time": "2018-11-09T20:10:38+00:00" }, + { + "name": "koodimonni/composer-dropin-installer", + "version": "1.2", + "source": { + "type": "git", + "url": "https://github.com/Koodimonni/Composer-Dropin-Installer.git", + "reference": "a749f19e3a3bc05529190961ed7529592b20138e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Koodimonni/Composer-Dropin-Installer/zipball/a749f19e3a3bc05529190961ed7529592b20138e", + "reference": "a749f19e3a3bc05529190961ed7529592b20138e", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*-dev" + }, + "type": "composer-plugin", + "extra": { + "class": "Koodimonni\\Composer\\Dropin" + }, + "autoload": { + "psr-4": { + "Koodimonni\\Composer\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "WTFPL" + ], + "authors": [ + { + "name": "Onni Hakala", + "email": "onni@koodimonni.fi", + "role": "Developer" + } + ], + "description": "Install packages or a few files from packages into custom paths without overwriting existing stuff.", + "time": "2018-02-04T10:52:01+00:00" + }, { "name": "lkwdwrd/wp-muplugin-loader", "version": "1.0.5", @@ -393,6 +436,31 @@ ], "time": "2018-04-20T22:09:51+00:00" }, + { + "name": "wpackagist-plugin/hyperdb", + "version": "1.6", + "source": { + "type": "svn", + "url": "https://plugins.svn.wordpress.org/hyperdb/", + "reference": "tags/1.6" + }, + "dist": { + "type": "zip", + "url": "https://downloads.wordpress.org/plugin/hyperdb.1.6.zip", + "reference": null, + "shasum": null + }, + "require": { + "composer/installers": "~1.0" + }, + "type": "wordpress-plugin", + "extra": { + "patches_applied": { + "hyperdb logging": "patches/hyperdb.patch" + } + }, + "homepage": "https://wordpress.org/plugins/hyperdb/" + }, { "name": "wpackagist-theme/minimalism", "version": "1.0.3", diff --git a/composer.patches.json b/composer.patches.json index 74db166805b90e78aa5d1a04ff634fc3a7b11eda..752ca3b03d716dec6abe9c5f34ef4c827864ea3c 100644 --- a/composer.patches.json +++ b/composer.patches.json @@ -1,10 +1,13 @@ { - "patches": { - "wpackagist-plugin/disable-wordpress-updates": { - "Patch title": "patches/0001-Patched-Disable-Updates-to-run-checks-during-cron-jo.patch" - }, - "wpackagist-theme/minimalism": { - "Minimalism theme footer": "patches/0001-Patch-theme-minimalism.patch" - } - } + "patches": { + "wpackagist-plugin/disable-wordpress-updates": { + "Disable automatic updates": "patches/0001-Patched-Disable-Updates-to-run-checks-during-cron-jo.patch" + }, + "wpackagist-theme/minimalism": { + "Minimalism theme footer": "patches/0001-Patch-theme-minimalism.patch" + }, + "wpackagist-plugin/hyperdb": { + "hyperdb logging": "patches/hyperdb.patch" + } + } } diff --git a/patches/hyperdb.patch b/patches/hyperdb.patch new file mode 100644 index 0000000000000000000000000000000000000000..78dd5099f8c1d38d7fdd6f2b17bf6b96ce241ed2 --- /dev/null +++ b/patches/hyperdb.patch @@ -0,0 +1,126 @@ +diff --git a/db.php b/db.php +index f900d305..8829d102 100644 +--- a/db.php ++++ b/db.php +@@ -51,6 +50,13 @@ define( 'HYPERDB_CONN_HOST_ERROR', 2003 ); // Can't connect to MySQL server on + define( 'HYPERDB_SERVER_GONE_ERROR', 2006 ); // MySQL server has gone away + + class hyperdb extends wpdb { ++ ++ /** ++ * A/I patch! ++ * store a FlexiHash() instance here. ++ */ ++ var $hash_map; ++ + /** + * The last table that was queried + * @var string +@@ -306,6 +312,12 @@ class hyperdb extends wpdb { + . ')\W([\w-]+)\W/is', $q, $maybe) ) + return $maybe[1]; + ++ // SHOW TABLES LIKE (used in some plugins) ++ if ( preg_match('/^\s*' ++ . 'SHOW\s+TABLES\s+LIKE\s+' ++ . '\W(\w+)\W/is', $q, $maybe) ) ++ return $maybe[1]; ++ + // Big pattern for the rest of the table-related queries in MySQL 5.0 + if ( preg_match('/^\s*(?:' + . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM' +@@ -401,6 +413,11 @@ class hyperdb extends wpdb { + + $this->run_callbacks( 'dataset_found', $dataset ); + ++ if (WP_DEBUG === true) { ++ $_ai_msg = sprintf("We choose dataset %s for query '%s'", $this->dataset, $query); ++ $this->print_error($_ai_msg); ++ } ++ + if ( empty( $this->hyper_servers ) ) { + if ( $this->is_mysql_connection( $this->dbh ) ) + return $this->dbh; +@@ -665,16 +682,19 @@ class hyperdb extends wpdb { + $success = false; + $this->last_connection = compact('dbhname', 'host', 'port', 'user', 'name', 'tcp', 'elapsed', 'success'); + $this->db_connections[] = $this->last_connection; +- $msg = date( "Y-m-d H:i:s" ) . " Can't select $dbhname - \n"; +- $msg .= "'referrer' => '{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}',\n"; +- $msg .= "'server' => {$server},\n"; +- $msg .= "'host' => {$host},\n"; +- $msg .= "'error' => " . $this->ex_mysql_error() . ",\n"; +- $msg .= "'errno' => " . $this->ex_mysql_errno() . ",\n"; +- $msg .= "'server_state' => $server_state\n"; +- $msg .= "'lagged_status' => " . ( isset( $lagged_status ) ? $lagged_status : HYPERDB_LAG_UNKNOWN ); +- +- $this->print_error( $msg ); ++ /* Workaround to stop logging a/i */ ++ if ( AI_LOG_HYPERDB == true ) { ++ $msg = date( "Y-m-d H:i:s" ) . " Can't select $dbhname - \n"; ++ $msg .= "'referrer' => '{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}',\n"; ++ $msg .= "'server' => {$server},\n"; ++ $msg .= "'host' => {$host},\n"; ++ $msg .= "'error' => " . $this->ex_mysql_error() . ",\n"; ++ $msg .= "'errno' => " . $this->ex_mysql_errno() . ",\n"; ++ $msg .= "'server_state' => $server_state\n"; ++ $msg .= "'lagged_status' => " . ( isset( $lagged_status ) ? $lagged_status : HYPERDB_LAG_UNKNOWN ); ++ ++ $this->print_error( $msg ); ++ } + } + + if ( ! $success || ! isset( $this->dbhs[$dbhname] ) || ! $this->is_mysql_connection( $this->dbhs[$dbhname] ) ) { +@@ -709,6 +729,15 @@ class hyperdb extends wpdb { + + $this->set_charset($this->dbhs[$dbhname], $charset, $collate); + ++ if ( !isset( $charset ) ) ++ $charset = null; ++ ++ if ( !isset( $collate ) ) ++ $collate = null; ++ ++ // AI workaround: set all queries to latin1 ++ $this->set_charset($this->dbhs[$dbhname], 'latin1'); ++ + $this->dbh = $this->dbhs[$dbhname]; // needed by $wpdb->_real_escape() + + $this->last_used_server = compact('host', 'user', 'name', 'read', 'write'); +@@ -857,6 +886,11 @@ class hyperdb extends wpdb { + $statement_after_query = $this->run_callbacks( 'statement_after_query' ); + $query_for_log = $query; + ++ // A/I: prevent mysql-proxy to cache the admin section ++ if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/') !== false) { ++ $query .= ' /* NO CACHE */'; ++ } ++ + $this->timer_start(); + if ( $statement_before_query ) { + $query_for_log = "$statement_before_query; $query_for_log"; +@@ -1428,6 +1462,23 @@ class hyperdb extends wpdb { + + } // class hyperdb + +-$wpdb = new hyperdb(); ++/** ++ * AI custom: Logs all queries for debugging purposes ++ */ ++function ai_log_db_queries($query, $time, $backtrace=null, hyperdb $obj ) { ++ $fh = fopen( ABSPATH . '/profiling/noblogs_queries_'. date('Ymd') . '.log', 'a'); ++ if (!$fh) { ++ return array($query, $time, $backtrace); ++ } ++ fwrite($fh, sprintf("##\n#Date: %s\n#Query time: %s\n%s\n", date('r'), $time, $query)); ++ fclose($fh); ++ return array($query, $time, $backtrace); ++} ++ + ++$wpdb = new hyperdb(); ++if ( AI_DB_PROFILER === true ) { ++ $wpdb->save_queries = true; ++ $wpdb->save_query_callback = 'ai_log_db_queries'; ++} + require( DB_CONFIG_FILE );