This commit is contained in:
Yuri Kuznetsov
2024-10-29 21:41:58 +02:00
parent 2c6dd05ec8
commit ec021fb63b
20 changed files with 81 additions and 126 deletions

View File

@@ -31,6 +31,7 @@ namespace Espo\Classes\DefaultLayouts;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Utils\Metadata;
use Espo\Entities\Team;
use Espo\Entities\User;
use stdClass;
@@ -47,18 +48,18 @@ class DefaultSidePanelType
$list = [];
if (
$this->metadata->get(['entityDefs', $scope, 'fields', 'assignedUser', 'type']) === 'link' &&
$this->metadata->get(['entityDefs', $scope, 'links', 'assignedUser', 'entity']) === 'User'
$this->metadata->get(['entityDefs', $scope, 'fields', 'assignedUser', 'type']) === FieldType::LINK &&
$this->metadata->get(['entityDefs', $scope, 'links', 'assignedUser', 'entity']) === User::ENTITY_TYPE
||
$this->metadata->get(['entityDefs', $scope, 'fields', 'assignedUsers', 'type']) === 'linkMultiple' &&
$this->metadata->get(['entityDefs', $scope, 'links', 'assignedUsers', 'entity']) === 'User'
$this->metadata->get(['entityDefs', $scope, 'fields', 'assignedUsers', 'type']) === FieldType::LINK_MULTIPLE &&
$this->metadata->get(['entityDefs', $scope, 'links', 'assignedUsers', 'entity']) === User::ENTITY_TYPE
) {
$list[] = (object) ['name' => ':assignedUser'];
}
if (
$this->metadata->get(['entityDefs', $scope, 'fields', 'teams', 'type']) === 'linkMultiple' &&
$this->metadata->get(['entityDefs', $scope, 'links', 'teams', 'entity']) === 'Team'
$this->metadata->get(['entityDefs', $scope, 'fields', 'teams', 'type']) === FieldType::LINK_MULTIPLE &&
$this->metadata->get(['entityDefs', $scope, 'links', 'teams', 'entity']) === Team::ENTITY_TYPE
) {
$list[] = (object) ['name' => 'teams'];
}

View File

@@ -29,27 +29,20 @@
namespace Espo\Core\Acl;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Utils\Metadata;
use Espo\Entities\User;
use Espo\ORM\Defs;
class OwnerUserFieldProvider
{
protected const FIELD_ASSIGNED_USERS = 'assignedUsers';
protected const FIELD_ASSIGNED_USER = 'assignedUser';
protected const FIELD_CREATED_BY = 'createdBy';
private $ormDefs;
private $metadata;
public function __construct(Defs $ormDefs, Metadata $metadata)
{
$this->ormDefs = $ormDefs;
$this->metadata = $metadata;
}
public function __construct(private Defs $ormDefs, private Metadata $metadata)
{}
/**
* Get an entity field that stores an owner-user (or multiple users).
@@ -67,27 +60,27 @@ class OwnerUserFieldProvider
if (
$defs->hasField(self::FIELD_ASSIGNED_USERS) &&
$defs->getField(self::FIELD_ASSIGNED_USERS)->getType() === 'linkMultiple' &&
$defs->getField(self::FIELD_ASSIGNED_USERS)->getType() === FieldType::LINK_MULTIPLE &&
$defs->hasRelation(self::FIELD_ASSIGNED_USERS) &&
$defs->getRelation(self::FIELD_ASSIGNED_USERS)->getForeignEntityType() === 'User'
$defs->getRelation(self::FIELD_ASSIGNED_USERS)->getForeignEntityType() === User::ENTITY_TYPE
) {
return self::FIELD_ASSIGNED_USERS;
}
if (
$defs->hasField(self::FIELD_ASSIGNED_USER) &&
$defs->getField(self::FIELD_ASSIGNED_USER)->getType() === 'link' &&
$defs->getField(self::FIELD_ASSIGNED_USER)->getType() === FieldType::LINK &&
$defs->hasRelation(self::FIELD_ASSIGNED_USER) &&
$defs->getRelation(self::FIELD_ASSIGNED_USER)->getForeignEntityType() === 'User'
$defs->getRelation(self::FIELD_ASSIGNED_USER)->getForeignEntityType() === User::ENTITY_TYPE
) {
return self::FIELD_ASSIGNED_USER;
}
if (
$defs->hasField(self::FIELD_CREATED_BY) &&
$defs->getField(self::FIELD_CREATED_BY)->getType() === 'link' &&
$defs->getField(self::FIELD_CREATED_BY)->getType() === FieldType::LINK &&
$defs->hasRelation(self::FIELD_CREATED_BY) &&
$defs->getRelation(self::FIELD_CREATED_BY)->getForeignEntityType() === 'User'
$defs->getRelation(self::FIELD_CREATED_BY)->getForeignEntityType() === User::ENTITY_TYPE
) {
return self::FIELD_CREATED_BY;
}

View File

@@ -29,6 +29,7 @@
namespace Espo\Core\Field\LinkMultiple;
use Espo\Core\ORM\Type\FieldType;
use Espo\ORM\Defs;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
@@ -57,7 +58,7 @@ class LinkMultipleFactory implements ValueFactory
return false;
}
return $entityDefs->getField($field)->getType() === 'linkMultiple';
return $entityDefs->getField($field)->getType() === FieldType::LINK_MULTIPLE;
}
public function createFromEntity(Entity $entity, string $field): LinkMultiple

View File

@@ -29,6 +29,7 @@
namespace Espo\Core\FieldProcessing\LinkMultiple;
use Espo\Core\ORM\Type\FieldType;
use Espo\ORM\Entity;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\FieldProcessing\Loader as LoaderInterface;
@@ -92,8 +93,8 @@ class ListLoader implements LoaderInterface
foreach ($entityDefs->getFieldList() as $fieldDefs) {
if (
$fieldDefs->getType() !== 'linkMultiple' &&
$fieldDefs->getType() !== 'attachmentMultiple'
$fieldDefs->getType() !== FieldType::LINK_MULTIPLE &&
$fieldDefs->getType() !== FieldType::ATTACHMENT_MULTIPLE
) {
continue;
}

View File

@@ -29,6 +29,7 @@
namespace Espo\Core\FieldProcessing\LinkMultiple;
use Espo\Core\ORM\Type\FieldType;
use Espo\ORM\Entity;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\FieldProcessing\Loader as LoaderInterface;
@@ -74,8 +75,8 @@ class Loader implements LoaderInterface
foreach ($entityDefs->getFieldList() as $fieldDefs) {
if (
$fieldDefs->getType() !== 'linkMultiple' &&
$fieldDefs->getType() !== 'attachmentMultiple'
$fieldDefs->getType() !== FieldType::LINK_MULTIPLE &&
$fieldDefs->getType() !== FieldType::ATTACHMENT_MULTIPLE
) {
continue;
}

View File

@@ -34,6 +34,7 @@ use Espo\Core\Formula\Exceptions\BadArgumentType;
use Espo\Core\Formula\Exceptions\TooFewArguments;
use Espo\Core\Formula\Func;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\ORM\Type\FieldType;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use stdClass;
@@ -84,7 +85,7 @@ class FetchType implements Func
foreach ($fieldDefsList as $fieldDefs) {
$field = $fieldDefs->getName();
if ($fieldDefs->getType() === 'linkMultiple' && $entity->hasLinkMultipleField($field)) {
if ($fieldDefs->getType() === FieldType::LINK_MULTIPLE && $entity->hasLinkMultipleField($field)) {
$entity->loadLinkMultipleField($field);
}
}

View File

@@ -55,7 +55,7 @@ class LinkMultiple implements FieldConverter
'relation' => $name,
'isUnordered' => true,
'attributeRole' => 'idList',
'fieldType' => 'linkMultiple',
'fieldType' => FieldType::LINK_MULTIPLE,
]);
/** @var array<string, mixed> $defaults */

View File

@@ -29,6 +29,7 @@
namespace Espo\Core\Utils\Database\Schema;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Utils\Util;
use Espo\ORM\Defs\IndexDefs;
@@ -127,7 +128,7 @@ class Utils
) {
$permittedFieldTypeList = [
'varchar',
FieldType::VARCHAR,
];
$fields = [];
@@ -203,7 +204,6 @@ class Utils
$type = self::getDbFieldType($ormFieldDefs);
$length = $defaultLength[$type] ?? $length;
//$length = isset($ormFieldDefs['len']) ? $ormFieldDefs['len'] : $length;
switch ($type) {
case 'varchar':

View File

@@ -37,6 +37,7 @@ use Espo\Core\Exceptions\Error;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Field\DateTime as DateTimeField;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Select\Helpers\RelationQueryHelper;
use Espo\Core\Select\SelectBuilderFactory;
use Espo\Core\Utils\Config;
@@ -523,7 +524,8 @@ class Service
}
if (
$this->metadata->get(['entityDefs', 'Task', 'fields', 'assignedUsers', 'type']) === 'linkMultiple' &&
$this->metadata->get(['entityDefs', 'Task', 'fields', 'assignedUsers', 'type']) ===
FieldType::LINK_MULTIPLE &&
!$this->metadata->get(['entityDefs', 'Task', 'fields', 'assignedUsers', 'disabled'])
) {
$queryBuilder->where(

View File

@@ -36,6 +36,7 @@ use Espo\Core\Utils\Metadata;
use Espo\Entities\Attachment;
use Espo\Entities\Settings;
use Espo\Entities\User;
use Espo\Core\ORM\Type\FieldType;
class AccessChecker
{

View File

@@ -34,22 +34,15 @@ use Espo\Core\Exceptions\ForbiddenSilent;
use Espo\Core\Utils\File\MimeType;
use Espo\Core\Utils\Metadata;
use Espo\Entities\Attachment;
use Espo\Core\ORM\Type\FieldType;
class Checker
{
private Metadata $metadata;
private MimeType $mimeType;
private DetailsObtainer $detailsObtainer;
public function __construct(
Metadata $metadata,
MimeType $mimeType,
DetailsObtainer $detailsObtainer
) {
$this->metadata = $metadata;
$this->mimeType = $mimeType;
$this->detailsObtainer = $detailsObtainer;
}
private Metadata $metadata,
private MimeType $mimeType,
private DetailsObtainer $detailsObtainer
) {}
/**
* Check a mine-type for allowance.

View File

@@ -1,38 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Tools\Attachment;
class FieldType
{
public const FILE = 'file';
public const IMAGE = 'image';
public const ATTACHMENT_MULTIPLE = 'attachmentMultiple';
public const WYSIWYG = 'wysiwyg';
}

View File

@@ -45,6 +45,7 @@ use Espo\Entities\Attachment;
use Espo\ORM\EntityManager;
use Espo\Repositories\Attachment as AttachmentRepository;
use Espo\Tools\Attachment\Jobs\MoveToStorage;
use Espo\Core\ORM\Type\FieldType;
class UploadService
{

View File

@@ -35,9 +35,11 @@ use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\FieldProcessing\EmailAddress\AccessChecker as EmailAddressAccessChecker;
use Espo\Core\FieldProcessing\PhoneNumber\AccessChecker as PhoneNumberAccessChecker;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Record\ServiceContainer as RecordServiceContainer;
use Espo\Core\Di;
use Espo\Entities\Attachment;
class Erasor implements
@@ -139,17 +141,17 @@ class Erasor implements
$entity->clear($field . 'Data');
continue;
} else if ($type === 'file' || $type === 'image') {
} else if ($type === FieldType::FILE || $type === FieldType::IMAGE) {
$attachmentId = $entity->get($field . 'Id');
if ($attachmentId) {
$attachment = $this->entityManager->getEntityById('Attachment', $attachmentId);
$attachment = $this->entityManager->getEntityById(Attachment::ENTITY_TYPE, $attachmentId);
if ($attachment) {
$this->entityManager->removeEntity($attachment);
}
}
} else if ($type === 'attachmentMultiple') {
} else if ($type === FieldType::ATTACHMENT_MULTIPLE) {
$attachmentList = $entity->get($field);
foreach ($attachmentList as $attachment) {

View File

@@ -29,37 +29,26 @@
namespace Espo\Tools\EmailTemplate;
use Espo\Core\ORM\Type\FieldType;
use Espo\ORM\Entity;
use Espo\Core\Utils\Metadata;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\Core\Utils\NumberUtil;
use Espo\Core\Utils\Language;
use Espo\ORM\Type\AttributeType;
use Stringable;
class Formatter
{
private Metadata $metadata;
private Config $config;
private DateTimeUtil $dateTime;
private NumberUtil $number;
private Language $language;
public function __construct(
Metadata $metadata,
Config $config,
DateTimeUtil $dateTime,
NumberUtil $number,
Language $language
) {
$this->metadata = $metadata;
$this->config = $config;
$this->dateTime = $dateTime;
$this->number = $number;
$this->language = $language;
}
private Metadata $metadata,
private Config $config,
private DateTimeUtil $dateTime,
private NumberUtil $number,
private Language $language
) {}
public function formatAttributeValue(Entity $entity, string $attribute, bool $isPlainText = false): ?string
{
@@ -88,7 +77,11 @@ class Formatter
return $label;
}
if ($fieldType === 'array' || $fieldType === 'multiEnum' || $fieldType === 'checklist') {
if (
$fieldType === FieldType::ARRAY ||
$fieldType === FieldType::MULTI_ENUM ||
$fieldType === FieldType::CHECKLIST
) {
$valueList = [];
if (!is_array($value)) {
@@ -102,7 +95,7 @@ class Formatter
return implode(', ', $valueList);
}
if ($attributeType === 'date') {
if ($attributeType === AttributeType::DATE) {
if (!$value) {
return '';
}
@@ -110,7 +103,7 @@ class Formatter
return $this->dateTime->convertSystemDate($value);
}
if ($attributeType === 'datetime') {
if ($attributeType === AttributeType::DATETIME) {
if (!$value) {
return '';
}
@@ -118,12 +111,12 @@ class Formatter
return $this->dateTime->convertSystemDateTime($value);
}
if ($attributeType === 'text') {
if ($attributeType === AttributeType::TEXT) {
if (!is_string($value)) {
return '';
}
if ($fieldType === 'wysiwyg') {
if ($fieldType === FieldType::WYSIWYG) {
return $value;
}
@@ -134,28 +127,28 @@ class Formatter
return nl2br($value);
}
if ($attributeType === 'float') {
if ($attributeType === AttributeType::FLOAT) {
if (!is_float($value)) {
return '';
}
$decimalPlaces = 2;
if ($fieldType === 'currency') {
if ($fieldType === FieldType::CURRENCY) {
$decimalPlaces = $this->config->get('currencyDecimalPlaces');
}
return $this->number->format($value, $decimalPlaces);
}
if ($attributeType === 'int') {
if ($attributeType === AttributeType::INT) {
if (!is_int($value)) {
return '';
}
if (
$fieldType === 'autoincrement' ||
$fieldType === 'int' &&
$fieldType === FieldType::AUTOINCREMENT ||
$fieldType === FieldType::INT &&
$this->metadata
->get(['entityDefs', $entity->getEntityType(), 'fields', $attribute, 'disableFormatting'])
) {

View File

@@ -32,6 +32,7 @@ namespace Espo\Tools\EmailTemplate\InsertField;
use Espo\Core\Acl;
use Espo\Core\Acl\Table;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Record\ServiceContainer;
use Espo\Core\Utils\FieldUtil;
use Espo\Entities\Email;
@@ -120,13 +121,13 @@ class Service
$recordService->prepareEntityForOutput($e);
$ignoreTypeList = [
'image',
'file',
FieldType::IMAGE,
FieldType::FILE,
FieldType::WYSIWYG,
FieldType::LINK_MULTIPLE,
FieldType::ATTACHMENT_MULTIPLE,
FieldType::BOOL,
'map',
'wysiwyg',
'linkMultiple',
'attachmentMultiple',
'bool',
];
foreach ($fm->getEntityTypeFieldList($entityType) as $field) {

View File

@@ -30,6 +30,7 @@
namespace Espo\Tools\Export\Format\Csv;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Utils\Metadata;
use Espo\ORM\Entity;
use Espo\Tools\Export\AdditionalFieldsLoader as AdditionalFieldsLoaderInterface;
@@ -52,8 +53,8 @@ class AdditionalFieldsLoader implements AdditionalFieldsLoaderInterface
->get(['entityDefs', $entity->getEntityType(), 'fields', $field, 'type']);
if (
$fieldType === 'linkMultiple' ||
$fieldType === 'attachmentMultiple'
$fieldType === FieldType::LINK_MULTIPLE ||
$fieldType === FieldType::ATTACHMENT_MULTIPLE
) {
if (!$entity->has($field . 'Ids') && $entity->hasLinkMultipleField($field)) {
$entity->loadLinkMultipleField($field);

View File

@@ -30,6 +30,7 @@
namespace Espo\Tools\Export\Format\Xlsx;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Utils\Metadata;
use Espo\ORM\Entity;
use Espo\Tools\Export\AdditionalFieldsLoader as AdditionalFieldsLoaderInterface;
@@ -77,7 +78,7 @@ class AdditionalFieldsLoader implements AdditionalFieldsLoaderInterface
$fieldType = $this->metadata
->get(['entityDefs', $entity->getEntityType(), 'fields', $field, 'type']);
if ($fieldType === 'linkMultiple' || $fieldType === 'attachmentMultiple') {
if ($fieldType === FieldType::LINK_MULTIPLE || $fieldType === FieldType::ATTACHMENT_MULTIPLE) {
if (!$entity->has($field . 'Ids') && $entity->hasLinkMultipleField($field)) {
$entity->loadLinkMultipleField($field);
}

View File

@@ -71,7 +71,7 @@ class ParamsHandler implements ProcessorParamsHandler
foreach ($fieldList as $i => $field) {
$type = $this->metadata->get(['entityDefs', $entityType, 'fields', $field, 'type']);
if (in_array($type, ['linkMultiple', 'attachmentMultiple'])) {
if (in_array($type, [FieldType::LINK_MULTIPLE, FieldType::ATTACHMENT_MULTIPLE])) {
unset($fieldList[$i]);
}
}

View File

@@ -50,8 +50,8 @@ use Espo\ORM\Entity;
use Espo\Repositories\Attachment as AttachmentRepository;
use Espo\Entities\User;
use Espo\Entities\Attachment;
use Espo\Core\ORM\Type\FieldType;
use Espo\Tools\Attachment\FieldType;
use Exception;
use RuntimeException;
use stdClass;