Skip to content

Commit

Permalink
bug #23 Fix detection of QueryPlatform (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.0-dev branch.

Discussion
----------

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | Closes rollerworks/search#178
| License       | MIT
| Doc PR        | 

Commits
-------

7847fbb Fix detection of QueryPlatform
dd3ac69 Run travis with all groups
  • Loading branch information
sstok authored Oct 17, 2017
2 parents a335cf0 + dd3ac69 commit c71aed6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ before_script:
script:
- export SYMFONY_DEPRECATIONS_HELPER=strict
- vendor/bin/phpunit --verbose
- if [ "$DB" != "" ] && [ "$DB" != "sqlite" ]; then vendor/bin/simple-phpunit --configuration tests/travis/$DB.travis.xml --exclude-group non-functional; fi;
- if [ "$DB" = "sqlite" ]; then vendor/bin/simple-phpunit --configuration tests/travis/sqlite.travis.xml; fi;
- if [ "$DB" != "" ]; then vendor/bin/simple-phpunit --configuration tests/travis/$DB.travis.xml; fi;
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
- if [[ $lint = 1 ]]; then phpstan analyse -c phpstan.neon -l5 --ansi src tests; fi
5 changes: 1 addition & 4 deletions src/CachedDqlConditionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ public function getWhereClause(string $prependQuery = ''): string
if (null === $this->whereClause) {
$cacheKey = $this->getCacheKey();

$this->nativePlatform = $this->getQueryPlatform(
$this->conditionGenerator->getEntityManager()->getConnection(),
$this->conditionGenerator->getFieldsConfig()->getFields()
);
$this->nativePlatform = $this->getQueryPlatform($this->conditionGenerator->getEntityManager()->getConnection());

if (null !== $cacheItem = $this->cacheDriver->get($cacheKey)) {
list($this->whereClause, $this->parameters) = $cacheItem;
Expand Down
2 changes: 1 addition & 1 deletion src/DqlConditionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getWhereClause(string $prependQuery = ''): string
$connection = $this->entityManager->getConnection();
$queryGenerator = new QueryGenerator($connection, $platform, $fields);

$this->nativePlatform = $this->getQueryPlatform($connection, $fields);
$this->nativePlatform = $this->getQueryPlatform($connection);
$this->whereClause = $queryGenerator->getGroupQuery($this->searchCondition->getValuesGroup());
$this->parameters = $platform->getEmbeddedValues();
}
Expand Down
2 changes: 1 addition & 1 deletion src/NativeQueryConditionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getWhereClause(string $prependQuery = ''): string
$fields = $this->fieldsConfig->getFields();
$connection = $this->entityManager->getConnection();

$queryGenerator = new QueryGenerator($connection, $this->getQueryPlatform($connection, $fields), $fields);
$queryGenerator = new QueryGenerator($connection, $this->getQueryPlatform($connection), $fields);
$this->whereClause = $queryGenerator->getGroupQuery($this->searchCondition->getValuesGroup());
}

Expand Down
15 changes: 4 additions & 11 deletions src/QueryPlatformTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,22 @@

use Doctrine\DBAL\Connection;
use Rollerworks\Component\Search\Doctrine\Dbal\QueryPlatform;
use Rollerworks\Component\Search\Doctrine\Dbal\QueryPlatform\SqlQueryPlatform;

/**
* @internal
*/
trait QueryPlatformTrait
{
/**
* Gets the QueryPlatform based on the connection.
*
* @param Connection $connection
* @param array $fields
*
* @return QueryPlatform
*/
protected function getQueryPlatform(Connection $connection, array $fields): QueryPlatform
protected function getQueryPlatform(Connection $connection): QueryPlatform
{
$dbPlatform = ucfirst($connection->getDatabasePlatform()->getName());
$platformClass = 'Rollerworks\\Component\\Search\\Doctrine\\Dbal\\QueryPlatform\\'.$dbPlatform.'QueryPlatform';

if (class_exists($platformClass)) {
return new $platformClass($connection, $fields);
return new $platformClass($connection);
}

throw new \RuntimeException(sprintf('No supported class found for database-platform "%s".', $dbPlatform));
return new SqlQueryPlatform($connection);
}
}

0 comments on commit c71aed6

Please sign in to comment.