Skip to content

Commit

Permalink
Merge pull request #1212 from matomo-org/collate-charset-override
Browse files Browse the repository at this point in the history
allow users to override charset/collation used for Matomo tables via two new consts
  • Loading branch information
diosmosis authored Nov 13, 2024
2 parents f6a27e8 + 70444e0 commit cbf2afa
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
9 changes: 8 additions & 1 deletion classes/WpMatomo/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,15 @@ public static function get_db_infos( $default = [] ) {
}
}

$charset = $wpdb->charset ? $wpdb->charset : 'utf8';
$charset = $wpdb->charset ? $wpdb->charset : 'utf8';
if ( defined( 'MATOMO_DB_CHARSET' ) && MATOMO_DB_CHARSET ) {
$charset = MATOMO_DB_CHARSET;
}

$collation = $wpdb->collate ? $wpdb->collate : 'utf8mb4_general_ci';
if ( defined( 'MATOMO_DB_COLLATE' ) && MATOMO_DB_COLLATE ) {
$collation = MATOMO_DB_COLLATE;
}

$database = [
'host' => $host,
Expand Down
2 changes: 1 addition & 1 deletion matomo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Version: 5.1.5
* Domain Path: /languages
* WC requires at least: 2.4.0
* WC tested up to: 9.3.3
* WC tested up to: 9.4.1
*
* Matomo - free/libre analytics platform
*
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: matomoteam
Tags: matomo,analytics,statistics,stats,ecommerce
Requires at least: 4.8
Tested up to: 6.6.2
Tested up to: 6.7.0
Stable tag: 5.1.5
Requires PHP: 7.2.5
License: GPLv3 or later
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/framework/test-case.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @package matomo
*/

use \WpMatomo\Capabilities;
require_once __DIR__ . '/fixture/test-wordpress-fixture.php';

/**
* phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/framework/test-matomo-test-case.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use WpMatomo\Uninstaller;
use WpMatomo\User;

require_once __DIR__ . '/fixture/test-matomo-fixture.php';

/**
* Piwik constants
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
Expand Down
20 changes: 20 additions & 0 deletions tests/phpunit/wpmatomo/test-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,24 @@ public function test_install_also_installs_on_other_blog() {
$this->assertCount( 1, $all_sites );
}

/**
* @preserveGlobalState disabled
* @runInSeparateProcess
*/
public function test_get_db_infos_respects_charset_overrides() {
global $wpdb;

$db_config = Installer::get_db_infos();

$this->assertEquals( $wpdb->charset ? $wpdb->charset : 'utf8', $db_config['charset'] );
$this->assertEquals( $wpdb->collate ? $wpdb->collate : 'utf8mb4_general_ci', $db_config['collation'] );

define( 'MATOMO_DB_CHARSET', 'dummycharset' );
define( 'MATOMO_DB_COLLATE', 'dummycollate' );

$db_config = Installer::get_db_infos();

$this->assertEquals( 'dummycharset', $db_config['charset'] );
$this->assertEquals( 'dummycollate', $db_config['collation'] );
}
}
11 changes: 9 additions & 2 deletions tests/phpunit/wpmatomo/test-release.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function test_wordpress_tested_up_to_is_latest() {

$tested_up_to_version = $matches[1];

$this->assertEquals( $latest_version, $tested_up_to_version );
$this->assertTrue( $this->compare_version( $latest_version, $tested_up_to_version ), "Tested up to version ($tested_up_to_version) does not match ($latest_version)." );
}

public function test_woocommerce_tested_up_to_is_latest() {
Expand All @@ -294,7 +294,7 @@ public function test_woocommerce_tested_up_to_is_latest() {

$tested_up_to_version = $matches[1];

$this->assertEquals( $latest_version, $tested_up_to_version );
$this->assertTrue( $this->compare_version( $latest_version, $tested_up_to_version ), "Tested up to version ($tested_up_to_version) does not match latest version ($latest_version)." );
}

private function get_zip_file_contents( $path_to_zip ) {
Expand Down Expand Up @@ -329,4 +329,11 @@ private function execute_command( $command ) {
$output = implode( '\n', $output );
return [ $return_code, $output ];
}

private function compare_version( $latest_version, $tested_up_to_version ) {
$latest_version = rtrim( $latest_version, '.0' );
$tested_up_to_version = rtrim( $tested_up_to_version, '.0' );

return version_compare( $latest_version, $tested_up_to_version, '==' );
}
}

0 comments on commit cbf2afa

Please sign in to comment.