Skip to content

Commit

Permalink
Further cleanup & fix of showcase editability in postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
WellinqScience1337 committed Oct 5, 2020
1 parent d3b2e2b commit fea65d4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 1 addition & 3 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ doctrine:
alias: App
dql:
string_functions:
JSON_EXTRACT: Bolt\Doctrine\Functions\JsonExtract # Why have a duplicate of the Scienta version?
# JSON_EXTRACT_PATH: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Postgresql\JsonExtractPath
JSON_EXTRACT: Bolt\Doctrine\Functions\JsonExtract
JSON_GET_TEXT: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Postgresql\JsonGetText
# CAST: DoctrineExtensions\Query\Mysql\Cast
CAST: Bolt\Doctrine\Query\Cast
numeric_functions:
RAND: Bolt\Doctrine\Functions\Rand
Expand Down
9 changes: 7 additions & 2 deletions src/Doctrine/Query/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ class Cast extends FunctionNode
public function getSql(SqlWalker $sqlWalker): string
{
$backend_driver = $sqlWalker->getConnection()->getDriver()->getName();

// test if we are using MySQL
if (mb_strpos($backend_driver, 'mysql') !== false) {
// YES we are using MySQL
// how do we know what type $this->first is? For now hardcoding
// type(t.value) = JSON for MySQL. JSONB for others.
// alternatively, test if true: $this->first->dispatch($sqlWalker)==='b2_.value'
if ($this->first->identificationVariable === 't' && $this->first->field === 'value' && $this->second === 'TEXT') {
// alternatively, test if true: $this->first->dispatch($sqlWalker)==='b2_.value',
// b4_.value for /bolt/new/showcases
if ($this->first->dispatch($sqlWalker)==='b2_.value' ||
$this->first->dispatch($sqlWalker)==='b4_.value')
{
return $this->first->dispatch($sqlWalker);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Storage/Directive/OrderDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ private function setOrderBy(QueryInterface $query, string $order, string $direct
} else {
// Note the `lower()` in the `addOrderBy()`. It is essential to sorting the
// results correctly. See also https://github.com/bolt/core/issues/1190
// again: lower breaks postgresql jsonb compatibility, first cast as txt
$query
->getQueryBuilder()
->addOrderBy('lower(' . $translationsAlias . '.value)', $direction);
->addOrderBy('lower(CAST(' . $translationsAlias . '.value as TEXT))', $direction);
}
$query->incrementIndex();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/SelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private function getRegularFieldExpression(Filter $filter, EntityManagerInterfac
$originalLeftExpression = 'content.' . $filter->getKey();
// LOWER() added to query to enable case insensitive search of JSON values. Used in conjunction with converting $params of setParameter() to lowercase.
// BUG SQLSTATE[42883]: Undefined function: 7 ERROR: function lower(jsonb) does not exist
// We want to be able to search case-insensitive, database-agnostic, have to think of a good way..
// We want to be able to search case-insensitive, database-agnostic, have to think of a good way..
$newLeftExpression = JsonHelper::wrapJsonFunction($valueAlias, null, $em->getConnection());
$valueWhere = $filter->getExpression();
$valueWhere = str_replace($originalLeftExpression, $newLeftExpression, $valueWhere);
Expand Down
6 changes: 3 additions & 3 deletions templates/helpers/_field_blocks.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@

{# Special case for 'select' fields: if it's a multiple select, the field is an array. #}
{# I dont know what is going on here, but field.selectedIds for pgsql showcase/mr-jean-feeney (and others) #}
{# yield field values, NOT integer IDs.. Also, selectedIds does not exists (try dump(field) ) #}
{# TODO: FIX IT, bypassing for now by setting field.id #}
{# yield field values (strings containing full name!), NOT integer IDs.. #}
{# TODO: FIX IT, bypassing for now by selecting on 'value' (string) and not 'id' (int) #}
{% if type == "select" and field is not empty %}
<p><strong>{{ field|label }}: </strong></p>
<ul>
{% if field.contentSelect %}
{% setcontent selected = field.contentType where {'id': field.id} %}
{% setcontent selected = field.contentType where {'value': field.selectedIds} %}
{% for record in selected %}
<li><a href="{{ record|link }}">{{ record|title }}</a></li>
{% endfor %}
Expand Down

0 comments on commit fea65d4

Please sign in to comment.