diff --git a/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php b/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php index 85cf5195d0..29cfe6d77e 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php @@ -132,6 +132,38 @@ public function addElement(Request $request, $file_id) /** @var LazaretManipulator $lazaretManipulator */ $lazaretManipulator = $this->app['manipulator.lazaret']; + //Check if the chosen record is eligible to the substitution + $recordId = $request->request->get('record_id'); + /** @var LazaretFile $lazaretFile */ + $metadatasToSet = []; + if($recordId !== "" && !!$request->request->get('copy_meta', false)) { + + $substitutedRecord = null; + + $lazaretFile = $this->getLazaretFileRepository()->find($file_id); + foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $r) { + if ($r->getRecordId() === (int)$recordId) { + $substitutedRecord = $r; + break; + } + } + if (!$substitutedRecord) { + $ret['message'] = $this->app->trans('The destination record provided is not allowed'); + + return $this->app->json($ret); + } + + $fieldsToCopy = []; + foreach ($substitutedRecord->getDatabox()->get_meta_structure() as $df) { + if(!$df->is_readonly()) { + $fieldsToCopy[] = $df->get_name(); + } + } + foreach ($substitutedRecord->getCaption($fieldsToCopy) as $k=>$v) { + $metadatasToSet[] = ['field_name' => $k, 'value' => $v]; + } + } + $ret = $lazaretManipulator->add($file_id, $keepAttributes, $attributesToKeep); try{ @@ -140,7 +172,13 @@ public function addElement(Request $request, $file_id) $postStatus = (array) $request->request->get('status'); // update status $this->updateRecordStatus($record, $postStatus); - }catch(\Exception $e){ + + if(!empty($metadatasToSet)) { + $actions = json_decode(json_encode(['metadatas' => $metadatasToSet])); + $record->setMetadatasByActions($actions); + } + } + catch(\Exception $e){ $ret['message'] = $this->app->trans('An error occured when wanting to change status!'); } @@ -229,16 +267,14 @@ public function acceptElement(Request $request, $file_id) return $this->app->json($ret); } - $found = false; //Check if the chosen record is eligible to the substitution + $found = false; foreach ($lazaretFile->getRecordsToSubstitute($this->app) as $record) { - if ($record->getRecordId() !== (int) $recordId) { - continue; + if ($record->getRecordId() === (int) $recordId) { + $found = true; + break; } - - $found = true; - break; } if (!$found) { diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php index 7ff511332a..3ca74cac8d 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V2.php @@ -104,13 +104,16 @@ public function connect(Application $app) $controllers->match('/search/', 'controller.api.v2.search:searchAction'); + /** @uses LazaretController::quarantineItemEmptyAction */ $controllers->delete('/quarantine/', 'controller.api.v2.lazaret:quarantineItemEmptyAction') ->bind('api_v2_quarantine_empty'); + /** @uses LazaretController::quarantineItemDeleteAction */ $controller = $controllers->delete('/quarantine/item/{lazaret_id}/', 'controller.api.v2.lazaret:quarantineItemDeleteAction') ->bind('api_v2_quarantine_item_delete'); $this->addQuarantineMiddleware($controller); + /** @uses LazaretController::quarantineItemAddAction */ $controller = $controllers->post('/quarantine/item/{lazaret_id}/add/', 'controller.api.v2.lazaret:quarantineItemAddAction') ->bind('api_v2_quarantine_item_add'); $this->addQuarantineMiddleware($controller); diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php index 53c2804fce..4b9e1d1932 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php @@ -56,32 +56,40 @@ public function connect(Application $app) $firewall->requireRight(\ACL::CANADDRECORD); }); + /** @uses LazaretController::listElement */ $controllers->get('/', 'controller.prod.lazaret:listElement') ->bind('lazaret_elements'); + /** @uses LazaretController::getElement */ $controllers->get('/{file_id}/', 'controller.prod.lazaret:getElement') ->assert('file_id', '\d+') ->bind('lazaret_element'); + /** @uses LazaretController::addElement */ $controllers->post('/{file_id}/force-add/', 'controller.prod.lazaret:addElement') ->assert('file_id', '\d+') ->bind('lazaret_force_add'); + /** @uses LazaretController::denyElement */ $controllers->post('/{file_id}/deny/', 'controller.prod.lazaret:denyElement') ->assert('file_id', '\d+') ->bind('lazaret_deny_element'); + /** @uses LazaretController::emptyLazaret */ $controllers->post('/empty/', 'controller.prod.lazaret:emptyLazaret') ->bind('lazaret_empty'); + /** @uses LazaretController::acceptElement */ $controllers->post('/{file_id}/accept/', 'controller.prod.lazaret:acceptElement') ->assert('file_id', '\d+') ->bind('lazaret_accept'); + /** @uses LazaretController::thumbnailElement */ $controllers->get('/{file_id}/thumbnail/', 'controller.prod.lazaret:thumbnailElement') ->assert('file_id', '\d+') ->bind('lazaret_thumbnail'); + /** @uses LazaretController::getDestinationStatus */ $controllers->get('/{databox_id}/{record_id}/status', 'controller.prod.lazaret:getDestinationStatus') ->assert('databox_id', '\d+') ->assert('record_id', '\d+') diff --git a/templates/web/prod/upload/lazaret.html.twig b/templates/web/prod/upload/lazaret.html.twig index 74cdce9c19..62b84a5a0d 100644 --- a/templates/web/prod/upload/lazaret.html.twig +++ b/templates/web/prod/upload/lazaret.html.twig @@ -33,8 +33,9 @@