stream create related many-many fix, options constants

This commit is contained in:
Yuri Kuznetsov
2025-01-02 17:52:12 +02:00
parent 86d4a5f78b
commit e5c2ec3371
8 changed files with 30 additions and 20 deletions
@@ -217,6 +217,7 @@ class LinkMultipleSaver
$repository->getRelation($entity, $name)->relateById($id, $data, [
SaveOption::SKIP_HOOKS => $skipHooks,
SaveOption::SILENT => $entity->isNew(),
self::RELATE_OPTION => $entity->hasLinkMultipleField($name),
]);
}
@@ -38,6 +38,7 @@ class SaveOption
{
/**
* Silent. Boolean.
* Skip stream notes, notifications, webhooks.
*/
public const SILENT = 'silent';
/**
@@ -97,4 +98,14 @@ class SaveOption
* @since 8.4.0
*/
public const MASS_UPDATE = 'massUpdate';
/**
* Skip stream notes. Boolean.
* @since 9.0.0
*/
public const NO_STREAM = 'noStream';
/**
* Skip notification. Boolean.
* @since 9.0.0
*/
public const NO_NOTIFICATIONS = 'noNotifications';
}
@@ -49,7 +49,7 @@ class AssignmentEmailNotification
{
if (
!empty($options[SaveOption::SILENT]) ||
!empty($options['noNotifications'])
!empty($options[SaveOption::NO_NOTIFICATIONS])
) {
return;
}
@@ -49,7 +49,7 @@ class Notifications
*/
public function afterSave(Entity $entity, array $options): void
{
if (!empty($options[SaveOption::SILENT]) || !empty($options['noNotifications'])) {
if (!empty($options[SaveOption::SILENT]) || !empty($options[SaveOption::NO_NOTIFICATIONS])) {
return;
}
@@ -61,7 +61,7 @@ class Notifications
*/
public function beforeRemove(Entity $entity, array $options): void
{
if (!empty($options[SaveOption::SILENT]) || !empty($options['noNotifications'])) {
if (!empty($options[SaveOption::SILENT]) || !empty($options[SaveOption::NO_NOTIFICATIONS])) {
return;
}
@@ -54,7 +54,7 @@ class StreamNotesAcl
*/
public function afterSave(Entity $entity, array $options): void
{
if (!empty($options['noStream'])) {
if (!empty($options[SaveOption::NO_STREAM])) {
return;
}
+2 -2
View File
@@ -578,8 +578,8 @@ class Import
}
$this->entityManager->saveEntity($entity, [
'noStream' => true,
'noNotifications' => true,
SaveOption::NO_STREAM => true,
SaveOption::NO_NOTIFICATIONS => true,
SaveOption::IMPORT => true,
SaveOption::SILENT => $params->isSilentMode(),
]);
+4 -4
View File
@@ -274,8 +274,8 @@ class Service
}
$this->entityManager->removeEntity($entity, [
'noStream' => true,
'noNotifications' => true,
SaveOption::NO_STREAM => true,
SaveOption::NO_NOTIFICATIONS => true,
SaveOption::SILENT => true,
SaveOption::IMPORT => true,
]);
@@ -403,8 +403,8 @@ class Service
$this->deleteRelations($entity);
$this->entityManager->removeEntity($entity, [
'noStream' => true,
'noNotifications' => true,
SaveOption::NO_STREAM => true,
SaveOption::NO_NOTIFICATIONS => true,
SaveOption::SILENT => true,
SaveOption::IMPORT => true,
]);
@@ -57,8 +57,6 @@ use Espo\Tools\Stream\Jobs\ControlFollowers as ControlFollowersJob;
*/
class HookProcessor
{
private const OPTION_NO_STREAM = 'noStream';
/** @var array<string, bool> */
private $hasStreamCache = [];
/** @var array<string, bool> */
@@ -81,7 +79,7 @@ class HookProcessor
{
if (
!$this->checkHasStream($entity->getEntityType()) ||
$options->get(self::OPTION_NO_STREAM) ||
$options->get(SaveOption::NO_STREAM) ||
$options->get(SaveOption::SILENT)
) {
return;
@@ -107,7 +105,7 @@ class HookProcessor
if (
$entity->isNew() &&
empty($options[self::OPTION_NO_STREAM]) &&
empty($options[SaveOption::NO_STREAM]) &&
empty($options[SaveOption::SILENT]) &&
$this->metadata->get(['scopes', $entity->getEntityType(), 'object'])
) {
@@ -172,7 +170,7 @@ class HookProcessor
continue;
}
if ($type === Entity::HAS_MANY) {
if ($type === Entity::HAS_MANY || $type === Entity::MANY_MANY) {
$this->handleCreateRelatedHasMany($entity, $relation, $notifiedEntityTypeList, $options);
/** @noinspection PhpUnnecessaryStopStatementInspection */
@@ -400,7 +398,7 @@ class HookProcessor
$this->service->followEntityMass($entity, $userIdList);
}
if (empty($options[self::OPTION_NO_STREAM]) && empty($options[SaveOption::SILENT])) {
if (empty($options[SaveOption::NO_STREAM]) && empty($options[SaveOption::SILENT])) {
$this->service->noteCreate($entity, $options);
}
@@ -438,7 +436,7 @@ class HookProcessor
*/
private function afterSaveStreamNotNew1(CoreEntity $entity, array $options): void
{
if (!empty($options[self::OPTION_NO_STREAM]) || !empty($options[SaveOption::SILENT])) {
if (!empty($options[SaveOption::NO_STREAM]) || !empty($options[SaveOption::SILENT])) {
return;
}
@@ -605,7 +603,7 @@ class HookProcessor
$foreignLink = $entity->getRelationParam($link, RelationParam::FOREIGN);
if (
!empty($options[self::OPTION_NO_STREAM]) ||
!empty($options[SaveOption::NO_STREAM]) ||
!empty($options[SaveOption::SILENT]) ||
!$this->metadata->get(['scopes', $entityType, 'object'])
) {
@@ -638,7 +636,7 @@ class HookProcessor
$foreignLink = $entity->getRelationParam($link, RelationParam::FOREIGN);
if (
!empty($options[self::OPTION_NO_STREAM]) ||
!empty($options[SaveOption::NO_STREAM]) ||
!empty($options[SaveOption::SILENT]) ||
!$this->metadata->get(['scopes', $entityType, 'object'])
) {
@@ -672,7 +670,7 @@ class HookProcessor
return;
}
if (!empty($options[self::OPTION_NO_STREAM]) || !empty($options[SaveOption::SILENT])) {
if (!empty($options[SaveOption::NO_STREAM]) || !empty($options[SaveOption::SILENT])) {
return;
}