Initial commit
This commit is contained in:
61
application/Espo/Hooks/AddressCountry/ClearCache.php
Normal file
61
application/Espo/Hooks/AddressCountry/ClearCache.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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\Hooks\AddressCountry;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterRemove;
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\Utils\DataCache;
|
||||
use Espo\Entities\AddressCountry;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\RemoveOptions;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterRemove<AddressCountry>
|
||||
* @implements AfterSave<AddressCountry>
|
||||
*/
|
||||
class ClearCache implements AfterRemove, AfterSave
|
||||
{
|
||||
private const CACHE_KEY = 'addressCountryData';
|
||||
|
||||
public function __construct(
|
||||
private DataCache $dataCache,
|
||||
) {}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
$this->dataCache->clear(self::CACHE_KEY);
|
||||
}
|
||||
|
||||
public function afterRemove(Entity $entity, RemoveOptions $options): void
|
||||
{
|
||||
$this->dataCache->clear(self::CACHE_KEY);
|
||||
}
|
||||
}
|
||||
99
application/Espo/Hooks/Attachment/RemoveFile.php
Normal file
99
application/Espo/Hooks/Attachment/RemoveFile.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?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\Hooks\Attachment;
|
||||
|
||||
use Espo\Core\FileStorage\Manager as FileStorageManager;
|
||||
use Espo\Core\Hook\Hook\AfterRemove;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\Attachment;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Repository\Option\RemoveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterRemove<Attachment>
|
||||
*/
|
||||
class RemoveFile implements AfterRemove
|
||||
{
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private EntityManager $entityManager,
|
||||
private FileManager $fileManager,
|
||||
private FileStorageManager $fileStorageManager
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param Attachment $entity
|
||||
*/
|
||||
public function afterRemove(Entity $entity, RemoveOptions $options): void
|
||||
{
|
||||
$duplicateCount = $this->entityManager
|
||||
->getRDBRepositoryByClass(Attachment::class)
|
||||
->where([
|
||||
'OR' => [
|
||||
'sourceId' => $entity->getSourceId(),
|
||||
'id' => $entity->getSourceId(),
|
||||
]
|
||||
])
|
||||
->count();
|
||||
|
||||
if ($duplicateCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->fileStorageManager->exists($entity)) {
|
||||
$this->fileStorageManager->unlink($entity);
|
||||
}
|
||||
|
||||
$this->removeThumbs($entity);
|
||||
}
|
||||
|
||||
private function removeThumbs(Attachment $entity): void
|
||||
{
|
||||
/** @var string[] $typeList */
|
||||
$typeList = $this->metadata->get(['app', 'image', 'resizableFileTypeList']) ?? [];
|
||||
|
||||
if (!in_array($entity->getType(), $typeList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var string[] $sizeList */
|
||||
$sizeList = array_keys($this->metadata->get(['app', 'image', 'sizes']) ?? []);
|
||||
|
||||
foreach ($sizeList as $size) {
|
||||
$filePath = "data/upload/thumbs/{$entity->getSourceId()}_{$size}";
|
||||
|
||||
if ($this->fileManager->isFile($filePath)) {
|
||||
$this->fileManager->removeFile($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Tools\EmailNotification\HookProcessor;
|
||||
|
||||
class AssignmentEmailNotification
|
||||
{
|
||||
private HookProcessor $processor;
|
||||
|
||||
public function __construct(HookProcessor $processor)
|
||||
{
|
||||
$this->processor = $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function afterSave(Entity $entity, array $options): void
|
||||
{
|
||||
if (
|
||||
!empty($options[SaveOption::SILENT]) ||
|
||||
!empty($options[SaveOption::NO_NOTIFICATIONS])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->afterSave($entity);
|
||||
}
|
||||
}
|
||||
54
application/Espo/Hooks/Common/CallDeferredActions.php
Normal file
54
application/Espo/Hooks/Common/CallDeferredActions.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\ORM\Repository\Option\SaveContext;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<Entity>
|
||||
*/
|
||||
class CallDeferredActions implements AfterSave
|
||||
{
|
||||
public static int $order = 101;
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
$saveContext = SaveContext::obtainFromOptions($options);
|
||||
|
||||
if (!$saveContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
$saveContext->callDeferredActions();
|
||||
}
|
||||
}
|
||||
143
application/Espo/Hooks/Common/Collaborators.php
Normal file
143
application/Espo/Hooks/Common/Collaborators.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\Field\Link;
|
||||
use Espo\Core\Field\LinkMultiple;
|
||||
use Espo\Core\Field\LinkMultipleItem;
|
||||
use Espo\Core\Hook\Hook\BeforeSave;
|
||||
use Espo\Core\Name\Field;
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements BeforeSave<Entity>
|
||||
*/
|
||||
class Collaborators implements BeforeSave
|
||||
{
|
||||
public static int $order = 7;
|
||||
|
||||
private const FIELD_COLLABORATORS = Field::COLLABORATORS;
|
||||
private const FIELD_ASSIGNED_USERS = Field::ASSIGNED_USERS;
|
||||
private const FIELD_ASSIGNED_USER = Field::ASSIGNED_USER;
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
) {}
|
||||
|
||||
public function beforeSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$entity instanceof CoreEntity) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->hasCollaborators($entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($entity->hasLinkMultipleField(self::FIELD_ASSIGNED_USERS)) {
|
||||
$this->processAssignedUsers($entity);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processAssignedUser($entity);
|
||||
}
|
||||
|
||||
private function hasCollaborators(CoreEntity $entity): bool
|
||||
{
|
||||
if (!$this->metadata->get("scopes.{$entity->getEntityType()}.collaborators")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$entity->hasLinkMultipleField(self::FIELD_COLLABORATORS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function processAssignedUsers(CoreEntity $entity): void
|
||||
{
|
||||
if (!$entity->has(self::FIELD_COLLABORATORS . 'Ids')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$assignedUsers = $entity->getValueObject(self::FIELD_ASSIGNED_USERS);
|
||||
$collaborators = $entity->getValueObject(self::FIELD_COLLABORATORS);
|
||||
|
||||
if (
|
||||
!$assignedUsers instanceof LinkMultiple ||
|
||||
!$collaborators instanceof LinkMultiple
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$countBefore = $collaborators->getCount();
|
||||
|
||||
foreach ($assignedUsers->getList() as $assignedUser) {
|
||||
$collaborators = $collaborators->withAdded($assignedUser);
|
||||
}
|
||||
|
||||
if ($countBefore === $collaborators->getCount()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->setValueObject(self::FIELD_COLLABORATORS, $collaborators);
|
||||
}
|
||||
|
||||
private function processAssignedUser(CoreEntity $entity): void
|
||||
{
|
||||
$idAttr = self::FIELD_ASSIGNED_USER . 'Id';
|
||||
|
||||
if (!$entity->hasAttribute($idAttr) || !$entity->isAttributeChanged($idAttr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$assignedUser = $entity->getValueObject(self::FIELD_ASSIGNED_USER);
|
||||
|
||||
if (!$assignedUser instanceof Link) {
|
||||
return;
|
||||
}
|
||||
|
||||
$collaborators = $entity->getValueObject(self::FIELD_COLLABORATORS);
|
||||
|
||||
if (!$collaborators instanceof LinkMultiple) {
|
||||
return;
|
||||
}
|
||||
|
||||
$collaborators = $collaborators
|
||||
->withAdded(LinkMultipleItem::create($assignedUser->getId(), $assignedUser->getName()));
|
||||
|
||||
$entity->setValueObject(self::FIELD_COLLABORATORS, $collaborators);
|
||||
}
|
||||
}
|
||||
97
application/Espo/Hooks/Common/CurrencyConverted.php
Normal file
97
application/Espo/Hooks/Common/CurrencyConverted.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\Di;
|
||||
|
||||
class CurrencyConverted implements Di\MetadataAware, Di\ConfigAware
|
||||
{
|
||||
use Di\MetadataSetter;
|
||||
use Di\ConfigSetter;
|
||||
|
||||
public static int $order = 1;
|
||||
|
||||
public function beforeSave(Entity $entity): void
|
||||
{
|
||||
$fieldDefs = $this->metadata->get(['entityDefs', $entity->getEntityType(), 'fields'], []);
|
||||
|
||||
foreach ($fieldDefs as $fieldName => $defs) {
|
||||
if (empty($defs['type']) || $defs['type'] !== FieldType::CURRENCY_CONVERTED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$currencyFieldName = substr($fieldName, 0, -9);
|
||||
|
||||
$currencyCurrencyFieldName = $currencyFieldName . 'Currency';
|
||||
|
||||
if (
|
||||
!$entity->isAttributeChanged($currencyFieldName) &&
|
||||
!$entity->isAttributeChanged($currencyCurrencyFieldName)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($fieldDefs[$currencyFieldName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($entity->get($currencyFieldName) === null) {
|
||||
$entity->set($fieldName, null);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$currency = $entity->get($currencyCurrencyFieldName);
|
||||
$value = $entity->get($currencyFieldName);
|
||||
|
||||
if (!$currency) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rates = $this->config->get('currencyRates', []);
|
||||
$baseCurrency = $this->config->get('baseCurrency');
|
||||
$defaultCurrency = $this->config->get('defaultCurrency');
|
||||
|
||||
if ($defaultCurrency === $currency) {
|
||||
$targetValue = $value;
|
||||
} else {
|
||||
$targetValue = $value;
|
||||
$targetValue = $targetValue / ($rates[$baseCurrency] ?? 1.0);
|
||||
$targetValue = $targetValue * ($rates[$currency] ?? 1.0);
|
||||
|
||||
$targetValue = round($targetValue, 2);
|
||||
}
|
||||
|
||||
$entity->set($fieldName, $targetValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
application/Espo/Hooks/Common/CurrencyDefault.php
Normal file
69
application/Espo/Hooks/Common/CurrencyDefault.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\FieldUtil;
|
||||
|
||||
class CurrencyDefault
|
||||
{
|
||||
public static int $order = 200;
|
||||
|
||||
public function __construct(private Config $config, private FieldUtil $fieldUtil)
|
||||
{}
|
||||
|
||||
public function beforeSave(Entity $entity): void
|
||||
{
|
||||
$fieldList = $this->fieldUtil->getFieldByTypeList($entity->getEntityType(), FieldType::CURRENCY);
|
||||
|
||||
$defaultCurrency = $this->config->get('defaultCurrency');
|
||||
|
||||
foreach ($fieldList as $field) {
|
||||
$currencyAttribute = $field . 'Currency';
|
||||
|
||||
if ($entity->isNew()) {
|
||||
if ($entity->get($field) && !$entity->get($currencyAttribute)) {
|
||||
$entity->set($currencyAttribute, $defaultCurrency);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
$entity->isAttributeChanged($field) && $entity->has($currencyAttribute) &&
|
||||
!$entity->get($currencyAttribute)
|
||||
) {
|
||||
$entity->set($currencyAttribute, $defaultCurrency);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
85
application/Espo/Hooks/Common/DeleteId.php
Normal file
85
application/Espo/Hooks/Common/DeleteId.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\Hook\Hook\BeforeRemove;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\ORM\Repository\Option\RemoveOptions;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
use Espo\Core\Hook\Hook\BeforeSave;
|
||||
|
||||
/**
|
||||
* Handles 'deleteId' on soft-deletes.
|
||||
*
|
||||
* @implements BeforeSave<Entity>
|
||||
* @implements BeforeRemove<Entity>
|
||||
*/
|
||||
class DeleteId implements BeforeSave, BeforeRemove
|
||||
{
|
||||
private const ID_ATTR = 'deleteId';
|
||||
private const DELETED_ATTR = Attribute::DELETED;
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
) {}
|
||||
|
||||
public function beforeRemove(Entity $entity, RemoveOptions $options): void
|
||||
{
|
||||
if (!$this->hasDeleteId($entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->set(self::ID_ATTR, Util::generateId());
|
||||
}
|
||||
|
||||
public function beforeSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$this->hasDeleteId($entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$entity->isAttributeChanged(self::DELETED_ATTR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$deleteId = $entity->get(self::DELETED_ATTR) ? Util::generateId() : '0';
|
||||
|
||||
$entity->set(self::ID_ATTR, $deleteId);
|
||||
}
|
||||
|
||||
private function hasDeleteId(Entity $entity): bool
|
||||
{
|
||||
return $entity->hasAttribute(self::DELETED_ATTR) &&
|
||||
$this->metadata->get("entityDefs.{$entity->getEntityType()}.deleteId");
|
||||
}
|
||||
}
|
||||
62
application/Espo/Hooks/Common/FieldProcessing.php
Normal file
62
application/Espo/Hooks/Common/FieldProcessing.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\FieldProcessing\SaveProcessor;
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
|
||||
class FieldProcessing
|
||||
{
|
||||
public static int $order = -11;
|
||||
|
||||
private SaveProcessor $saveProcessor;
|
||||
|
||||
public function __construct(SaveProcessor $saveProcessor)
|
||||
{
|
||||
$this->saveProcessor = $saveProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function afterSave(Entity $entity, array $options): void
|
||||
{
|
||||
if (!empty($options['skipFieldProcessing'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$entity instanceof CoreEntity) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->saveProcessor->process($entity, $options);
|
||||
}
|
||||
}
|
||||
85
application/Espo/Hooks/Common/ForeignFields.php
Normal file
85
application/Espo/Hooks/Common/ForeignFields.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\ORM\Defs;
|
||||
use Espo\ORM\Defs\Params\AttributeParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
use Espo\ORM\Type\AttributeType;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<Entity>
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class ForeignFields implements AfterSave
|
||||
{
|
||||
public static int $order = 8;
|
||||
|
||||
public function __construct(
|
||||
private Defs $defs,
|
||||
private EntityManager $entityManager
|
||||
) {}
|
||||
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$options->get(SaveOption::API) || $entity->isNew()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$defs = $this->defs->getEntity($entity->getEntityType());
|
||||
|
||||
$foreignList = array_filter(
|
||||
$entity->getAttributeList(), fn ($it) => $entity->getAttributeType($it) === AttributeType::FOREIGN);
|
||||
|
||||
$relationList = array_map(
|
||||
fn ($it) => $defs->getAttribute($it)->getParam(AttributeParam::RELATION), $foreignList);
|
||||
$relationList = array_filter($relationList, fn ($it) => $entity->isAttributeChanged($it . 'Id'));
|
||||
$relationList = array_values($relationList);
|
||||
|
||||
if ($relationList === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$copy = $this->entityManager->getEntityById($entity->getEntityType(), $entity->getId());
|
||||
|
||||
if (!$copy) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($foreignList as $attribute) {
|
||||
$entity->set($attribute, $copy->get($attribute));
|
||||
}
|
||||
}
|
||||
}
|
||||
89
application/Espo/Hooks/Common/Formula.php
Normal file
89
application/Espo/Hooks/Common/Formula.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
use Espo\Core\Hook\Hook\BeforeSave;
|
||||
use Espo\Core\Formula\Manager as FormulaManager;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
|
||||
use Exception;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* @implements BeforeSave<Entity>
|
||||
*/
|
||||
class Formula implements BeforeSave
|
||||
{
|
||||
public static int $order = 11;
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private FormulaManager $formulaManager,
|
||||
private Log $log
|
||||
) {}
|
||||
|
||||
public function beforeSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if ($options->get('skipFormula')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$scriptList = $this->metadata->get(['formula', $entity->getEntityType(), 'beforeSaveScriptList'], []);
|
||||
|
||||
$variables = (object) [];
|
||||
|
||||
foreach ($scriptList as $script) {
|
||||
$this->runScript($script, $entity, $variables);
|
||||
}
|
||||
|
||||
$customScript = $this->metadata->get(['formula', $entity->getEntityType(), 'beforeSaveCustomScript']);
|
||||
|
||||
if (!$customScript) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->runScript($customScript, $entity, $variables);
|
||||
}
|
||||
|
||||
private function runScript(string $script, Entity $entity, stdClass $variables): void
|
||||
{
|
||||
try {
|
||||
$this->formulaManager->run($script, $entity, $variables);
|
||||
} catch (Exception $e) {
|
||||
$this->log->critical('Before-save formula script failed. {message}', [
|
||||
'message' => $e->getMessage(),
|
||||
'exception' => $e,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
application/Espo/Hooks/Common/NextNumber.php
Normal file
52
application/Espo/Hooks/Common/NextNumber.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\FieldProcessing\NextNumber\BeforeSaveProcessor as Processor;
|
||||
|
||||
class NextNumber
|
||||
{
|
||||
public function __construct(private Processor $processor)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function beforeSave(Entity $entity, array $options): void
|
||||
{
|
||||
if (!$entity instanceof CoreEntity) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->process($entity, $options);
|
||||
}
|
||||
}
|
||||
82
application/Espo/Hooks/Common/Notifications.php
Normal file
82
application/Espo/Hooks/Common/Notifications.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\Tools\Notification\HookProcessor;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class Notifications
|
||||
{
|
||||
public static int $order = 10;
|
||||
|
||||
private HookProcessor $processor;
|
||||
|
||||
public function __construct(HookProcessor $processor)
|
||||
{
|
||||
$this->processor = $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function afterSave(Entity $entity, array $options): void
|
||||
{
|
||||
if (!empty($options[SaveOption::SILENT]) || !empty($options[SaveOption::NO_NOTIFICATIONS])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->afterSave($entity, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function beforeRemove(Entity $entity, array $options): void
|
||||
{
|
||||
if (!empty($options[SaveOption::SILENT]) || !empty($options[SaveOption::NO_NOTIFICATIONS])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->beforeRemove($entity, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function afterRemove(Entity $entity, array $options): void
|
||||
{
|
||||
if (!empty($options[SaveOption::SILENT])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->afterRemove($entity);
|
||||
}
|
||||
}
|
||||
107
application/Espo/Hooks/Common/Stream.php
Normal file
107
application/Espo/Hooks/Common/Stream.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterRelate;
|
||||
use Espo\Core\Hook\Hook\AfterRemove;
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\Hook\Hook\AfterUnrelate;
|
||||
use Espo\Core\Hook\Hook\BeforeSave;
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\RelateOptions;
|
||||
use Espo\ORM\Repository\Option\RemoveOptions;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
use Espo\ORM\Repository\Option\UnrelateOptions;
|
||||
use Espo\Tools\Stream\HookProcessor;
|
||||
|
||||
class Stream implements BeforeSave, AfterSave, AfterRemove, AfterRelate, AfterUnrelate
|
||||
{
|
||||
public static int $order = 9;
|
||||
|
||||
public function __construct(private HookProcessor $processor)
|
||||
{}
|
||||
|
||||
public function beforeSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if ($options->get(SaveOption::SILENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->beforeSave($entity, $options);
|
||||
}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if ($options->get(SaveOption::SILENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->afterSave($entity, $options->toAssoc());
|
||||
}
|
||||
|
||||
public function afterRemove(Entity $entity, RemoveOptions $options): void
|
||||
{
|
||||
if ($options->get(SaveOption::SILENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->afterRemove($entity, $options);
|
||||
}
|
||||
|
||||
public function afterRelate(
|
||||
Entity $entity,
|
||||
string $relationName,
|
||||
Entity $relatedEntity,
|
||||
array $columnData,
|
||||
RelateOptions $options
|
||||
): void {
|
||||
|
||||
if ($options->get(SaveOption::SILENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->afterRelate($entity, $relatedEntity, $relationName, $options->toAssoc());
|
||||
}
|
||||
|
||||
public function afterUnrelate(
|
||||
Entity $entity,
|
||||
string $relationName,
|
||||
Entity $relatedEntity,
|
||||
UnrelateOptions $options
|
||||
): void {
|
||||
|
||||
if ($options->get(SaveOption::SILENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->afterUnrelate($entity, $relatedEntity, $relationName, $options->toAssoc());
|
||||
}
|
||||
}
|
||||
75
application/Espo/Hooks/Common/StreamNotesAcl.php
Normal file
75
application/Espo/Hooks/Common/StreamNotesAcl.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Tools\Stream\NoteAcl\AccessModifier;
|
||||
|
||||
/**
|
||||
* Notes having `related` or `superParent` are subjects to access control
|
||||
* through `users` and `teams` fields.
|
||||
*
|
||||
* When users or teams of `related` or `parent` record are changed
|
||||
* the note record will be changed too.
|
||||
*
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class StreamNotesAcl
|
||||
{
|
||||
public static int $order = 10;
|
||||
|
||||
public function __construct(private AccessModifier $processor)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function afterSave(Entity $entity, array $options): void
|
||||
{
|
||||
if (!empty($options[SaveOption::NO_STREAM])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($options[SaveOption::SILENT])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($options['skipStreamNotesAcl'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($entity->isNew()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->processor->process($entity);
|
||||
}
|
||||
}
|
||||
49
application/Espo/Hooks/Common/VersionNumber.php
Normal file
49
application/Espo/Hooks/Common/VersionNumber.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Core\FieldProcessing\VersionNumber\BeforeSaveProcessor as Processor;
|
||||
|
||||
class VersionNumber
|
||||
{
|
||||
private Processor $processor;
|
||||
|
||||
public function __construct(Processor $processor)
|
||||
{
|
||||
$this->processor = $processor;
|
||||
}
|
||||
|
||||
public function beforeSave(Entity $entity): void
|
||||
{
|
||||
$this->processor->process($entity);
|
||||
}
|
||||
}
|
||||
73
application/Espo/Hooks/Common/WebSocketSubmit.php
Normal file
73
application/Espo/Hooks/Common/WebSocketSubmit.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\WebSocket\ConfigDataProvider;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\WebSocket\Submission as WebSocketSubmission;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<Entity>
|
||||
*/
|
||||
class WebSocketSubmit implements AfterSave
|
||||
{
|
||||
public static int $order = 20;
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private WebSocketSubmission $webSocketSubmission,
|
||||
) {}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if ($options->get(SaveOption::SILENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($entity->isNew()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$scope = $entity->getEntityType();
|
||||
$id = $entity->getId();
|
||||
|
||||
if (!$this->metadata->get("scopes.$scope.object")) {
|
||||
return;
|
||||
}
|
||||
|
||||
$topic = "recordUpdate.$scope.$id";
|
||||
|
||||
$this->webSocketSubmission->submit($topic);
|
||||
}
|
||||
}
|
||||
104
application/Espo/Hooks/Common/Webhook.php
Normal file
104
application/Espo/Hooks/Common/Webhook.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?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\Hooks\Common;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterRemove;
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\Webhook\Options;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\ORM\Entity as CoreEntity;
|
||||
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Webhook\Manager as WebhookManager;
|
||||
use Espo\ORM\Repository\Option\RemoveOptions;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<Entity>
|
||||
* @implements AfterRemove<Entity>
|
||||
*/
|
||||
class Webhook implements AfterSave, AfterRemove
|
||||
{
|
||||
public static int $order = 101;
|
||||
|
||||
public function __construct(
|
||||
private Metadata $metadata,
|
||||
private WebhookManager $webhookManager,
|
||||
private User $user,
|
||||
) {}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (
|
||||
$this->toSkip($options, $entity) ||
|
||||
!$entity instanceof CoreEntity
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$userIdParam = $entity->isNew() ? SaveOption::CREATED_BY_ID : SaveOption::MODIFIED_BY_ID;
|
||||
|
||||
$eventOptions = new Options(
|
||||
userId: $options->get($userIdParam) ?? $this->user->getId(),
|
||||
);
|
||||
|
||||
if ($entity->isNew()) {
|
||||
$this->webhookManager->processCreate($entity, $eventOptions);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->webhookManager->processUpdate($entity, $eventOptions);
|
||||
}
|
||||
|
||||
public function afterRemove(Entity $entity, RemoveOptions $options): void
|
||||
{
|
||||
if (
|
||||
$this->toSkip($options, $entity) ||
|
||||
!$entity instanceof CoreEntity
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventOptions = new Options(
|
||||
userId: $options->get(SaveOption::MODIFIED_BY_ID) ?? $this->user->getId(),
|
||||
);
|
||||
|
||||
$this->webhookManager->processDelete($entity, $eventOptions);
|
||||
}
|
||||
|
||||
private function toSkip(SaveOptions|RemoveOptions $options, Entity $entity): bool
|
||||
{
|
||||
return $options->get(SaveOption::SILENT) ||
|
||||
!$this->metadata->get("scopes.{$entity->getEntityType()}.object");
|
||||
}
|
||||
}
|
||||
82
application/Espo/Hooks/EmailFilter/CacheClearing.php
Normal file
82
application/Espo/Hooks/EmailFilter/CacheClearing.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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\Hooks\EmailFilter;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterRemove;
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\Utils\DataCache;
|
||||
use Espo\Entities\EmailFilter;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\RemoveOptions;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<EmailFilter>
|
||||
* @implements AfterRemove<EmailFilter>
|
||||
*/
|
||||
class CacheClearing implements AfterSave, AfterRemove
|
||||
{
|
||||
private const CACHE_KEY = 'emailFilters';
|
||||
|
||||
public function __construct(private DataCache $dataCache) {}
|
||||
|
||||
/**
|
||||
* @param EmailFilter $entity
|
||||
*/
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
$this->processEntity($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailFilter $entity
|
||||
*/
|
||||
public function afterRemove(Entity $entity, RemoveOptions $options): void
|
||||
{
|
||||
$this->processEntity($entity);
|
||||
}
|
||||
|
||||
private function processEntity(EmailFilter $entity): void
|
||||
{
|
||||
if ($entity->getParentType() !== User::ENTITY_TYPE || !$entity->getParentId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cacheKey = $this->composeCacheKey($entity->getParentId());
|
||||
|
||||
$this->dataCache->clear($cacheKey);
|
||||
}
|
||||
|
||||
private function composeCacheKey(string $userId): string
|
||||
{
|
||||
return self::CACHE_KEY . '/' . $userId;
|
||||
}
|
||||
}
|
||||
68
application/Espo/Hooks/GroupEmailFolder/Order.php
Normal file
68
application/Espo/Hooks/GroupEmailFolder/Order.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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\Hooks\GroupEmailFolder;
|
||||
|
||||
use Espo\Entities\GroupEmailFolder;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
class Order
|
||||
{
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GroupEmailFolder $entity
|
||||
*/
|
||||
public function beforeSave(Entity $entity): void
|
||||
{
|
||||
$order = $entity->getOrder();
|
||||
|
||||
if ($order !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order = $this->entityManager
|
||||
->getRDBRepositoryByClass(GroupEmailFolder::class)
|
||||
->max('order');
|
||||
|
||||
if (!$order) {
|
||||
$order = 0;
|
||||
}
|
||||
|
||||
$order++;
|
||||
|
||||
$entity->set('order', $order);
|
||||
}
|
||||
}
|
||||
69
application/Espo/Hooks/Integration/GoogleMaps.php
Normal file
69
application/Espo/Hooks/Integration/GoogleMaps.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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\Hooks\Integration;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Entities\Integration;
|
||||
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
|
||||
class GoogleMaps
|
||||
{
|
||||
private ConfigWriter $configWriter;
|
||||
|
||||
public function __construct(ConfigWriter $configWriter)
|
||||
{
|
||||
$this->configWriter = $configWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Integration $entity
|
||||
*/
|
||||
public function afterSave(Entity $entity): void
|
||||
{
|
||||
if ($entity->getId() !== 'GoogleMaps') {
|
||||
return;
|
||||
}
|
||||
|
||||
$apiKey = $entity->get('apiKey');
|
||||
$mapId = $entity->get('mapId');
|
||||
|
||||
if (!$entity->isEnabled()) {
|
||||
$apiKey = null;
|
||||
$mapId = null;
|
||||
}
|
||||
|
||||
$this->configWriter->set('googleMapsApiKey', $apiKey);
|
||||
$this->configWriter->set('googleMapsMapId', $mapId);
|
||||
|
||||
$this->configWriter->save();
|
||||
}
|
||||
}
|
||||
85
application/Espo/Hooks/LayoutSet/Removal.php
Normal file
85
application/Espo/Hooks/LayoutSet/Removal.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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\Hooks\LayoutSet;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
use Espo\Entities\LayoutSet;
|
||||
use Espo\Entities\Team;
|
||||
use Espo\Entities\Portal;
|
||||
|
||||
class Removal
|
||||
{
|
||||
private EntityManager $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LayoutSet $entity
|
||||
*/
|
||||
public function afterRemove(Entity $entity): void
|
||||
{
|
||||
$updateQuery1 = $this->entityManager
|
||||
->getQueryBuilder()
|
||||
->update()
|
||||
->in(Team::ENTITY_TYPE)
|
||||
->set([
|
||||
'layoutSetId' => null,
|
||||
])
|
||||
->where([
|
||||
'layoutSetId' => $entity->getId(),
|
||||
])
|
||||
->build();
|
||||
|
||||
$this->entityManager
|
||||
->getQueryExecutor()
|
||||
->execute($updateQuery1);
|
||||
|
||||
$updateQuery2 = $this->entityManager
|
||||
->getQueryBuilder()
|
||||
->update()
|
||||
->in(Portal::ENTITY_TYPE)
|
||||
->set([
|
||||
'layoutSetId' => null,
|
||||
])
|
||||
->where([
|
||||
'layoutSetId' => $entity->getId(),
|
||||
])
|
||||
->build();
|
||||
|
||||
$this->entityManager
|
||||
->getQueryExecutor()
|
||||
->execute($updateQuery2);
|
||||
}
|
||||
}
|
||||
62
application/Espo/Hooks/LeadCapture/ClearCache.php
Normal file
62
application/Espo/Hooks/LeadCapture/ClearCache.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Hooks\LeadCapture;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\Utils\DataCache;
|
||||
use Espo\Entities\LeadCapture;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<LeadCapture>
|
||||
*/
|
||||
class ClearCache implements AfterSave
|
||||
{
|
||||
private const CACHE_KEY_PREFIX = 'leadCaptureForm';
|
||||
|
||||
public function __construct(
|
||||
private DataCache $dataCache,
|
||||
) {}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if ($entity->isNew()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dataCache->clear($this->getCacheKey($entity));
|
||||
}
|
||||
|
||||
private function getCacheKey(LeadCapture $leadCapture): string
|
||||
{
|
||||
return self::CACHE_KEY_PREFIX . '/' . $leadCapture->getId();
|
||||
}
|
||||
}
|
||||
61
application/Espo/Hooks/Note/Mentions.php
Normal file
61
application/Espo/Hooks/Note/Mentions.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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\Hooks\Note;
|
||||
|
||||
use Espo\Core\ORM\Repository\Option\SaveOption;
|
||||
use Espo\Tools\Notification\NoteMentionHookProcessor;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Entities\Note;
|
||||
|
||||
class Mentions
|
||||
{
|
||||
public static int $order = 9;
|
||||
|
||||
private NoteMentionHookProcessor $processor;
|
||||
|
||||
public function __construct(NoteMentionHookProcessor $processor)
|
||||
{
|
||||
$this->processor = $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function beforeSave(Entity $entity, array $options): void
|
||||
{
|
||||
if (!empty($options[SaveOption::SILENT])) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert($entity instanceof Note);
|
||||
|
||||
$this->processor->beforeSave($entity);
|
||||
}
|
||||
}
|
||||
62
application/Espo/Hooks/Note/Notifications.php
Normal file
62
application/Espo/Hooks/Note/Notifications.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Hooks\Note;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Core\ORM\Repository\Option\SaveContext;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
use Espo\Tools\Notification\HookProcessor\Params;
|
||||
use Espo\Tools\Notification\NoteHookProcessor;
|
||||
use Espo\Entities\Note;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<Note>
|
||||
*/
|
||||
class Notifications implements AfterSave
|
||||
{
|
||||
public static int $order = 14;
|
||||
|
||||
public function __construct(private NoteHookProcessor $processor)
|
||||
{}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$entity->isNew() && !$options->get('forceProcessNotifications')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$saveContext = SaveContext::obtainFromOptions($options);
|
||||
|
||||
$params = new Params(actionId: $saveContext?->getActionId());
|
||||
|
||||
$this->processor->afterSave($entity, $params);
|
||||
}
|
||||
}
|
||||
66
application/Espo/Hooks/Note/StreamUpdatedAt.php
Normal file
66
application/Espo/Hooks/Note/StreamUpdatedAt.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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\Hooks\Note;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
use Espo\Entities\Note;
|
||||
use Espo\Tools\Stream\Service;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<Note>
|
||||
*/
|
||||
class StreamUpdatedAt implements AfterSave
|
||||
{
|
||||
public function __construct(private Service $service)
|
||||
{}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$entity->isNew()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
$entity->getType() !== Note::TYPE_POST ||
|
||||
!$entity->getParentType() ||
|
||||
!$this->service->checkIsEnabled($entity->getParentType())
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$entity->getParent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->service->updateStreamUpdatedAt($entity->getParent());
|
||||
}
|
||||
}
|
||||
77
application/Espo/Hooks/Note/WebSocketSubmit.php
Normal file
77
application/Espo/Hooks/Note/WebSocketSubmit.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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\Hooks\Note;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Entities\Note;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\WebSocket\Submission as WebSocketSubmission;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<Note>
|
||||
*/
|
||||
class WebSocketSubmit implements AfterSave
|
||||
{
|
||||
public static int $order = 20;
|
||||
|
||||
public function __construct(
|
||||
private WebSocketSubmission $webSocketSubmission,
|
||||
) {}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$entity->isNew()) {
|
||||
$updateTopic = "recordUpdate.Note.{$entity->getId()}";
|
||||
|
||||
$this->webSocketSubmission->submit($updateTopic);
|
||||
}
|
||||
|
||||
$parentId = $entity->getParentId();
|
||||
$parentType = $entity->getParentType();
|
||||
|
||||
if (!$parentId || !$parentType) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = (object) [
|
||||
'createdById' => $entity->getCreatedById(),
|
||||
];
|
||||
|
||||
if (!$entity->isNew()) {
|
||||
$data->noteId = $entity->getId();
|
||||
$data->pin = $entity->isAttributeChanged('isPinned');
|
||||
}
|
||||
|
||||
$topic = "streamUpdate.$parentType.$parentId";
|
||||
|
||||
$this->webSocketSubmission->submit($topic, null, $data);
|
||||
}
|
||||
}
|
||||
63
application/Espo/Hooks/Notification/WebSocketSubmit.php
Normal file
63
application/Espo/Hooks/Notification/WebSocketSubmit.php
Normal 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\Hooks\Notification;
|
||||
|
||||
use Espo\Core\Hook\Hook\AfterSave;
|
||||
use Espo\Entities\Notification;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\WebSocket\Submission as WebSocketSubmission;
|
||||
use Espo\ORM\Repository\Option\SaveOptions;
|
||||
|
||||
/**
|
||||
* @implements AfterSave<Notification>
|
||||
*/
|
||||
class WebSocketSubmit implements AfterSave
|
||||
{
|
||||
public static int $order = 20;
|
||||
|
||||
public function __construct(
|
||||
private WebSocketSubmission $webSocketSubmission,
|
||||
) {}
|
||||
|
||||
public function afterSave(Entity $entity, SaveOptions $options): void
|
||||
{
|
||||
if (!$entity->isNew()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$userId = $entity->getUserId();
|
||||
|
||||
if (!$userId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->webSocketSubmission->submit('newNotification', $userId);
|
||||
}
|
||||
}
|
||||
69
application/Espo/Hooks/Portal/WriteConfig.php
Normal file
69
application/Espo/Hooks/Portal/WriteConfig.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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\Hooks\Portal;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Entities\Portal;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\Config\ConfigWriter;
|
||||
|
||||
class WriteConfig
|
||||
{
|
||||
public function __construct(private Config $config, private ConfigWriter $configWriter)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @param Portal $entity
|
||||
*/
|
||||
public function afterSave(Entity $entity): void
|
||||
{
|
||||
if (!$entity->has('isDefault')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($entity->get('isDefault')) {
|
||||
$defaultPortalId = $this->config->get('defaultPortalId');
|
||||
|
||||
if ($defaultPortalId === $entity->getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->configWriter->set('defaultPortalId', $entity->getId());
|
||||
|
||||
$this->configWriter->save();
|
||||
}
|
||||
|
||||
if ($entity->isAttributeChanged('isDefault') && $entity->getFetched('isDefault')) {
|
||||
$this->configWriter->set('defaultPortalId', null);
|
||||
|
||||
$this->configWriter->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
114
application/Espo/Hooks/Sms/Numbers.php
Normal file
114
application/Espo/Hooks/Sms/Numbers.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?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\Hooks\Sms;
|
||||
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\Entities\Sms;
|
||||
use Espo\Entities\PhoneNumber;
|
||||
use Espo\Repositories\PhoneNumber as PhoneNumberRepository;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class Numbers
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function beforeSave(Entity $entity): void
|
||||
{
|
||||
assert($entity instanceof Sms);
|
||||
|
||||
$this->processNumbers($entity);
|
||||
}
|
||||
|
||||
private function processNumbers(Sms $entity): void
|
||||
{
|
||||
if ($entity->has('from')) {
|
||||
$this->processFrom($entity);
|
||||
}
|
||||
|
||||
if ($entity->has('to')) {
|
||||
$this->processTo($entity);
|
||||
}
|
||||
}
|
||||
|
||||
private function processFrom(Sms $entity): void
|
||||
{
|
||||
$from = $entity->get('from');
|
||||
|
||||
$entity->set('fromPhoneNumberId', null);
|
||||
$entity->set('fromEmailAddressName', null);
|
||||
|
||||
if (!$from) {
|
||||
return;
|
||||
}
|
||||
|
||||
$numberIds = $this->getPhoneNumberRepository()->getIds([$from]);
|
||||
|
||||
if (!count($numberIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->set('fromEmailAddressId', $numberIds[0]);
|
||||
$entity->set('fromEmailAddressName', $from);
|
||||
}
|
||||
|
||||
private function processTo(Sms $entity): void
|
||||
{
|
||||
$entity->setLinkMultipleIdList('toPhoneNumbers', []);
|
||||
|
||||
$to = $entity->get('to');
|
||||
|
||||
if ($to === null || !$to) {
|
||||
return;
|
||||
}
|
||||
|
||||
$numberList = array_map(
|
||||
function (string $item): string {
|
||||
return trim($item);
|
||||
},
|
||||
explode(';', $to)
|
||||
);
|
||||
|
||||
$numberIds = $this->getPhoneNumberRepository()->getIds($numberList);
|
||||
|
||||
$entity->setLinkMultipleIdList('toPhoneNumbers', $numberIds);
|
||||
}
|
||||
|
||||
private function getPhoneNumberRepository(): PhoneNumberRepository
|
||||
{
|
||||
/** @var PhoneNumberRepository */
|
||||
return $this->entityManager->getRepository(PhoneNumber::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
87
application/Espo/Hooks/User/ApiKey.php
Normal file
87
application/Espo/Hooks/User/ApiKey.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?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\Hooks\User;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Core\Utils\ApiKey as ApiKeyUtil;
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class ApiKey
|
||||
{
|
||||
private ApiKeyUtil $apiKey;
|
||||
|
||||
public function __construct(ApiKeyUtil $apiKey)
|
||||
{
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $entity
|
||||
*/
|
||||
public function afterSave(Entity $entity): void
|
||||
{
|
||||
if (!$entity->isApi()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
$entity->get('apiKey') && $entity->get('secretKey') &&
|
||||
(
|
||||
$entity->isAttributeChanged('apiKey') ||
|
||||
$entity->isAttributeChanged('authMethod')
|
||||
)
|
||||
) {
|
||||
$this->apiKey->storeSecretKeyForUserId($entity->getId(), $entity->get('secretKey'));
|
||||
}
|
||||
|
||||
if (
|
||||
$entity->isAttributeChanged('authMethod') &&
|
||||
$entity->get('authMethod') !== 'Hmac'
|
||||
) {
|
||||
$this->apiKey->removeSecretKeyForUserId($entity->getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $entity
|
||||
*/
|
||||
public function afterRemove(Entity $entity): void
|
||||
{
|
||||
if (!$entity->isApi()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($entity->get('authMethod') === 'Hmac') {
|
||||
$this->apiKey->removeSecretKeyForUserId($entity->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user