Initial commit

This commit is contained in:
root
2026-01-19 17:44:46 +01:00
commit 823af8b11d
8721 changed files with 1130846 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Email;
use Espo\ORM\Entity;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Repositories\Email as EmailRepository;
use Espo\Entities\Email;
/**
* @implements Loader<Email>
*/
class AddressDataLoader implements Loader
{
public function __construct(private EntityManager $entityManager)
{}
/**
* @param Email $entity
*/
public function process(Entity $entity, Params $params): void
{
/** @var EmailRepository $repository */
$repository = $this->entityManager->getRepository(Email::ENTITY_TYPE);
$repository->loadNameHash($entity);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Email;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Entities\Email;
use Espo\ORM\Entity;
use Espo\Repositories\Email as EmailRepository;
/**
* @implements Loader<Email>
*/
class AddressLoader implements Loader
{
public function __construct(private EntityManager $entityManager)
{}
/**
* @inheritDoc
*/
public function process(Entity $entity, Params $params): void
{
/** @var EmailRepository $repository */
$repository = $this->entityManager->getRepository(Email::ENTITY_TYPE);
$repository->loadFromField($entity);
$repository->loadToField($entity);
$repository->loadCcField($entity);
$repository->loadBccField($entity);
$repository->loadReplyToField($entity);
}
}

View File

@@ -0,0 +1,67 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Email;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\Email;
use Espo\Entities\EmailFolder;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Name\Attribute;
/**
* @implements Loader<Email>
*/
class FolderDataLoader implements Loader
{
public function __construct(private EntityManager $entityManager) {}
public function process(Entity $entity, Params $params): void
{
$folderId = $entity->get(Email::USERS_COLUMN_FOLDER_ID);
if (!$folderId) {
return;
}
$folder = $this->entityManager
->getRDBRepositoryByClass(EmailFolder::class)
->select([Attribute::ID, 'name'])
->where([Attribute::ID => $folderId])
->findOne();
if (!$folder) {
return;
}
$entity->set('folderName', $folder->getName());
}
}

View File

@@ -0,0 +1,239 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Email;
use Espo\Core\Name\Field;
use Espo\Entities\User;
use Espo\Modules\Crm\Entities\Call;
use Espo\Modules\Crm\Entities\Contact;
use Espo\Modules\Crm\Entities\Lead;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Name\Attribute;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\Entities\EmailAddress;
use Espo\Entities\Email;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\Mail\Event\Event as EspoEvent;
use Espo\Core\Mail\Event\EventFactory;
use Espo\Core\Utils\Log;
use ICal\Event;
use ICal\ICal;
use Throwable;
use stdClass;
/**
* @implements Loader<Email>
*/
class IcsDataLoader implements Loader
{
/** @var array<string, string> */
private $entityTypeLinkMap = [
User::ENTITY_TYPE => Meeting::LINK_USERS,
Contact::ENTITY_TYPE => Meeting::LINK_CONTACTS,
Lead::ENTITY_TYPE => Meeting::LINK_LEADS,
];
public function __construct(private EntityManager $entityManager, private Log $log)
{}
public function process(Entity $entity, Params $params): void
{
$icsContents = $entity->get('icsContents');
if ($icsContents === null) {
return;
}
$ical = new ICal();
$ical->initString($icsContents);
/* @var ?Event $event */
$event = $ical->events()[0] ?? null;
if ($event === null) {
return;
}
if ($event->status === 'CANCELLED') {
return;
}
$espoEvent = EventFactory::createFromU01jmg3Ical($ical);
$valueMap = (object) [
'sourceEmailId' => $entity->getId(),
];
try {
$valueMap->name = $espoEvent->getName();
$valueMap->description = $espoEvent->getDescription();
$valueMap->dateStart = $espoEvent->getDateStart();
$valueMap->dateEnd = $espoEvent->getDateEnd();
$valueMap->location = $espoEvent->getLocation();
$valueMap->isAllDay = $espoEvent->isAllDay();
if ($espoEvent->isAllDay()) {
$valueMap->dateStartDate = $espoEvent->getDateStart();
$valueMap->dateEndDate = $espoEvent->getDateEnd();
}
} catch (Throwable $e) {
$this->log->warning("Error while converting ICS event '" . $entity->getId() . "': " . $e->getMessage());
return;
}
if ($this->eventAlreadyExists($espoEvent)) {
return;
}
/** @var EmailAddressRepository $emailAddressRepository */
$emailAddressRepository = $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
$attendeeEmailAddressList = $espoEvent->getAttendeeEmailAddressList();
$organizerEmailAddress = $espoEvent->getOrganizerEmailAddress();
if ($organizerEmailAddress) {
$attendeeEmailAddressList[] = $organizerEmailAddress;
}
foreach ($attendeeEmailAddressList as $address) {
$personEntity = $emailAddressRepository->getEntityByAddress($address);
if (!$personEntity) {
continue;
}
$link = $this->entityTypeLinkMap[$personEntity->getEntityType()] ?? null;
if (!$link) {
continue;
}
$idsAttribute = $link . 'Ids';
$namesAttribute = $link . 'Names';
$idList = $valueMap->$idsAttribute ?? [];
$nameMap = $valueMap->$namesAttribute ?? (object) [];
$idList[] = $personEntity->getId();
$nameMap->{$personEntity->getId()} = $personEntity->get(Field::NAME);
$valueMap->$idsAttribute = $idList;
$valueMap->$namesAttribute = $nameMap;
}
$eventData = (object) [
'valueMap' => $valueMap,
'uid' => $espoEvent->getUid(),
'createdEvent' => null,
];
$this->loadCreatedEvent($entity, $espoEvent, $eventData);
$entity->set('icsEventData', $eventData);
$entity->set('icsEventDateStart', $espoEvent->getDateStart());
if ($espoEvent->isAllDay()) {
$entity->set('icsEventDateStartDate', $espoEvent->getDateStart());
}
}
private function loadCreatedEvent(Entity $entity, EspoEvent $espoEvent, stdClass $eventData): void
{
$emailSameEvent = $this->entityManager
->getRDBRepository(Email::ENTITY_TYPE)
->where([
'icsEventUid' => $espoEvent->getUid(),
'id!=' => $entity->getId()
])
->findOne();
if (!$emailSameEvent) {
return;
}
if (
!$emailSameEvent->get('createdEventId') ||
!$emailSameEvent->get('createdEventType')
) {
return;
}
$createdEvent = $this->entityManager
->getEntityById($emailSameEvent->get('createdEventType'), $emailSameEvent->get('createdEventId'));
if (!$createdEvent) {
return;
}
$eventData->createdEvent = (object) [
'id' => $createdEvent->getId(),
'entityType' => $emailSameEvent->getEntityType(),
'name' => $createdEvent->get(Field::NAME),
];
}
private function eventAlreadyExists(EspoEvent $espoEvent): bool
{
$id = $espoEvent->getUid();
if (!$id) {
return false;
}
$found1 = $this->entityManager
->getRDBRepository(Meeting::ENTITY_TYPE)
->select([Attribute::ID])
->where([Attribute::ID => $id])
->findOne();
if ($found1) {
return true;
}
$found2 = $this->entityManager
->getRDBRepository(Call::ENTITY_TYPE)
->select([Attribute::ID])
->where([Attribute::ID => $id])
->findOne();
if ($found2) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,128 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Email;
use Espo\Core\Name\Field;
use Espo\Core\Name\Link;
use Espo\ORM\Entity;
use Espo\ORM\Name\Attribute;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Entities\Email;
use Espo\Entities\User;
/**
* @implements Loader<Email>
*/
class StringDataLoader implements Loader
{
private const LINK_EMAIL_ADDRESSES = Link::EMAIL_ADDRESSES;
/** @var array<string, string> */
private $fromEmailAddressNameCache = [];
public function __construct(
private EntityManager $entityManager,
private User $user
) {}
public function process(Entity $entity, Params $params): void
{
/** @var Email $entity */
$userEmailAddressIdList = [];
$emailAddressCollection = $this->entityManager
->getRelation($this->user, self::LINK_EMAIL_ADDRESSES)
->select([Attribute::ID])
->find();
foreach ($emailAddressCollection as $emailAddress) {
$userEmailAddressIdList[] = $emailAddress->getId();
}
if (
in_array($entity->get('fromEmailAddressId'), $userEmailAddressIdList) ||
$entity->get('createdById') === $this->user->getId() &&
$entity->getStatus() === Email::STATUS_SENT
) {
$entity->loadLinkMultipleField('toEmailAddresses');
$idList = $entity->get('toEmailAddressesIds');
$names = $entity->get('toEmailAddressesNames');
if (empty($idList)) {
return;
}
$list = [];
foreach ($idList as $emailAddressId) {
$person = $this->getEmailAddressRepository()->getEntityByAddressId($emailAddressId, null, true);
$list[] = $person ? $person->get(Field::NAME) : $names->$emailAddressId;
}
$entity->set('personStringData', 'To: ' . implode(', ', $list));
return;
}
/** @var ?string $fromEmailAddressId */
$fromEmailAddressId = $entity->get('fromEmailAddressId');
if (!$fromEmailAddressId) {
return;
}
if (!array_key_exists($fromEmailAddressId, $this->fromEmailAddressNameCache)) {
$person = $this->getEmailAddressRepository()->getEntityByAddressId($fromEmailAddressId, null, true);
$fromName = $person?->get(Field::NAME);
$this->fromEmailAddressNameCache[$fromEmailAddressId] = $fromName;
}
$fromName =
$this->fromEmailAddressNameCache[$fromEmailAddressId] ??
$entity->get('fromName') ??
$entity->get('fromEmailAddressName');
$entity->set('personStringData', $fromName);
}
private function getEmailAddressRepository(): EmailAddressRepository
{
/** @var EmailAddressRepository */
return $this->entityManager->getRepository('EmailAddress');
}
}

View File

@@ -0,0 +1,90 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Email;
use Espo\Entities\Email;
use Espo\ORM\Entity;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Entities\User;
use Espo\ORM\Name\Attribute;
/**
* @implements Loader<Email>
*/
class UserColumnsLoader implements Loader
{
public function __construct(
private EntityManager $entityManager,
private User $user
) {}
public function process(Entity $entity, Params $params): void
{
$emailUser = $this->entityManager
->getRDBRepository(Email::RELATIONSHIP_EMAIL_USER)
->select([
Email::USERS_COLUMN_IS_READ,
Email::USERS_COLUMN_IS_IMPORTANT,
Email::USERS_COLUMN_IN_TRASH,
Email::USERS_COLUMN_IN_ARCHIVE,
])
->where([
Attribute::DELETED => false,
'userId' => $this->user->getId(),
'emailId' => $entity->getId(),
])
->findOne();
if (!$emailUser) {
$entity->set(Email::USERS_COLUMN_IS_READ, null);
$entity->clear(Email::USERS_COLUMN_IS_IMPORTANT);
$entity->clear(Email::USERS_COLUMN_IN_TRASH);
$entity->clear(Email::USERS_COLUMN_IN_ARCHIVE);
return;
}
$values = [
Email::USERS_COLUMN_IS_READ => $emailUser->get(Email::USERS_COLUMN_IS_READ),
Email::USERS_COLUMN_IS_IMPORTANT => $emailUser->get(Email::USERS_COLUMN_IS_IMPORTANT),
Email::USERS_COLUMN_IN_TRASH => $emailUser->get(Email::USERS_COLUMN_IN_TRASH),
Email::USERS_COLUMN_IN_ARCHIVE => $emailUser->get(Email::USERS_COLUMN_IN_ARCHIVE),
'isUsersSent' => $entity->getSentBy()?->getId() === $this->user->getId(),
];
$entity->setMultiple($values);
foreach ($values as $key => $value) {
$entity->setFetched($key, $value);
}
}
}

View File

@@ -0,0 +1,63 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Import;
use Espo\Entities\Import;
use Espo\ORM\Entity;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Repositories\Import as ImportRepository;
/**
* @implements Loader<Import>
*/
class CountsLoader implements Loader
{
public function __construct(private EntityManager $entityManager)
{}
public function process(Entity $entity, Params $params): void
{
/** @var ImportRepository $repository */
$repository = $this->entityManager->getRepository('Import');
$importedCount = $repository->countResultRecords($entity, 'imported');
$duplicateCount = $repository->countResultRecords($entity, 'duplicates');
$updatedCount = $repository->countResultRecords($entity, 'updated');
$entity->set([
'importedCount' => $importedCount,
'duplicateCount' => $duplicateCount,
'updatedCount' => $updatedCount,
]);
}
}

View File

@@ -0,0 +1,53 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\InboundEmail;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\Mail\ConfigDataProvider;
use Espo\Entities\InboundEmail;
use Espo\ORM\Entity;
/**
* @implements Loader<InboundEmail>
*/
class IsSystemLoader implements Loader
{
public function __construct(
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
$isSystem = $entity->getEmailAddress() === $this->configDataProvider->getSystemOutboundAddress();
$entity->set('isSystem', $isSystem);
}
}

View File

@@ -0,0 +1,159 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\LeadCapture;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Config\ApplicationConfig;
use Espo\Core\Utils\FieldUtil;
use Espo\Core\Utils\Util;
use Espo\Entities\LeadCapture;
use Espo\Modules\Crm\Entities\Lead;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Type\AttributeType;
/**
* @implements Loader<LeadCapture>
*/
class ExampleLoader implements Loader
{
public function __construct(
private FieldUtil $fieldUtil,
private ApplicationConfig $applicationConfig,
private EntityManager $entityManager,
private Config $config,
) {}
public function process(Entity $entity, Params $params): void
{
$entity->set('exampleRequestMethod', 'POST');
$entity->set('exampleRequestHeaders', [
'Content-Type: application/json',
]);
$this->processRequestUrl($entity);
$this->processRequestPayload($entity);
$this->processFormUrl($entity);
}
private function processRequestUrl(LeadCapture $entity): void
{
$apiKey = $entity->getApiKey();
$siteUrl = $this->applicationConfig->getSiteUrl();
if (!$apiKey) {
return;
}
$requestUrl = "$siteUrl/api/v1/LeadCapture/$apiKey";
$entity->set('exampleRequestUrl', $requestUrl);
}
private function processRequestPayload(LeadCapture $entity): void
{
$requestPayload = "```\n{\n";
$attributeList = [];
$attributeIgnoreList = [
'emailAddressIsOptedOut',
'phoneNumberIsOptedOut',
'emailAddressIsInvalid',
'phoneNumberIsInvalid',
'emailAddressData',
'phoneNumberData',
];
foreach ($entity->getFieldList() as $field) {
foreach ($this->fieldUtil->getActualAttributeList(Lead::ENTITY_TYPE, $field) as $attribute) {
if (!in_array($attribute, $attributeIgnoreList)) {
$attributeList[] = $attribute;
}
}
}
$seed = $this->entityManager->getNewEntity(Lead::ENTITY_TYPE);
foreach ($attributeList as $i => $attribute) {
$value = strtoupper(Util::camelCaseToUnderscore($attribute));
if (
in_array(
$seed->getAttributeType($attribute), [
Entity::VARCHAR,
Entity::TEXT,
AttributeType::DATETIME,
AttributeType::DATE,
]
)
) {
$value = '"' . $value . '"';
}
$requestPayload .= " \"" . $attribute . "\": " . $value;
if ($i < count($attributeList) - 1) {
$requestPayload .= ",";
}
$requestPayload .= "\n";
}
$requestPayload .= "}\n```";
$entity->set('exampleRequestPayload', $requestPayload);
}
private function processFormUrl(LeadCapture $entity): void
{
$formId = $entity->getFormId();
$siteUrl = $this->getSiteUrl();
if (!$entity->hasFormEnabled() || !$formId) {
/** @noinspection PhpRedundantOptionalArgumentInspection */
$entity->set('formUrl', null);
return;
}
$formUrl = "$siteUrl?entryPoint=leadCaptureForm&id=$formId";
$entity->set('formUrl', $formUrl);
}
private function getSiteUrl(): string
{
return $this->config->get('leadCaptureSiteUrl') ?? $this->applicationConfig->getSiteUrl();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Note;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\Note;
use Espo\ORM\Entity;
use Espo\Tools\Stream\MassNotePreparator;
/**
* @implements Loader<Note>
*/
class AdditionalFieldsLoader implements Loader
{
public function __construct(
private MassNotePreparator $massNotePreparator,
) {}
public function process(Entity $entity, Params $params): void
{
$entity->loadAdditionalFields();
$this->massNotePreparator->prepare([$entity]);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\OAuthAccount;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\OAuthAccount;
use Espo\ORM\Entity;
use Espo\Tools\OAuth\ConfigDataProvider;
/**
* @implements Loader<OAuthAccount>
*/
class DataLoader implements Loader
{
public function __construct(
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
if (!$entity->get('providerId')) {
return;
}
$provider = $entity->getProvider();
$scope = null;
if ($provider->getScopes()) {
$scope = implode($provider->getScopeSeparator() ?? ' ', $provider->getScopes());
}
$data = [
'endpoint' => $provider->getAuthorizationEndpoint(),
'clientId' => $provider->getClientId(),
'redirectUri' => $this->configDataProvider->getRedirectUri(),
'scope' => $scope,
'prompt' => $provider->getAuthorizationPrompt(),
'params' => $provider->getAuthorizationParams(),
];
$entity->set('data', $data);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\OAuthProvider;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\OAuthProvider;
use Espo\ORM\Entity;
use Espo\Tools\OAuth\ConfigDataProvider;
/**
* @implements Loader<OAuthProvider>
*/
class AuthorizationRedirectUriLoader implements Loader
{
public function __construct(
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
$entity->set('authorizationRedirectUri', $this->configDataProvider->getRedirectUri());
}
}

View File

@@ -0,0 +1,64 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\Portal;
use Espo\ORM\Entity;
use Espo\Repositories\Portal as PortalRepository;
use Espo\Entities\Portal;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
/**
* @implements Loader<Portal>
*/
class UrlLoader implements Loader
{
private EntityManager $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function process(Entity $entity, Params $params): void
{
/** @var Portal $entity */
$this->getPortalRepository()->loadUrlField($entity);
}
private function getPortalRepository(): PortalRepository
{
/** @var PortalRepository */
return $this->entityManager->getRepository('Portal');
}
}

View File

@@ -0,0 +1,112 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 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\Classes\FieldProcessing\User;
use Espo\Core\Name\Field;
use Espo\Entities\AuthLogRecord;
use Espo\Entities\AuthToken;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use DateTime;
use Espo\ORM\Name\Attribute;
use Exception;
/**
* @implements Loader<User>
* @noinspection PhpUnused
*/
class LastAccessLoader implements Loader
{
private EntityManager $entityManager;
private Acl $acl;
public function __construct(EntityManager $entityManager, Acl $acl)
{
$this->entityManager = $entityManager;
$this->acl = $acl;
}
public function process(Entity $entity, Params $params): void
{
if (!$this->acl->checkField($entity->getEntityType(), 'lastAccess')) {
return;
}
$authToken = $this->entityManager
->getRDBRepository(AuthToken::ENTITY_TYPE)
->select([Attribute::ID, 'lastAccess'])
->where([
'userId' => $entity->getId(),
])
->order('lastAccess', 'DESC')
->findOne();
$lastAccess = null;
if ($authToken) {
$lastAccess = $authToken->get('lastAccess');
}
$dt = null;
if ($lastAccess) {
try {
$dt = new DateTime($lastAccess);
} catch (Exception) {}
}
$where = [
'userId' => $entity->getId(),
'isDenied' => false,
];
if ($dt) {
$where['requestTime>'] = $dt->format('U');
}
$authLogRecord = $this->entityManager
->getRDBRepository(AuthLogRecord::ENTITY_TYPE)
->select([Attribute::ID, Field::CREATED_AT])
->where($where)
->order('requestTime', true)
->findOne();
if ($authLogRecord) {
$lastAccess = $authLogRecord->get(Field::CREATED_AT);
}
$entity->set('lastAccess', $lastAccess);
}
}