Skip to content

Commit

Permalink
Merge pull request #4807 from craftcms/feature/param-column-type
Browse files Browse the repository at this point in the history
Update parseParam to accept columnType argument

Fixes #4808
  • Loading branch information
brandonkelly committed Aug 23, 2019
2 parents ea302c3 + 5724810 commit e450131
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Section and Matrix “Propagation Method” settings now display warnings about the potential for data loss when appropriate.
- Entries’ drafts and revisions are now soft-deleted and restored along with their source elements. ([#4797](https://github.com/craftcms/cms/issues/4797))
- `craft\behaviors\DraftBehavior::getCreator()` can now return `null`.
- `craft\helpers\Db::parseParam()` now has an optional `$columnType` argument. ([#4807](https://github.com/craftcms/cms/pull/4807))

### Removed
- Removed `craft\base\ElementInterface::getSource()`. ([#4754](https://github.com/craftcms/cms/issues/4754))
Expand All @@ -31,6 +32,7 @@
- Fixed an error that occurred when editing an entry with a draft that was created by a soft-deleted user. ([#4800](https://github.com/craftcms/cms/issues/4800))
- Fixed a bug where entry revisions and drafts would be deleted when the user that created them was hard-deleted.
- Fixed a SQL error that could occur when executing an element query that had custom `JOIN` and `WHERE` clauses if the `search` param was also set. ([#4788](https://github.com/craftcms/cms/issues/4788))
- Fixed a SQL error that could occur when `:empty:` or `not :empty:` was passed to a date param on an element query when running MySQL 8. ([#4808](https://github.com/craftcms/cms/issues/4808))

## 3.2.10 - 2019-08-13

Expand Down
12 changes: 8 additions & 4 deletions src/helpers/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,10 @@ public static function escapeParam(string $value): string
* @param string $defaultOperator The default operator to apply to the values
* (can be `not`, `!=`, `<=`, `>=`, `<`, `>`, or `=`)
* @param bool $caseInsensitive Whether the resulting condition should be case-insensitive
* @param string|null $columnType The database column type the param is targeting
* @return mixed
*/
public static function parseParam(string $column, $value, string $defaultOperator = '=', $caseInsensitive = false)
public static function parseParam(string $column, $value, string $defaultOperator = '=', bool $caseInsensitive = false, string $columnType = null)
{
if (is_string($value) && preg_match('/^not\s*$/', $value)) {
return '';
Expand Down Expand Up @@ -484,14 +485,17 @@ public static function parseParam(string $column, $value, string $defaultOperato
$operator = self::_parseParamOperator($val, $defaultOperator, $negate);

if ($val === ':empty:') {
if ($isMysql) {
// If this is a textual column type, also check for empty strings
if (
($columnType === null && $isMysql) ||
static::isTextualColumnType($columnType)
) {
$valCondition = [
'or',
[$column => null],
[$column => '']
];
} else {
// Because PostgreSQL chokes if you do a string check on an int column
$valCondition = [$column => null];
}
if ($operator === '!=') {
Expand Down Expand Up @@ -605,7 +609,7 @@ public static function parseDateParam(string $column, $value, string $defaultOpe
$normalizedValues[] = $operator . static::prepareDateForDb($val);
}

return static::parseParam($column, $normalizedValues);
return static::parseParam($column, $normalizedValues, $defaultOperator, false, Schema::TYPE_DATETIME);
}

/**
Expand Down

0 comments on commit e450131

Please sign in to comment.