type fixes
This commit is contained in:
@@ -52,7 +52,7 @@ class PortalOnlyAccount implements Filter
|
||||
{
|
||||
$orGroup = [];
|
||||
|
||||
$accountIdList = $this->user->getLinkMultipleIdList('accounts');
|
||||
$accountIdList = $this->user->getLinkMultipleIdList('accounts') ?? [];
|
||||
$contactId = $this->user->get('contactId');
|
||||
|
||||
if (count($accountIdList)) {
|
||||
|
||||
@@ -110,10 +110,10 @@ class Order
|
||||
if (!$order) {
|
||||
$order = $this->metadataProvider->getDefaultOrder($this->entityType);
|
||||
|
||||
if (strtolower($order) === 'desc') {
|
||||
if ($order && strtolower($order) === 'desc') {
|
||||
$order = SearchParams::ORDER_DESC;
|
||||
}
|
||||
else if (strtolower($order) === 'asc') {
|
||||
else if ($order && strtolower($order) === 'asc') {
|
||||
$order = SearchParams::ORDER_ASC;
|
||||
}
|
||||
else if ($order !== null) {
|
||||
|
||||
@@ -52,7 +52,7 @@ class FieldHelper
|
||||
|
||||
private function getSeed(): Entity
|
||||
{
|
||||
return $this->seed ?? $this->entityManager->getEntity($this->entityType);
|
||||
return $this->seed ?? $this->entityManager->getNewEntity($this->entityType);
|
||||
}
|
||||
|
||||
public function hasAssignedUsersField(): bool
|
||||
|
||||
@@ -216,7 +216,7 @@ class SearchParams
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function withWhere(?WhereItem $where): self
|
||||
public function withWhere(WhereItem $where): self
|
||||
{
|
||||
$obj = clone $this;
|
||||
|
||||
|
||||
@@ -186,6 +186,7 @@ class SelectBuilder
|
||||
|
||||
$this->applyAdditional();
|
||||
|
||||
/** @var QueryBuilder */
|
||||
return $this->queryBuilder;
|
||||
}
|
||||
|
||||
@@ -348,6 +349,9 @@ class SelectBuilder
|
||||
|
||||
private function applyPrimaryFilter(): void
|
||||
{
|
||||
assert($this->queryBuilder !== null);
|
||||
assert($this->primaryFilter !== null);
|
||||
|
||||
$this->createPrimaryFilterApplier()
|
||||
->apply(
|
||||
$this->queryBuilder,
|
||||
@@ -357,6 +361,8 @@ class SelectBuilder
|
||||
|
||||
private function applyBoolFilterList(): void
|
||||
{
|
||||
assert($this->queryBuilder !== null);
|
||||
|
||||
$this->createBoolFilterListApplier()
|
||||
->apply(
|
||||
$this->queryBuilder,
|
||||
@@ -366,6 +372,9 @@ class SelectBuilder
|
||||
|
||||
private function applyTextFilter(): void
|
||||
{
|
||||
assert($this->queryBuilder !== null);
|
||||
assert($this->textFilter !== null);
|
||||
|
||||
$noFullTextSearch = false;
|
||||
|
||||
if ($this->searchParams && $this->searchParams->noFullTextSearch()) {
|
||||
@@ -384,6 +393,8 @@ class SelectBuilder
|
||||
|
||||
private function applyAccessControlFilter(): void
|
||||
{
|
||||
assert($this->queryBuilder !== null);
|
||||
|
||||
$this->createAccessControlFilterApplier()
|
||||
->apply(
|
||||
$this->queryBuilder
|
||||
@@ -392,6 +403,8 @@ class SelectBuilder
|
||||
|
||||
private function applyDefaultOrder(): void
|
||||
{
|
||||
assert($this->queryBuilder !== null);
|
||||
|
||||
$order = null;
|
||||
|
||||
if ($this->searchParams) {
|
||||
@@ -419,6 +432,8 @@ class SelectBuilder
|
||||
|
||||
private function applyWhereItem(WhereItem $whereItem): void
|
||||
{
|
||||
assert($this->queryBuilder !== null);
|
||||
|
||||
$params = WhereParams::fromArray([
|
||||
'applyPermissionCheck' => $this->applyWherePermissionCheck,
|
||||
'forbidComplexExpressions' => $this->applyComplexExpressionsForbidden,
|
||||
@@ -438,6 +453,8 @@ class SelectBuilder
|
||||
return;
|
||||
}
|
||||
|
||||
assert($this->queryBuilder !== null);
|
||||
|
||||
if (
|
||||
!$this->applyDefaultOrder &&
|
||||
($this->searchParams->getOrderBy() || $this->searchParams->getOrder())
|
||||
@@ -483,6 +500,8 @@ class SelectBuilder
|
||||
|
||||
private function applyAdditional(): void
|
||||
{
|
||||
assert($this->queryBuilder !== null);
|
||||
|
||||
if (count($this->additionalApplierClassNameList) === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -506,6 +525,8 @@ class SelectBuilder
|
||||
|
||||
private function createWhereApplier(): WhereApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var WhereApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
@@ -516,6 +537,8 @@ class SelectBuilder
|
||||
|
||||
private function createSelectApplier(): SelectApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var SelectApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
@@ -526,6 +549,8 @@ class SelectBuilder
|
||||
|
||||
private function createOrderApplier(): OrderApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var OrderApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
@@ -536,6 +561,8 @@ class SelectBuilder
|
||||
|
||||
private function createLimitApplier(): LimitApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var LimitApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
@@ -546,6 +573,8 @@ class SelectBuilder
|
||||
|
||||
private function createAccessControlFilterApplier(): AccessControlFilterApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var AccessControlFilterApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
@@ -556,6 +585,8 @@ class SelectBuilder
|
||||
|
||||
private function createTextFilterApplier(): TextFilterApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var TextFilterApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
@@ -566,6 +597,8 @@ class SelectBuilder
|
||||
|
||||
private function createPrimaryFilterApplier(): PrimaryFilterApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var PrimaryFilterApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
@@ -576,6 +609,8 @@ class SelectBuilder
|
||||
|
||||
private function createBoolFilterListApplier(): BoolFilterListApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var BoolFilterListApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
@@ -586,6 +621,8 @@ class SelectBuilder
|
||||
|
||||
private function createAdditionalApplier(): AdditionalApplier
|
||||
{
|
||||
assert($this->entityType !== null);
|
||||
|
||||
/** @var AdditionalApplier */
|
||||
return $this->applierFactory->create(
|
||||
$this->entityType,
|
||||
|
||||
@@ -33,20 +33,28 @@ use InvalidArgumentException;
|
||||
|
||||
class FullTextSearchData
|
||||
{
|
||||
private ?string $expression = null;
|
||||
private string $expression;
|
||||
|
||||
/**
|
||||
* @var ?string[]
|
||||
* @var string[]
|
||||
*/
|
||||
private ?array $fieldList = null;
|
||||
private array $fieldList;
|
||||
|
||||
/**
|
||||
* @var ?string[]
|
||||
* @var string[]
|
||||
*/
|
||||
private ?array $columnList = null;
|
||||
private array $columnList;
|
||||
|
||||
private function __construct()
|
||||
/**
|
||||
* @param string $expression
|
||||
* @param string[] $fieldList
|
||||
* @param string[] $columnList
|
||||
*/
|
||||
public function __construct(string $expression, array $fieldList, array $columnList)
|
||||
{
|
||||
$this->expression = $expression;
|
||||
$this->fieldList = $fieldList;
|
||||
$this->columnList = $columnList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,9 +62,19 @@ class FullTextSearchData
|
||||
*/
|
||||
public static function fromArray(array $params): self
|
||||
{
|
||||
$object = new self();
|
||||
$expression = $params['expression'] ?? null;
|
||||
|
||||
$object->expression = $params['expression'] ?? null;
|
||||
if (!$expression || !is_string($expression)) {
|
||||
throw new InvalidArgumentException("Bad expression.");
|
||||
}
|
||||
|
||||
$object = new self(
|
||||
$expression,
|
||||
$params['fieldList'] ?? [],
|
||||
$params['columnList'] ?? []
|
||||
);
|
||||
|
||||
$object->expression = $expression;
|
||||
$object->fieldList = $params['fieldList'] ?? [];
|
||||
$object->columnList = $params['columnList'] ?? [];
|
||||
|
||||
@@ -66,10 +84,6 @@ class FullTextSearchData
|
||||
}
|
||||
}
|
||||
|
||||
if (!$object->expression || !is_string($object->expression)) {
|
||||
throw new InvalidArgumentException("Bad expression.");
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ class FullTextSearchDataComposer
|
||||
$filter = trim($filter);
|
||||
}
|
||||
|
||||
$expression = $function . ':(' . implode(', ', $fullTextSearchColumnList) . ', ' . "'{$filter}'" . ')';
|
||||
$expression = $function . ':(' . implode(', ', $fullTextSearchColumnList ?? []) . ', ' . "'{$filter}'" . ')';
|
||||
|
||||
return FullTextSearchData::fromArray([
|
||||
'expression' => $expression,
|
||||
|
||||
@@ -223,7 +223,7 @@ class Checker
|
||||
|
||||
private function getSeed(): Entity
|
||||
{
|
||||
return $this->seed ?? $this->entityManager->getEntity($this->entityType);
|
||||
return $this->seed ?? $this->entityManager->getNewEntity($this->entityType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ class Item
|
||||
|
||||
public const TYPE_OR = 'or';
|
||||
|
||||
private ?string $type = null;
|
||||
private string $type;
|
||||
|
||||
private ?string $attribute = null;
|
||||
|
||||
@@ -71,16 +71,24 @@ class Item
|
||||
self::TYPE_AND,
|
||||
];
|
||||
|
||||
private function __construct() {}
|
||||
private function __construct(string $type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $params
|
||||
*/
|
||||
public static function fromRaw(array $params): self
|
||||
{
|
||||
$obj = new self();
|
||||
$type = $params['type'] ?? null;
|
||||
|
||||
if (!$type) {
|
||||
throw new InvalidArgumentException("No 'type' in where item.");
|
||||
}
|
||||
|
||||
$obj = new self($type);
|
||||
|
||||
$obj->type = $params['type'] ?? null;
|
||||
$obj->attribute = $params['attribute'] ?? $params['field'] ?? null;
|
||||
$obj->value = $params['value'] ?? null;
|
||||
$obj->dateTime = $params['dateTime'] ?? false;
|
||||
@@ -94,10 +102,6 @@ class Item
|
||||
}
|
||||
}
|
||||
|
||||
if (!$obj->type) {
|
||||
throw new InvalidArgumentException("No 'type' in where item.");
|
||||
}
|
||||
|
||||
if (
|
||||
!$obj->attribute &&
|
||||
!in_array($obj->type, $obj->noAttributeTypeList)
|
||||
@@ -131,7 +135,6 @@ class Item
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array{
|
||||
* type: string,
|
||||
* value: mixed,
|
||||
@@ -142,7 +145,6 @@ class Item
|
||||
*/
|
||||
public function getRaw(): array
|
||||
{
|
||||
/** @var string */
|
||||
$type = $this->type;
|
||||
|
||||
$raw = [
|
||||
@@ -170,6 +172,8 @@ class Item
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
assert($this->type !== null);
|
||||
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ class Scanner
|
||||
private function getSeed(string $entityType): Entity
|
||||
{
|
||||
if (!isset($this->seedHash[$entityType])) {
|
||||
$this->seedHash[$entityType] = $this->entityManager->getEntity($entityType);
|
||||
$this->seedHash[$entityType] = $this->entityManager->getNewEntity($entityType);
|
||||
}
|
||||
|
||||
return $this->seedHash[$entityType];
|
||||
|
||||
@@ -65,13 +65,13 @@ class CheckerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->any())
|
||||
->method('getEntity')
|
||||
->method('getNewEntity')
|
||||
->with($this->entityType)
|
||||
->willReturn($this->entity);
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->any())
|
||||
->method('getEntity')
|
||||
->method('getNewEntity')
|
||||
->with($this->foreignEntityType)
|
||||
->willReturn($this->foreignEntity);
|
||||
}
|
||||
|
||||
@@ -30,14 +30,12 @@
|
||||
namespace tests\unit\Espo\Core\Select\Where;
|
||||
|
||||
use Espo\{
|
||||
Core\Exceptions\Error,
|
||||
Core\Select\Where\Scanner,
|
||||
Core\Select\Where\Item,
|
||||
ORM\EntityManager,
|
||||
ORM\BaseEntity as Entity,
|
||||
ORM\Query\Select as Query,
|
||||
ORM\Query\SelectBuilder as QueryBuilder,
|
||||
ORM\QueryComposer\BaseQueryComposer as QueryComposer,
|
||||
};
|
||||
|
||||
class ScannerTest extends \PHPUnit\Framework\TestCase
|
||||
@@ -68,7 +66,7 @@ class ScannerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->any())
|
||||
->method('getEntity')
|
||||
->method('getNewEntity')
|
||||
->with($this->entityType)
|
||||
->willReturn($this->entity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user