diff --git a/.travis.yml b/.travis.yml index 890e1c30..a1fa5f95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ env: matrix: include: - php: 7.0 - env: WP_VERSION= + env: WP_VERSION= DB_CHARSET=utf8mb4 - php: 5.3 env: WP_VERSION= - php: 5.4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aad1b7b..35a43606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ ## Changelog ## +### 0.21.10 ### + +Improve database charset operations + +* If your DB_CHARSET was set to utf8mb4, then you could have issues in plugin activation +* If your DB_CHARSET was set to latin1, then you could have issues with scales showing + +To completely clear DB from wp-testing in case of activation issues you can use the script: + + https://github.com/garex/wp-testing/blob/master/db/sql/drop-all.sql + + +This hotfix is mostly for those, who was having troubles with plugin activation. + + ### 0.21.9 ### Update readme to latest plugin directory format. diff --git a/README.md b/README.md index b8391831..b7970e7a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ **Tested up to:** 4.9 -**Stable tag:** 0.21.9 +**Stable tag:** 0.21.10 **License:** GPLv3 diff --git a/composer.json b/composer.json index 85f8af23..c682c8d2 100644 --- a/composer.json +++ b/composer.json @@ -149,10 +149,10 @@ "source": { "url": "https://github.com/garex/flourish-classes", "type": "git", - "reference": "0a5b2536d9736b6fe12d8ab1b8f9ad341d2397bf" + "reference": "c826410c3edb9da885e70c6f05d714b357fb2a4a" }, "dist": { - "url": "https://github.com/garex/flourish-classes/archive/0a5b2536d9736b6fe12d8ab1b8f9ad341d2397bf.zip", + "url": "https://github.com/garex/flourish-classes/archive/c826410c3edb9da885e70c6f05d714b357fb2a4a.zip", "type": "zip" } } diff --git a/composer.lock.dist b/composer.lock.dist index 895230a1..bbf939c9 100644 --- a/composer.lock.dist +++ b/composer.lock.dist @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "617c766c15cc0c7a37ad96d17b98cf6c", - "content-hash": "a29878b55574f5f4db7e877534d849b9", + "hash": "3609284e2b5a713f8a7eb70c8d29e467", + "content-hash": "a7d9019a859b7d6219377847c504cb4d", "packages": [ { "name": "broofa/node-uuid", @@ -18,7 +18,7 @@ "dist": { "type": "zip", "url": "https://github.com/broofa/node-uuid/archive/v1.4.7.zip", - "reference": null, + "reference": "309512573ec1c60143c257157479a20f7f1f51cd", "shasum": null }, "type": "library" @@ -124,12 +124,12 @@ "source": { "type": "git", "url": "https://github.com/garex/flourish-classes", - "reference": "0a5b2536d9736b6fe12d8ab1b8f9ad341d2397bf" + "reference": "c826410c3edb9da885e70c6f05d714b357fb2a4a" }, "dist": { "type": "zip", - "url": "https://github.com/garex/flourish-classes/archive/0a5b2536d9736b6fe12d8ab1b8f9ad341d2397bf.zip", - "reference": null, + "url": "https://github.com/garex/flourish-classes/archive/c826410c3edb9da885e70c6f05d714b357fb2a4a.zip", + "reference": "c826410c3edb9da885e70c6f05d714b357fb2a4a", "shasum": null }, "type": "library", @@ -138,7 +138,7 @@ "." ] }, - "time": "2015-09-27 06:52:10" + "time": "2018-03-18 16:33:05" }, { "name": "nikic/php-parser", @@ -196,7 +196,7 @@ "dist": { "type": "zip", "url": "https://github.com/garex/ruckusing-migrations/archive/issue/avoid-schema-constant.zip", - "reference": null, + "reference": "issue/avoid-schema-constant", "shasum": null }, "require": { @@ -224,7 +224,7 @@ "dist": { "type": "zip", "url": "https://github.com/samyk/evercookie/archive/977db236367c509ce6b10fb565ed5a75c8d729d5.zip", - "reference": null, + "reference": "977db236367c509ce6b10fb565ed5a75c8d729d5", "shasum": null }, "type": "library", diff --git a/db/migrations/wp_testing/Base/Base.php b/db/migrations/wp_testing/Base/Base.php index 1ac42239..6c3a770b 100644 --- a/db/migrations/wp_testing/Base/Base.php +++ b/db/migrations/wp_testing/Base/Base.php @@ -46,6 +46,8 @@ abstract public function down(); public function execute($query) { + $this->adaptee->get_adapter()->logger->log(trim($query, ';') . ';'); + return $this->adaptee->execute($query); } diff --git a/db/sql/drop-all.sql b/db/sql/drop-all.sql index f1b44106..5669ab88 100644 --- a/db/sql/drop-all.sql +++ b/db/sql/drop-all.sql @@ -1,35 +1,31 @@ --- SHOW TABLE STATUS; +-- All table names here use default table prefix "wp_" +-- It's defined in your wp-config.php by string like: +-- $table_prefix = 'wp_'; +-- If your setting not default, then just replace in this script "wp_" onto your setting. --- DROP SCHEMA IF EXISTS wp_testing2; CREATE SCHEMA wp_testing2; - --- USE wp_testing; +-- !!! WARNING !!! +-- This script will erase completely your's database part, related to wp-testing plugin. +-- So if you alerady has some tests/passings/scores, then you must not run this script. +-- !!! WARNING !!! SET FOREIGN_KEY_CHECKS = 0; -DROP TABLE IF EXISTS wp_t_answers; -DROP TABLE IF EXISTS wp_t_answers_parameters; -DROP TABLE IF EXISTS wp_t_parameters; -DROP TABLE IF EXISTS wp_t_questions; -DROP TABLE IF EXISTS wp_t_scales; -DROP TABLE IF EXISTS wp_t_scales_tests; DROP TABLE IF EXISTS wp_t_schema_migrations; -DROP TABLE IF EXISTS wp_t_tests; - +DROP TABLE IF EXISTS wp_t_field_values; DROP TABLE IF EXISTS wp_t_formulas; DROP TABLE IF EXISTS wp_t_passing_answers; DROP TABLE IF EXISTS wp_t_passings; DROP TABLE IF EXISTS wp_t_scores; +DROP TABLE IF EXISTS wp_t_sections; +DROP TABLE IF EXISTS wp_t_answers; +DROP TABLE IF EXISTS wp_t_fields; +DROP TABLE IF EXISTS wp_t_questions; +DROP TABLE IF EXISTS wp_t_computed_variables; SET FOREIGN_KEY_CHECKS = 1; -DELETE FROM wp_posts WHERE post_title LIKE '%EPI%'; -DELETE FROM wp_terms WHERE term_id > 1; -DELETE FROM wp_postmeta WHERE post_id NOT IN ( - SELECT ID FROM wp_posts -); - -DELETE FROM wp_term_relationships WHERE object_id NOT IN ( - SELECT ID FROM wp_posts -); -DELETE FROM wp_term_taxonomy where taxonomy like 'wpt\_%'; - +DELETE FROM wp_postmeta where meta_key like 'wpt_%'; +DELETE FROM wp_posts WHERE post_type = 'wpt_test'; +DELETE FROM wp_term_taxonomy where taxonomy like 'wpt_%'; +DELETE FROM wp_term_relationships WHERE term_taxonomy_id NOT IN (SELECT term_taxonomy_id FROM wp_term_taxonomy); +DELETE FROM wp_terms WHERE term_id NOT IN (SELECT term_id FROM wp_term_taxonomy); diff --git a/src/Doer/Installer.php b/src/Doer/Installer.php index 36a913e1..fba47757 100644 --- a/src/Doer/Installer.php +++ b/src/Doer/Installer.php @@ -112,7 +112,8 @@ private function setNetworkWide($value = null) private function upgradeOnBlog() { - $this->migrateDatabase(array(__FILE__, 'db:migrate')); + $this->migrateDatabase(array(__FILE__, 'db:setup', 'env=fixed-charset')); + $this->migrateDatabase(array(__FILE__, 'db:migrate', 'env=development')); new WpTesting_Doer_WordPressEntitiesRegistrator($this->wp); $this->flushRewrite(); } @@ -183,11 +184,15 @@ private function migrateDatabase($argv) 'pluginPrefix' => $wptPrefix, 'schema_version_table_name' => $wptPrefix . 'schema_migrations', ), + 'fixed-charset' => array( + 'charset' => 'utf8', + ), ), 'db_dir' => $databaseDirectory, 'migrations_dir' => array('default' => $databaseDirectory . '/migrations'), 'log_dir' => $this->wp->getTempDir() . 'wp_testing_' . md5(__FILE__), ); + $config['db']['fixed-charset'] = array_merge($config['db']['development'], $config['db']['fixed-charset']); $runner = new Ruckusing_FrameworkRunner($config, $argv); restore_error_handler(); diff --git a/src/Facade.php b/src/Facade.php index 2fc93ff5..c25e4bfa 100644 --- a/src/Facade.php +++ b/src/Facade.php @@ -224,11 +224,21 @@ public function setupORM() // Extract port from host. See wpdb::db_connect $port = null; $host = $this->wp->getDbHost(); + $m = array(); if (preg_match('/^(.+):(\d+)$/', trim($host), $m)) { $host = $m[1]; $port = $m[2]; } - $database = new fDatabase('mysql', $this->wp->getDbName(), $this->wp->getDbUser(), $this->wp->getDbPassword(), $host, $port); + $database = new fDatabase( + 'mysql', + $this->wp->getDbName(), + $this->wp->getDbUser(), + $this->wp->getDbPassword(), + $host, + $port, + null, + $this->wp->getDbCharset() + ); fORMDatabase::attach($database); fORM::mapClassToTable('WpTesting_Model_Test', $wpPrefix . 'posts'); diff --git a/tests/integration-environment/create.sh b/tests/integration-environment/create.sh index 65a04fb6..88fa29dd 100755 --- a/tests/integration-environment/create.sh +++ b/tests/integration-environment/create.sh @@ -91,7 +91,7 @@ function install_wp { log '.. patching wordpress' patch -p0 < $WP_PATCH fi - cp ../wp-config.php wp-config.php + cat ../wp-config.php | sed 's/utf8/'$DB_CHARSET'/' > wp-config.php log '.. installing' wget --quiet --output-document=- --post-data='weblog_title=wpti&user_name=wpti&admin_password=wpti&admin_password2=wpti&admin_email=wpti%40wpti.dev&blog_public=1' $WP_T_SERVER'/wp-admin/install.php?step=2' | grep installed } diff --git a/tests/phpunit/Mock/WordPressFacade.php b/tests/phpunit/Mock/WordPressFacade.php index 42c768d4..96d6686a 100644 --- a/tests/phpunit/Mock/WordPressFacade.php +++ b/tests/phpunit/Mock/WordPressFacade.php @@ -38,7 +38,7 @@ public function getTablePrefix() public function getDbCharset() { - return 'utf-8'; + return $this->db['charset']; } public function isMultisite() @@ -154,6 +154,7 @@ public function getExtended($post) // Version from 4.3 // Match the new style more links. + $matches = array(); if (preg_match('//', $post, $matches)) { list($main, $extended) = explode($matches[0], $post, 2); $more_text = $matches[1]; diff --git a/tests/phpunit/Model/QuestionTest.php b/tests/phpunit/Model/QuestionTest.php index 3f0e604e..41f1125c 100644 --- a/tests/phpunit/Model/QuestionTest.php +++ b/tests/phpunit/Model/QuestionTest.php @@ -21,8 +21,6 @@ protected function tearDown() public function testQuestionSavedInUtfEncoding() { - $link = $this->db->getConnection(); - $question = new WpTesting_Model_Question(); $question->setTitle('راهنمایی برای ایجاد آزمون های روانشناسی.')->setTestId(1); $id = $question->store()->getId(); diff --git a/wp-testing.php b/wp-testing.php index 4a0005b9..0305120c 100644 --- a/wp-testing.php +++ b/wp-testing.php @@ -3,7 +3,7 @@ * Plugin Name: Wp-testing * Plugin URI: http://wordpress.org/extend/plugins/wp-testing/ * Description: Helps to create psychological tests. - * Version: 0.21.9 + * Version: 0.21.10 * Author: Alexander Ustimenko * Author URI: http://ustimen.co * License: GPL3