Skip to content

Commit

Permalink
rewrite update to transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 3, 2024
1 parent f1d9d75 commit 004d099
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,31 @@ public function update(Request $request, Entity $entity)
case '0':

$xml_file = $this->deleteTags($updated_entity['metadata']);
$entity->update([
'name_en' => $updated_entity['name_en'],
'name_cs' => $updated_entity['name_cs'],
'description_en' => $updated_entity['description_en'],
'description_cs' => $updated_entity['description_cs'],
'cocov1' => $updated_entity['cocov1'],
'sirtfi' => $updated_entity['sirtfi'],
'metadata' => $updated_entity['metadata'],
'xml_file' => $xml_file,
]);

if ($entity->type->value === 'idp') {
$entity->update(['rs' => $updated_entity['rs']]);
}

DB::transaction(function () use ($entity, $updated_entity, $xml_file) {
$entity->update([
'name_en' => $updated_entity['name_en'],
'name_cs' => $updated_entity['name_cs'],
'description_en' => $updated_entity['description_en'],
'description_cs' => $updated_entity['description_cs'],
'cocov1' => $updated_entity['cocov1'],
'sirtfi' => $updated_entity['sirtfi'],
'metadata' => $updated_entity['metadata'],
'xml_file' => $xml_file,
]);

if ($entity->type->value === 'idp') {
$entity->update(['rs' => $updated_entity['rs']]);
}
});

if (! $entity->wasChanged()) {
return redirect()
->back()
->with('status', __('entities.not_changed'));
}

//TODO updateChain
/* Bus::chain([
new GitUpdateEntity($entity, Auth::user()),
function () use ($entity) {
Expand Down

0 comments on commit 004d099

Please sign in to comment.