snapshot of https://github.com/espocrm/espocrm.git (master, 2026-09-18; blobs > 131072B omitted)
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s
Some checks failed
Test / Test on PHP 8.3 (push) Failing after 5s
Test / Test on PHP 8.4 (push) Failing after 4s
Test / Test on PHP 8.5 (push) Failing after 3s
TypeScript static analysis / TypeScript check (push) Failing after 14s
Test Integration on MySQL / Test on PHP 8.3 (push) Failing after 2s
Test Integration on MySQL / Test on PHP 8.5 (push) Failing after 0s
Test Integration on PostgreSQL / Test on PHP 8.4 fix (push) Failing after 1s
Test Integration on PostgreSQL / Test on PHP 8.4 master (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class AssignedUsersUpdateHook implements UpdateHook
|
||||
{
|
||||
private const PARAM = 'assignedUsers';
|
||||
private const FIELD = Field::ASSIGNED_USERS;
|
||||
private const RELATION_NAME = 'entityUser';
|
||||
private const FIELD_ASSIGNED_USER = Field::ASSIGNED_USER;
|
||||
|
||||
private const DEFAULT_MAX_COUNT = 10;
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private Log $log,
|
||||
) {}
|
||||
|
||||
public function process(Params $params, Params $previousParams): void
|
||||
{
|
||||
if ($params->get(self::PARAM) && !$previousParams->get(self::PARAM)) {
|
||||
$this->add($params->getName());
|
||||
} else if (!$params->get(self::PARAM) && $previousParams->get(self::PARAM)) {
|
||||
$this->remove($params->getName());
|
||||
}
|
||||
}
|
||||
|
||||
private function add(string $entityType): void
|
||||
{
|
||||
if ($this->metadata->get("entityDefs.$entityType.links." . self::FIELD . ".isCustom")) {
|
||||
$this->log->warning("Cannot enable multiple assigned users for $entityType as the link already exists.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->metadata->set('entityDefs', $entityType, [
|
||||
'fields' => [
|
||||
self::FIELD => [
|
||||
'type' => FieldType::LINK_MULTIPLE,
|
||||
'view' => 'views/fields/assigned-users',
|
||||
'maxCount' => self::DEFAULT_MAX_COUNT,
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
self::FIELD => [
|
||||
'type' => RelationType::HAS_MANY,
|
||||
'entity' => User::ENTITY_TYPE,
|
||||
'relationName' => self::RELATION_NAME,
|
||||
'layoutRelationshipsDisabled' => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->metadata->set('entityAcl', $entityType, [
|
||||
'links' => [
|
||||
self::FIELD => [
|
||||
'readOnly' => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
if ($this->metadata->get("entityDefs.$entityType.fields.assignedUser")) {
|
||||
$this->metadata->set('entityDefs', $entityType, [
|
||||
'fields' => [
|
||||
self::FIELD_ASSIGNED_USER => [
|
||||
'disabled' => true,
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
self::FIELD_ASSIGNED_USER => [
|
||||
'disabled' => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->metadata->save();
|
||||
}
|
||||
|
||||
private function remove(string $entityType): void
|
||||
{
|
||||
$field = self::FIELD;
|
||||
|
||||
if (
|
||||
$this->metadata->get("entityDefs.$entityType.links.$field.isCustom") &&
|
||||
$this->metadata->get("entityDefs.$entityType.links.$field.relationName") !== self::RELATION_NAME
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->metadata->delete('entityDefs', $entityType, [
|
||||
'fields.' . self::FIELD,
|
||||
'links.' . self::FIELD,
|
||||
'fields.' . self::FIELD_ASSIGNED_USER . '.disabled',
|
||||
'links.' . self::FIELD_ASSIGNED_USER . '.disabled',
|
||||
]);
|
||||
|
||||
$this->metadata->delete('entityAcl', $entityType, [
|
||||
'links.' . self::FIELD,
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Exceptions\Conflict;
|
||||
use Espo\Core\Exceptions\Error\Body;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class CategoriesBeforeUpdateHook implements UpdateHook
|
||||
{
|
||||
private const string PARAM = 'categories';
|
||||
|
||||
public function process(Params $params, Params $previousParams): void
|
||||
{
|
||||
if ($params->get(self::PARAM) && $params->get('kanbanViewMode')) {
|
||||
throw Conflict::createWithBody(
|
||||
'cannotEnableCategoriesWithKanbanViewMode',
|
||||
Body::create()->withMessageTranslation('cannotEnableCategoriesWithKanbanViewMode', 'EntityManager')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Templates\Entities\Base;
|
||||
use Espo\Core\Templates\Entities\BasePlus;
|
||||
use Espo\Tools\EntityManager\Hook\DeleteHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class CategoriesDeleteHook implements DeleteHook
|
||||
{
|
||||
private const string PARAM = 'categories';
|
||||
|
||||
public function __construct(
|
||||
private CategoriesUpdateHook $categoriesUpdateHook,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
* @throws Error
|
||||
*/
|
||||
public function process(Params $params): void
|
||||
{
|
||||
if (!in_array($params->getType(), [BasePlus::TEMPLATE_TYPE, Base::TEMPLATE_TYPE])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$params->get(self::PARAM)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->categoriesUpdateHook->remove($params->getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Binding\Attributes\Qualify;
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Conflict;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Templates\Entities\Base;
|
||||
use Espo\Core\Templates\Entities\BasePlus;
|
||||
use Espo\Core\Templates\Entities\CategoryTree;
|
||||
use Espo\Core\Utils\Language;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\ORM\Defs\Params\FieldParam;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use Espo\Tools\EntityManager\CreateParams;
|
||||
use Espo\Tools\EntityManager\DeleteParams;
|
||||
use Espo\Tools\EntityManager\EntityManager;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
use Espo\Tools\LayoutManager\LayoutCustomizer;
|
||||
use Espo\Tools\LayoutManager\LayoutName;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class CategoriesUpdateHook implements UpdateHook
|
||||
{
|
||||
private const string PARAM = 'categories';
|
||||
private const string FIELD = 'category';
|
||||
|
||||
public function __construct(
|
||||
private InjectableFactory $injectableFactory,
|
||||
#[Qualify(Language::QUALIFIER_DEFAULT)]
|
||||
private Language $defaultLanguage,
|
||||
private Metadata $metadata,
|
||||
private DataManager $dataManager,
|
||||
private LayoutCustomizer $layoutCustomizer,
|
||||
private Log $log,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Forbidden
|
||||
* @throws Error
|
||||
* @throws Conflict
|
||||
*/
|
||||
public function process(Params $params, Params $previousParams): void
|
||||
{
|
||||
if (!in_array($params->getType(), [BasePlus::TEMPLATE_TYPE, Base::TEMPLATE_TYPE])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($params->get(self::PARAM) && !$previousParams->get(self::PARAM)) {
|
||||
$this->add($params->getName());
|
||||
} else if (!$params->get(self::PARAM) && $previousParams->get(self::PARAM)) {
|
||||
$this->remove($params->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequest
|
||||
* @throws Conflict
|
||||
* @throws Error
|
||||
*/
|
||||
private function add(string $name): void
|
||||
{
|
||||
$entityType = $this->composeEntityType($name);
|
||||
|
||||
if ($this->metadata->get("scopes.$entityType")) {
|
||||
$message = "Could not create category entity type $entityType as the same entity type exists";
|
||||
|
||||
$this->log->warning($message);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$createParams = new CreateParams(
|
||||
forceCreate: true,
|
||||
replaceData: [
|
||||
'subjectEntityType' => $name,
|
||||
],
|
||||
skipCustomPrefix: true,
|
||||
isNotRemovable: true,
|
||||
addTab: false,
|
||||
);
|
||||
|
||||
$this->getEntityManagerTool()->create(
|
||||
name: $entityType,
|
||||
type: CategoryTree::TEMPLATE_TYPE,
|
||||
params: [
|
||||
'labelSingular' => $this->defaultLanguage->translateLabel($name, 'scopeNames') . ' ' .
|
||||
$this->defaultLanguage->translateLabel('Category', 'entityNameParts', 'EntityManager'),
|
||||
'labelPlural' => $this->defaultLanguage->translateLabel($name, 'scopeNames') . ' ' .
|
||||
$this->defaultLanguage->translateLabel('Category', 'entityNamePartsPlural', 'EntityManager')
|
||||
],
|
||||
createParams: $createParams,
|
||||
);
|
||||
|
||||
$this->metadata->set('entityDefs', $name, [
|
||||
'fields' => [
|
||||
self::FIELD => [
|
||||
FieldParam::TYPE => FieldType::LINK,
|
||||
'audited' => true,
|
||||
'view' => 'views/fields/link-category-tree'
|
||||
]
|
||||
],
|
||||
'links' => [
|
||||
self::FIELD => [
|
||||
RelationParam::TYPE => RelationType::BELONGS_TO,
|
||||
RelationParam::ENTITY => $entityType,
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$this->metadata->set('clientDefs', $name, [
|
||||
'views' => [
|
||||
'list' => 'views/list-with-categories',
|
||||
],
|
||||
'modalViews' => [
|
||||
'select' => 'views/modals/select-records-with-categories',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
$this->dataManager->rebuild([$entityType]);
|
||||
$this->dataManager->rebuild([$name]);
|
||||
|
||||
$this->layoutCustomizer->addDetailField($name, self::FIELD, LayoutName::DETAIL);
|
||||
$this->layoutCustomizer->addDetailField($name, self::FIELD, LayoutName::DETAIL_SMALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Forbidden
|
||||
* @throws Error
|
||||
*/
|
||||
public function remove(string $name): void
|
||||
{
|
||||
$entityType = $this->composeEntityType($name);
|
||||
|
||||
$deleteParams = new DeleteParams(
|
||||
forceRemove: true,
|
||||
);
|
||||
|
||||
$this->getEntityManagerTool()->delete($entityType, $deleteParams);
|
||||
|
||||
$this->metadata->delete('entityDefs', $name, [
|
||||
'fields.' . self::FIELD,
|
||||
'links.' . self::FIELD,
|
||||
]);
|
||||
|
||||
$this->metadata->delete('clientDefs', $name, [
|
||||
'views.list',
|
||||
'modalViews.select',
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
$this->dataManager->rebuild([$entityType]);
|
||||
$this->dataManager->rebuild([$name]);
|
||||
|
||||
$this->layoutCustomizer->removeInDetail($name, self::FIELD, LayoutName::DETAIL);
|
||||
$this->layoutCustomizer->removeInDetail($name, self::FIELD, LayoutName::DETAIL_SMALL);
|
||||
}
|
||||
|
||||
private function getEntityManagerTool(): EntityManager
|
||||
{
|
||||
return $this->injectableFactory->create(EntityManager::class);
|
||||
}
|
||||
|
||||
private function composeEntityType(string $name): string
|
||||
{
|
||||
return $name . 'Category';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\User;
|
||||
use Espo\Modules\Crm\Entities\CaseObj;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use Espo\ORM\Defs\Params\FieldParam;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class CollaboratorsUpdateHook implements UpdateHook
|
||||
{
|
||||
private const PARAM = 'collaborators';
|
||||
private const FIELD = Field::COLLABORATORS;
|
||||
private const RELATION_NAME = 'entityCollaborator';
|
||||
|
||||
private const DEFAULT_MAX_COUNT = 30;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private array $enabledByDefaultEntityTypeList = [
|
||||
CaseObj::ENTITY_TYPE,
|
||||
Task::ENTITY_TYPE,
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private Log $log,
|
||||
private DataManager $dataManager,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function process(Params $params, Params $previousParams): void
|
||||
{
|
||||
if ($params->get(self::PARAM) && !$previousParams->get(self::PARAM)) {
|
||||
$this->add($params->getName());
|
||||
} else if (!$params->get(self::PARAM) && $previousParams->get(self::PARAM)) {
|
||||
$this->remove($params->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
private function add(string $entityType): void
|
||||
{
|
||||
if ($this->metadata->get("entityDefs.$entityType.links." . self::FIELD . ".isCustom")) {
|
||||
$this->log->warning("Cannot enable collaborators for $entityType as the link already exists.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isEnabledByDefault($entityType)) {
|
||||
$this->addEnabledByDefault($entityType);
|
||||
} else {
|
||||
$this->addInternal($entityType);
|
||||
}
|
||||
|
||||
$this->metadata->save();
|
||||
$this->dataManager->rebuild([$entityType]);
|
||||
}
|
||||
|
||||
private function remove(string $entityType): void
|
||||
{
|
||||
$field = self::FIELD;
|
||||
|
||||
if (
|
||||
$this->metadata->get("entityDefs.$entityType.links.$field.isCustom") &&
|
||||
$this->metadata->get("entityDefs.$entityType.links.$field.relationName") !== self::RELATION_NAME
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->metadata->delete('entityDefs', $entityType, [
|
||||
'fields.' . self::FIELD,
|
||||
'links.' . self::FIELD,
|
||||
]);
|
||||
|
||||
$this->metadata->delete('entityAcl', $entityType, [
|
||||
'links.' . self::FIELD,
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
|
||||
// Must be after metadata is saved.
|
||||
if ($this->isEnabledByDefault($entityType)) {
|
||||
$this->metadata->set('entityDefs', $entityType, [
|
||||
'fields' => [
|
||||
self::FIELD => [
|
||||
FieldParam::DISABLED => true,
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
self::FIELD => [
|
||||
RelationParam::DISABLED => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
}
|
||||
}
|
||||
|
||||
private function addInternal(string $entityType): void
|
||||
{
|
||||
$this->metadata->set('entityDefs', $entityType, [
|
||||
'fields' => [
|
||||
self::FIELD => [
|
||||
'type' => FieldType::LINK_MULTIPLE,
|
||||
'view' => 'views/fields/collaborators',
|
||||
'maxCount' => self::DEFAULT_MAX_COUNT,
|
||||
'fieldManagerParamList' => [
|
||||
'readOnly',
|
||||
'readOnlyAfterCreate',
|
||||
'audited',
|
||||
'autocompleteOnEmpty',
|
||||
'maxCount',
|
||||
'inlineEditDisabled',
|
||||
'tooltipText',
|
||||
]
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
self::FIELD => [
|
||||
'type' => RelationType::HAS_MANY,
|
||||
'entity' => User::ENTITY_TYPE,
|
||||
RelationParam::RELATION_NAME => self::RELATION_NAME,
|
||||
'layoutRelationshipsDisabled' => true,
|
||||
RelationParam::READ_ONLY => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->metadata->set('entityAcl', $entityType, [
|
||||
'links' => [
|
||||
self::FIELD => [
|
||||
'readOnly' => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function addEnabledByDefault(string $entityType): void
|
||||
{
|
||||
$this->metadata->delete('entityDefs', $entityType, [
|
||||
'fields.' . self::FIELD,
|
||||
'links.' . self::FIELD,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $entityType
|
||||
* @return bool
|
||||
*/
|
||||
private function isEnabledByDefault(string $entityType): bool
|
||||
{
|
||||
return in_array($entityType, $this->enabledByDefaultEntityTypeList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use Espo\Tools\EntityManager\Hook\DeleteHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class DeleteHasChildrenLinks implements DeleteHook
|
||||
{
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
) {}
|
||||
|
||||
public function process(Params $params): void
|
||||
{
|
||||
/** @var array<string, array<string, mixed>> $entityDefs */
|
||||
$entityDefs = $this->metadata->get('entityDefs', []);
|
||||
|
||||
foreach ($entityDefs as $entityType => $defs) {
|
||||
/** @var array<string, array<string, mixed>> $links */
|
||||
$links = $defs['links'] ?? [];
|
||||
|
||||
foreach ($links as $link => $linkDefs) {
|
||||
$isCustom = $linkDefs['isCustom'] ?? false;
|
||||
$foreignEntityType = $linkDefs[RelationParam::ENTITY] ?? null;
|
||||
$type = $linkDefs[RelationParam::TYPE] ?? null;
|
||||
|
||||
if (
|
||||
!$isCustom ||
|
||||
$foreignEntityType !== $params->getName() ||
|
||||
$type !== RelationType::HAS_CHILDREN
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->metadata->delete('entityDefs', $entityType, "links.$link");
|
||||
}
|
||||
}
|
||||
|
||||
$this->metadata->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Binding\Attributes\Qualify;
|
||||
use Espo\Core\Templates\Entities\Event;
|
||||
use Espo\Core\Utils\Language;
|
||||
use Espo\Tools\EntityManager\Hook\CreateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
class EventCreateHook implements CreateHook
|
||||
{
|
||||
public function __construct(
|
||||
#[Qualify(Language::QUALIFIER_BASE)]
|
||||
private Language $baseLanguage,
|
||||
private Language $language
|
||||
) {}
|
||||
|
||||
public function process(Params $params): void
|
||||
{
|
||||
if ($params->getType() !== Event::TEMPLATE_TYPE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->translate($this->baseLanguage, $params);
|
||||
|
||||
if ($this->baseLanguage->getLanguage() === $this->language->getLanguage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->translate($this->language, $params);
|
||||
}
|
||||
|
||||
private function translate(Language $language, Params $params): void
|
||||
{
|
||||
$name = $params->getName();
|
||||
|
||||
$label1 = 'Schedule ' . $name;
|
||||
$label2 = 'Log ' . $name;
|
||||
|
||||
$translatedName = $params->get('labelSingular') ?? $name;
|
||||
|
||||
$translation1 = $language->translateLabel('Schedule') . ' ' . $translatedName;
|
||||
$translation2 = $language->translateLabel('Log') . ' ' . $translatedName;
|
||||
|
||||
$language->set('Global', 'labels', $label1, $translation1);
|
||||
$language->set('Global', 'labels', $label2, $translation2);
|
||||
|
||||
$language->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Binding\Attributes\Qualify;
|
||||
use Espo\Core\Templates\Entities\Event;
|
||||
use Espo\Core\Utils\Language;
|
||||
use Espo\Tools\EntityManager\Hook\DeleteHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
class EventDeleteHook implements DeleteHook
|
||||
{
|
||||
public function __construct(
|
||||
#[Qualify(Language::QUALIFIER_BASE)]
|
||||
private Language $baseLanguage,
|
||||
private Language $language
|
||||
) {}
|
||||
|
||||
public function process(Params $params): void
|
||||
{
|
||||
if (
|
||||
$params->getType() !== Event::TEMPLATE_TYPE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $params->getName();
|
||||
|
||||
$label1 = 'Schedule ' . $name;
|
||||
$label2 = 'Log ' . $name;
|
||||
|
||||
$this->baseLanguage->delete('Global', 'labels', $label1);
|
||||
$this->baseLanguage->delete('Global', 'labels', $label2);
|
||||
|
||||
$this->language->delete('Global', 'labels', $label1);
|
||||
$this->language->delete('Global', 'labels', $label2);
|
||||
|
||||
$this->baseLanguage->save();
|
||||
$this->language->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Modules\Crm\Entities\Account;
|
||||
use Espo\ORM\Defs\Params\FieldParam;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class LockableUpdateHook implements UpdateHook
|
||||
{
|
||||
private const string PARAM = 'lockable';
|
||||
private const string FIELD = Field::IS_LOCKED;
|
||||
|
||||
/** @var string[] */
|
||||
private array $enabledByDefaultEntityTypeList = [
|
||||
Account::ENTITY_TYPE,
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private Log $log,
|
||||
private DataManager $dataManager,
|
||||
) {}
|
||||
|
||||
public function process(Params $params, Params $previousParams): void
|
||||
{
|
||||
if ($params->get(self::PARAM) && !$previousParams->get(self::PARAM)) {
|
||||
$this->add($params->getName());
|
||||
} else if (!$params->get(self::PARAM) && $previousParams->get(self::PARAM)) {
|
||||
$this->remove($params->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
private function add(string $entityType): void
|
||||
{
|
||||
if ($this->metadata->get("entityDefs.$entityType.fields." . self::FIELD . ".isCustom")) {
|
||||
$this->log->warning("Cannot enable lockable for $entityType as the field already exists.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isEnabledByDefault($entityType)) {
|
||||
$this->addEnabledByDefault($entityType);
|
||||
} else {
|
||||
$this->addInternal($entityType);
|
||||
}
|
||||
|
||||
|
||||
$this->metadata->save();
|
||||
$this->dataManager->rebuild([$entityType]);
|
||||
}
|
||||
|
||||
private function addEnabledByDefault(string $entityType): void
|
||||
{
|
||||
$this->metadata->delete('entityDefs', $entityType, [
|
||||
'fields.' . self::FIELD,
|
||||
]);
|
||||
}
|
||||
|
||||
private function addInternal(string $entityType): void
|
||||
{
|
||||
$this->metadata->set('entityDefs', $entityType, [
|
||||
'fields' => [
|
||||
self::FIELD => [
|
||||
FieldParam::TYPE => FieldType::BOOL,
|
||||
FieldParam::READ_ONLY => true,
|
||||
'audited' => true,
|
||||
'fieldManagerParamList' => [
|
||||
'audited',
|
||||
'tooltipText',
|
||||
],
|
||||
'layoutAvailabilityList' => [
|
||||
'filters',
|
||||
'list',
|
||||
],
|
||||
],
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
private function remove(string $entityType): void
|
||||
{
|
||||
$this->metadata->delete('entityDefs', $entityType, [
|
||||
'fields.' . self::FIELD,
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
|
||||
// Must be after metadata is saved.
|
||||
if ($this->isEnabledByDefault($entityType)) {
|
||||
$this->metadata->set('entityDefs', $entityType, [
|
||||
'fields' => [
|
||||
self::FIELD => [
|
||||
FieldParam::DISABLED => true,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
}
|
||||
}
|
||||
|
||||
private function isEnabledByDefault(string $entityType): bool
|
||||
{
|
||||
return in_array($entityType, $this->enabledByDefaultEntityTypeList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Exceptions\Conflict;
|
||||
use Espo\Core\Exceptions\Error\Body;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class PipelinesBeforeUpdateHook implements UpdateHook
|
||||
{
|
||||
private const string PARAM = 'pipelines';
|
||||
|
||||
public function process(Params $params, Params $previousParams): void
|
||||
{
|
||||
if ($params->get(self::PARAM) && !$params->get('statusField')) {
|
||||
throw Conflict::createWithBody(
|
||||
'cannotEnablePipelinesWithNoStatusField',
|
||||
Body::create()->withMessageTranslation('cannotEnablePipelinesWithNoStatusField', 'EntityManager')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Classes\Acl\Common\Pipeline\PipelineLinkChecker;
|
||||
use Espo\Classes\Acl\Common\Pipeline\PipelineStageLinkChecker;
|
||||
use Espo\Classes\FieldValidators\Common\PipelineStage\Valid;
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\Pipeline;
|
||||
use Espo\Entities\PipelineStage;
|
||||
use Espo\ORM\Defs\Params\FieldParam;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
use Espo\Tools\LayoutManager\LayoutCustomizer;
|
||||
use Espo\Tools\LayoutManager\LayoutName;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class PipelinesUpdateHook implements UpdateHook
|
||||
{
|
||||
private const string PARAM = 'pipelines';
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private DataManager $dataManager,
|
||||
private LayoutCustomizer $layoutCustomizer,
|
||||
private Log $log,
|
||||
) {}
|
||||
|
||||
public function process(Params $params, Params $previousParams): void
|
||||
{
|
||||
if ($params->get(self::PARAM) && !$previousParams->get(self::PARAM)) {
|
||||
$this->add($params->getName());
|
||||
} else if (!$params->get(self::PARAM) && $previousParams->get(self::PARAM)) {
|
||||
$this->remove($params->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
private function add(string $entityType): void
|
||||
{
|
||||
if ($this->metadata->get("entityDefs.$entityType.links." . Field::PIPELINE . ".isCustom")) {
|
||||
$this->log->warning("Cannot enable pipelines for $entityType as the link already exists.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->metadata->set('entityDefs', $entityType, [
|
||||
'fields' => [
|
||||
Field::PIPELINE => [
|
||||
FieldParam::TYPE => FieldType::LINK,
|
||||
FieldParam::REQUIRED => true,
|
||||
'audited' => true,
|
||||
'inlineEditDisabled' => true,
|
||||
'fieldManagerParamList' => [
|
||||
FieldParam::READ_ONLY_AFTER_CREATE,
|
||||
'audited',
|
||||
'tooltipText',
|
||||
],
|
||||
'view' => 'views/fields/extra/pipeline',
|
||||
],
|
||||
Field::PIPELINE_STAGE => [
|
||||
FieldParam::TYPE => FieldType::LINK,
|
||||
FieldParam::REQUIRED => true,
|
||||
'audited' => true,
|
||||
'validationDependsOnFieldList' => [
|
||||
Field::PIPELINE,
|
||||
],
|
||||
'validatorClassNameList' => [
|
||||
Valid::class,
|
||||
],
|
||||
'fieldManagerParamList' => [
|
||||
'audited',
|
||||
'tooltipText',
|
||||
'inlineEditDisabled',
|
||||
],
|
||||
'view' => 'views/fields/extra/pipeline-stage',
|
||||
'dynamicLogicConditionTypeList' => [
|
||||
'isEmpty',
|
||||
'isNotEmpty',
|
||||
]
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
Field::PIPELINE => [
|
||||
'type' => RelationType::BELONGS_TO,
|
||||
'entity' => Pipeline::ENTITY_TYPE,
|
||||
],
|
||||
Field::PIPELINE_STAGE => [
|
||||
'type' => RelationType::BELONGS_TO,
|
||||
'entity' => PipelineStage::ENTITY_TYPE,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->metadata->set('aclDefs', $entityType, [
|
||||
'linkCheckerClassNameMap' => [
|
||||
Field::PIPELINE => PipelineLinkChecker::class,
|
||||
Field::PIPELINE_STAGE => PipelineStageLinkChecker::class,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->metadata->set('selectDefs', $entityType, [
|
||||
'selectAttributesDependencyMap' => [
|
||||
Field::PIPELINE_STAGE . 'Id' => [
|
||||
Field::PIPELINE . 'Id',
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
$this->dataManager->rebuild([$entityType]);
|
||||
|
||||
$this->layoutCustomizer->addDetailField($entityType, Field::PIPELINE, LayoutName::DETAIL);
|
||||
$this->layoutCustomizer->addDetailField($entityType, Field::PIPELINE_STAGE, LayoutName::DETAIL);
|
||||
|
||||
$this->layoutCustomizer->addDetailField($entityType, Field::PIPELINE, LayoutName::DETAIL_SMALL);
|
||||
$this->layoutCustomizer->addDetailField($entityType, Field::PIPELINE_STAGE, LayoutName::DETAIL_SMALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
private function remove(string $entityType): void
|
||||
{
|
||||
$field = Field::PIPELINE;
|
||||
|
||||
if (
|
||||
$this->metadata->get("entityDefs.$entityType.links.$field.isCustom") &&
|
||||
$this->metadata->get("entityDefs.$entityType.links.$field.entityType") !== Pipeline::ENTITY_TYPE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->metadata->delete('entityDefs', $entityType, [
|
||||
'fields.' . Field::PIPELINE,
|
||||
'fields.' . Field::PIPELINE_STAGE,
|
||||
'links.' . Field::PIPELINE,
|
||||
'links.' . Field::PIPELINE_STAGE,
|
||||
]);
|
||||
|
||||
$this->metadata->delete('entityAcl', $entityType, [
|
||||
'links.' . Field::PIPELINE,
|
||||
'links.' . Field::PIPELINE_STAGE,
|
||||
]);
|
||||
|
||||
$this->metadata->delete('aclDefs', $entityType, [
|
||||
'linkCheckerClassNameMap.' . Field::PIPELINE,
|
||||
'linkCheckerClassNameMap.' . Field::PIPELINE_STAGE,
|
||||
]);
|
||||
|
||||
$this->metadata->delete('selectDefs', $entityType, [
|
||||
'selectAttributesDependencyMap.' . Field::PIPELINE_STAGE . 'Id',
|
||||
]);
|
||||
|
||||
$this->metadata->save();
|
||||
$this->dataManager->rebuild([$entityType]);
|
||||
|
||||
$this->layoutCustomizer->removeInDetail($entityType, Field::PIPELINE, LayoutName::DETAIL);
|
||||
$this->layoutCustomizer->removeInDetail($entityType, Field::PIPELINE_STAGE, LayoutName::DETAIL);
|
||||
|
||||
$this->layoutCustomizer->removeInDetail($entityType, Field::PIPELINE, LayoutName::DETAIL_SMALL);
|
||||
$this->layoutCustomizer->removeInDetail($entityType, Field::PIPELINE_STAGE, LayoutName::DETAIL_SMALL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\Templates\Entities\BasePlus;
|
||||
use Espo\Core\Templates\Entities\Company;
|
||||
use Espo\Core\Templates\Entities\Person;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use Espo\Tools\EntityManager\Hook\CreateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
class PlusCreateHook implements CreateHook
|
||||
{
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private Metadata $metadata
|
||||
) {}
|
||||
|
||||
public function process(Params $params): void
|
||||
{
|
||||
if (
|
||||
!in_array($params->getType(), [
|
||||
BasePlus::TEMPLATE_TYPE,
|
||||
Company::TEMPLATE_TYPE,
|
||||
Person::TEMPLATE_TYPE,
|
||||
])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $params->getName();
|
||||
|
||||
$activitiesEntityTypeList = $this->config->get('activitiesEntityList', []);
|
||||
$historyEntityTypeList = $this->config->get('historyEntityList', []);
|
||||
|
||||
$entityTypeList = array_merge($activitiesEntityTypeList, $historyEntityTypeList);
|
||||
$entityTypeList[] = Task::ENTITY_TYPE;
|
||||
$entityTypeList = array_unique($entityTypeList);
|
||||
|
||||
foreach ($entityTypeList as $entityType) {
|
||||
if (!$this->metadata->get(['entityDefs', $entityType, 'fields', Field::PARENT, 'entityList'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list = $this->metadata->get(['entityDefs', $entityType, 'fields', Field::PARENT, 'entityList'], []);
|
||||
|
||||
if (!in_array($name, $list)) {
|
||||
$list[] = $name;
|
||||
|
||||
$data = [
|
||||
'fields' => [
|
||||
Field::PARENT => ['entityList' => $list]
|
||||
]
|
||||
];
|
||||
|
||||
$this->metadata->set('entityDefs', $entityType, $data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->metadata->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\Templates\Entities\BasePlus;
|
||||
use Espo\Core\Templates\Entities\Company;
|
||||
use Espo\Core\Templates\Entities\Person;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Modules\Crm\Entities\Task;
|
||||
use Espo\Tools\EntityManager\Hook\CreateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
class PlusDeleteHook implements CreateHook
|
||||
{
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private Metadata $metadata
|
||||
) {}
|
||||
|
||||
public function process(Params $params): void
|
||||
{
|
||||
if (
|
||||
!in_array($params->getType(), [
|
||||
BasePlus::TEMPLATE_TYPE,
|
||||
Company::TEMPLATE_TYPE,
|
||||
Person::TEMPLATE_TYPE,
|
||||
])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $params->getName();
|
||||
|
||||
$activitiesEntityTypeList = $this->config->get('activitiesEntityList', []);
|
||||
$historyEntityTypeList = $this->config->get('historyEntityList', []);
|
||||
|
||||
$entityTypeList = array_merge($activitiesEntityTypeList, $historyEntityTypeList);
|
||||
$entityTypeList[] = Task::ENTITY_TYPE;
|
||||
$entityTypeList = array_unique($entityTypeList);
|
||||
|
||||
foreach ($entityTypeList as $entityType) {
|
||||
if (!$this->metadata->get(['entityDefs', $entityType, 'fields', Field::PARENT, 'entityList'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$list = $this->metadata->get(['entityDefs', $entityType, 'fields', Field::PARENT, 'entityList'], []);
|
||||
|
||||
if (in_array($name, $list)) {
|
||||
$key = array_search($name, $list);
|
||||
|
||||
unset($list[$key]);
|
||||
|
||||
$list = array_values($list);
|
||||
|
||||
$data = [
|
||||
'fields' => [
|
||||
'parent' => ['entityList' => $list]
|
||||
]
|
||||
];
|
||||
|
||||
$this->metadata->set('entityDefs', $entityType, $data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->metadata->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* 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\EntityManager\Hook\Hooks;
|
||||
|
||||
use Espo\Core\DataManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class StreamUpdateHook implements UpdateHook
|
||||
{
|
||||
private const PARAM = 'stream';
|
||||
|
||||
public function __construct(
|
||||
private DataManager $dataManager,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws Error
|
||||
*/
|
||||
public function process(Params $params, Params $previousParams): void
|
||||
{
|
||||
if ($params->get(self::PARAM) && !$previousParams->get(self::PARAM)) {
|
||||
$this->dataManager->rebuild([$params->getName()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user