acl->getPermissionLevel('dataPrivacyPermission') === Table::LEVEL_NO) { throw new Forbidden(); } $service = $this->recordServiceContainer->get($entityType); $entity = $this->entityManager->getEntity($entityType, $id); if (!$entity) { throw new NotFound(); } if (!$this->acl->check($entity, Table::ACTION_EDIT)) { throw new Forbidden("No edit access."); } $forbiddenFieldList = $this->acl->getScopeForbiddenFieldList($entityType, Table::ACTION_EDIT); foreach ($fieldList as $field) { if (in_array($field, $forbiddenFieldList)) { throw new Forbidden("Field '{$field}' is forbidden to edit."); } } $service->loadAdditionalFields($entity); $fieldUtil = $this->fieldUtil; foreach ($fieldList as $field) { $type = $this->metadata->get(['entityDefs', $entityType, 'fields', $field, 'type']); $attributeList = $fieldUtil->getActualAttributeList($entityType, $field); if ($type === 'email') { $emailAddressList = $entity->get('emailAddresses'); foreach ($emailAddressList as $emailAddress) { if ( $this->emailAddressAccessChecker ->checkEdit($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->phoneNumberAccessChecker ->checkEdit($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->getEntityById('Attachment', $attachmentId); if ($attachment) { $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); } }