Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recognize new mariadb specific queries in the custom WordPress database adapter #1237

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion classes/WpMatomo/Db/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ public function query( $sql, $bind = array() ) {
$test_sql = trim( $test_sql );
}

if ( preg_match( '/^\s*(select)\s/i', $test_sql ) ) {
if (
preg_match( '/^\s*(select)\s/i', $test_sql )
|| preg_match( '/\sfor select\s/i', $test_sql )
) {
// WordPress does not fetch any result when doing a query w/ a select... it's only supposed to be used for things like
// insert / update / drop ...
$result = $this->fetchAll( $sql, $bind );
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/wpmatomo/db/test-wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,29 @@ public function test_update_sets_null_values_correctly_when_all_params_are_null(
$this->assertNull( $row['message'] );
}

public function test_query_recognizes_mariadb_set_for_queries() {
\Piwik\Config::getInstance()->database['schema'] = 'Mariadb';
\Piwik\Db\Schema::unsetInstance();

$params = new \Piwik\ArchiveProcessor\Parameters(
new \Piwik\Site( 1 ),
\Piwik\Period\Factory::build( 'day', 'today' ),
new \Piwik\Segment( '', [ 1 ] )
);
$log_aggregator = new \Piwik\DataAccess\LogAggregator( $params );

$sql = $log_aggregator->getQueryByDimensionSql( [], false, [], false, false, false, 120, false );

// make sure SQL we're testing has MariaDB specific SQL
$this->assertStringContainsString( 'SET STATEMENT max_statement_time', $sql['sql'] );

// test that the query works in MWP
$statement = $log_aggregator->queryVisitsByDimension( [], false, [], false, false, false, 120, false );
$row = $statement->fetch();

$this->assertIsArray( $row );
}

private function insert_many_values() {
$this->insert_access( 'foo', 'view' );
$this->insert_access( 'bar', 'write' );
Expand Down
Loading