Skip to content

Commit

Permalink
add: quarantine: when "adding", can copy metadata from the selected r…
Browse files Browse the repository at this point in the history
…ecord
  • Loading branch information
jygaulier committed Jul 27, 2023
1 parent ad015fb commit 05ad588
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 86 deletions.
51 changes: 44 additions & 7 deletions lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@ 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 */
$lazaretFile = $this->getLazaretFileRepository()->find($file_id);

$metadatasToSet = [];
if(!!$request->request->get('copy_meta', false)) {

$substitutedRecord = null;
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();
}
}
$metadatas = [];
foreach ($substitutedRecord->getCaption($fieldsToCopy) as $k=>$v) {
$metadatasToSet[] = ['field_name' => $k, 'value' => $v];
}
}

$ret = $lazaretManipulator->add($file_id, $keepAttributes, $attributesToKeep);

try{
Expand All @@ -132,7 +165,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!');
}

Expand Down Expand Up @@ -209,16 +248,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) {
Expand Down
Loading

0 comments on commit 05ad588

Please sign in to comment.