acl->check('Import'); } private function getImportService(): Service { return $this->injectableFactory->create(Service::class); } public function postActionUploadFile(Request $request): stdClass { $contents = $request->getBodyContents() ?? ''; $attachmentId = $this->getImportService()->uploadFile($contents); return (object) [ 'attachmentId' => $attachmentId ]; } public function postActionRevert(Request $request): bool { $data = $request->getParsedBody(); $this->getImportService()->revert($data->id); return true; } public function postActionRemoveDuplicates(Request $request): bool { $data = $request->getParsedBody(); if (empty($data->id)) { throw new BadRequest(); } $this->getImportService()->removeDuplicates($data->id); return true; } public function postActionCreate(Request $request, Response $response): stdClass { $data = $request->getParsedBody(); $entityType = $data->entityType ?? null; $attributeList = $data->attributeList ?? null; $attachmentId = $data->attachmentId ?? null; if (!is_array($attributeList)) { throw new BadRequest("No attributeList."); } if (!$attachmentId) { throw new BadRequest("No attachmentId."); } if (!$entityType) { throw new BadRequest("No entityType."); } $params = ImportParams::fromRaw($data); $result = $this->getImportService()->import( $entityType, $attributeList, $attachmentId, $params ); return $result->getValueMap(); } public function postActionUnmarkAsDuplicate(Request $request): bool { $data = $request->getParsedBody(); if ( empty($data->id) || empty($data->entityType) || empty($data->entityId) ) { throw new BadRequest(); } $this->getImportService()->unmarkAsDuplicate($data->id, $data->entityType, $data->entityId); return true; } /** * @throws BadRequest * @throws \Espo\Core\Exceptions\NotFound */ public function postActionExportErrors(Request $request): stdClass { $id = $request->getParsedBody()->id ?? null; if (!$id) { throw new BadRequest("No `id`."); } $attachmentId = $this->getImportService()->exportErrors($id); return (object) [ 'attachmentId' => $attachmentId, ]; } public function putActionUpdate(Request $request, Response $response): stdClass { throw new Forbidden(); } public function postActionCreateLink(Request $request): bool { throw new Forbidden(); } public function deleteActionRemoveLink(Request $request): bool { throw new Forbidden(); } }