acl->get('dataPrivacyPermission') === 'no') { throw new Forbidden(); } if ($this->serviceFactory->checkExists($entityType)) { $service = $this->serviceFactory->create($entityType); } else { $service = $this->serviceFactory->create('Record'); $service->setEntityType($entityType); } $entity = $this->entityManager->getEntity($entityType, $id); if (!$entity) { throw new NotFound(); } if (!$this->acl->check($entity, 'edit')) { throw new Forbidden("No edit access."); } $forbiddenFieldList = $this->acl->getScopeForbiddenFieldList($entityType, 'edit'); foreach ($fieldList as $field) { if (in_array($field, $forbiddenFieldList)) { throw new Forbidden("Field '{$field}' is forbidden to edit."); } } $service->loadAdditionalFields($entity); $filedManager = $this->fieldManagerUtil; foreach ($fieldList as $field) { $type = $this->metadata->get(['entityDefs', $entityType, 'fields', $field, 'type']); $attributeList = $filedManager->getActualAttributeList($entityType, $field); if ($type === 'email') { $emailAddressList = $entity->get('emailAddresses'); foreach ($emailAddressList as $emailAddress) { if ( $this ->aclManager ->getImplementation('EmailAddress') ->checkEditInEntity($this->user, $emailAddress, $entity) ) { $emailAddress->set('name', 'ERASED:' . $emailAddress->id); $emailAddress->set('optOut', true); $this->entityManager->saveEntity($emailAddress); } } $entity->clear($field); $entity->clear($field . 'Data'); continue; } else if ($type === 'phone') { $phoneNumberList = $entity->get('phoneNumbers'); foreach ($phoneNumberList as $phoneNumber) { if ( $this ->aclManager ->getImplementation('PhoneNumber') ->checkEditInEntity($this->user, $phoneNumber, $entity) ) { $phoneNumber->set('name', 'ERASED:' . $phoneNumber->id); $this->entityManager->saveEntity($phoneNumber); } } $entity->clear($field); $entity->clear($field . 'Data'); continue; } else if ($type === 'file' || $type === 'image') { $attachmentId = $entity->get($field . 'Id'); if ($attachmentId) { $attachment = $this->entityManager->getEntity('Attachment', $attachmentId); $this->entityManager->removeEntity($attachment); } } else if ($type === 'attachmentMultiple') { $attachmentList = $entity->get($field); foreach ($attachmentList as $attachment) { $this->entityManager->removeEntity($attachment); } } foreach ($attributeList as $attribute) { if (in_array($entity->getAttributeType($attribute), [$entity::VARCHAR, $entity::TEXT]) && $entity->get($attribute)) { $entity->set($attribute, null); } else { $entity->set($attribute, null); } } } $this->entityManager->saveEntity($entity); return true; } }