From 90becc2d2e436b5cf4c7b467b3c69549c90c7949 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 22 Jul 2014 10:21:53 +0200 Subject: [PATCH] Bug 10212: Use the update_or_create DBIC method when possible Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- C4/Utils/DataTables/ColumnsSettings.pm | 29 +++----------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/C4/Utils/DataTables/ColumnsSettings.pm b/C4/Utils/DataTables/ColumnsSettings.pm index 8b8c79fb5a..ed8d9acfd6 100644 --- a/C4/Utils/DataTables/ColumnsSettings.pm +++ b/C4/Utils/DataTables/ColumnsSettings.pm @@ -67,39 +67,16 @@ sub update_columns { $c->{is_hidden} //= 0; $c->{cannot_be_toggled} //= 0; - my $column = $schema->resultset('ColumnsSetting')->search( + $schema->resultset('ColumnsSetting')->update_or_create( { module => $c->{module}, page => $c->{page}, tablename => $c->{tablename}, columnname => $c->{columnname}, + is_hidden => $c->{is_hidden}, + cannot_be_toggled => $c->{cannot_be_toggled}, } ); - if ( $column->count ) { - $column = $column->first; - $column->update( - { - module => $c->{module}, - page => $c->{page}, - tablename => $c->{tablename}, - columnname => $c->{columnname}, - is_hidden => $c->{is_hidden}, - cannot_be_toggled => $c->{cannot_be_toggled}, - } - ); - } - else { - $schema->resultset('ColumnsSetting')->create( - { - module => $c->{module}, - page => $c->{page}, - tablename => $c->{tablename}, - columnname => $c->{columnname}, - is_hidden => $c->{is_hidden}, - cannot_be_toggled => $c->{cannot_be_toggled}, - } - ); - } } } -- 2.39.5