Skip to content

Commit

Permalink
Issue #2298: Accepted CodePolicy suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaerter authored and svenoe committed Feb 26, 2024
1 parent a5c05cb commit b9a6b40
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
1 change: 1 addition & 0 deletions Kernel/System/DynamicField/Backend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ our @ObjectDependencies = (
'Kernel::System::DynamicFieldValue',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::Web::FormCache',
);

=head1 NAME
Expand Down
2 changes: 2 additions & 0 deletions Kernel/System/DynamicField/Driver/BaseReference.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ use Kernel::System::VariableCheck qw(IsArrayRefWithData IsStringWithData);

our @ObjectDependencies = (
'Kernel::Config',
'Kernel::Output::HTML::Layout',
'Kernel::System::DB',
'Kernel::System::DynamicFieldValue',
'Kernel::System::Log',
'Kernel::System::Web::FormCache',
);

=head1 NAME
Expand Down
11 changes: 7 additions & 4 deletions Kernel/System/DynamicField/Driver/Lens.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ use Kernel::Language qw(Translatable);

our @ObjectDependencies = (
'Kernel::Config',
'Kernel::Output::HTML::Layout',
'Kernel::System::DB',
'Kernel::System::DynamicField',
'Kernel::System::DynamicField::Backend',
'Kernel::System::DynamicFieldValue',
'Kernel::System::Log',
'Kernel::System::Web::FormCache',
'Kernel::System::Web::Request',
);

Expand Down Expand Up @@ -643,7 +645,7 @@ sub GetFieldState {
my $ReferenceID = $DFParam->{ $DynamicFieldConfig->{Config}{ReferenceDFName} } ? $DFParam->{ $DynamicFieldConfig->{Config}{ReferenceDFName} }[0] : undef;

# get the current value of the referenced attribute field if an object is referenced
if ( $ReferenceID ) {
if ($ReferenceID) {
$AttributeFieldValue = $Self->ValueGet(
DynamicFieldConfig => $DynamicFieldConfig,

Expand All @@ -668,7 +670,7 @@ sub GetFieldState {
{
my $ReferenceDFName = $DynamicFieldConfig->{Config}{ReferenceDFName};

# if the value would change, we need to verify that the user is really allowed
# if the value would change, we need to verify that the user is really allowed
# to access the provided referenced object via this form
# this is the case if either the referenced object was shown via a search (1)
# or is currently stored for the edited ticket/ci/... (2)
Expand All @@ -678,7 +680,8 @@ sub GetFieldState {
);

my $Allowed = 0;
if ( $LastSearchResults ) {
if ($LastSearchResults) {

# if a search has already been performed for this form id
$Allowed = ( grep { $_ eq $ReferenceID } $LastSearchResults->@* ) ? 1 : 0;
}
Expand All @@ -687,7 +690,7 @@ sub GetFieldState {
# TODO
}

if ( $Allowed ) {
if ($Allowed) {
$Return{NewValue} = $AttributeFieldValue;

# already write the new value to DFParam, for possible values check further down
Expand Down
34 changes: 20 additions & 14 deletions Kernel/System/Web/FormCache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ use Kernel::System::VariableCheck qw(IsHashRefWithData);

our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::DB',
'Kernel::System::Encode',
'Kernel::System::Log',
'Kernel::System::Storable',
'Kernel::System::Web::UploadCache',
);

=head1 NAME
Expand All @@ -38,7 +43,7 @@ Kernel::System::Web::FormCache - a cache which stores relevant form data
=head1 DESCRIPTION
All form data which has to be stored server side, except the upload cache.
All form data which has to be stored server side, except the upload cache.
=head1 PUBLIC INTERFACE
Expand Down Expand Up @@ -75,8 +80,8 @@ sub PrepareFormID {
my ( $Self, %Param ) = @_;

# check required params
for my $Needed ( qw/LayoutObject ParamObject/ ){
if ( !$Param{ $Needed } ) {
for my $Needed (qw/LayoutObject ParamObject/) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
Expand Down Expand Up @@ -110,8 +115,8 @@ sub GetFormData {
my ( $Self, %Param ) = @_;

# check required params
for my $Needed ( qw/LayoutObject/ ){
if ( !$Param{ $Needed } ) {
for my $Needed (qw/LayoutObject/) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
Expand Down Expand Up @@ -152,9 +157,10 @@ sub GetFormData {

ROW:
while ( my @Row = $DBObject->FetchrowArray() ) {

# unserialized values can be handled directly
if ( !$Row[2] ) {
$FormData{$Row[0]} = $Row[1];
$FormData{ $Row[0] } = $Row[1];

next ROW;
}
Expand All @@ -166,7 +172,7 @@ sub GetFormData {

$EncodeObject->EncodeOutput( \$Value );

$FormData{$Row[0]} = $Value;
$FormData{ $Row[0] } = $Value;
}

$Self->{Cache}{$SessionID}{$FormID} = \%FormData;
Expand All @@ -192,8 +198,8 @@ sub SetFormData {
my ( $Self, %Param ) = @_;

# check required params
for my $Needed ( qw/LayoutObject Key/ ){
if ( !$Param{ $Needed } ) {
for my $Needed (qw/LayoutObject Key/) {
if ( !$Param{$Needed} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $Needed!",
Expand Down Expand Up @@ -230,6 +236,7 @@ create a new Form ID - usually this will be called by PrepareFormID() rather tha
=cut

sub FormIDCreate {

# return a new form id - this is also used by Web::UploadCache
return time() . '.' . rand(12341241);
}
Expand Down Expand Up @@ -268,15 +275,14 @@ sub FormIDRemove {

if ( $Param{SessionID} ) {
push @SQLWhere, 'session_id = ?';
push @Bind, \$Param{SessionID};
push @Bind, \$Param{SessionID};
}

if ( $Param{FormID} ) {
push @SQLWhere, 'form_id = ?';
push @Bind, \$Param{FormID};
push @Bind, \$Param{FormID};
}


my $Success = $Kernel::OM->Get('Kernel::System::DB')->Do(
SQL => 'DELETE FROM form_cache WHERE' . join( ' AND ', @SQLWhere ),
Bind => \@Bind,
Expand Down Expand Up @@ -330,10 +336,10 @@ sub DESTROY {
push @KeysToDelete, $Key;

# undefined values will just be deleted
next KEY if !defined $Data->{ $Key };
next KEY if !defined $Data->{$Key};

my $Serialized = 0;
my $Value = $Data->{ $Key };
my $Value = $Data->{$Key};
if ( ref $Value ) {
$Value = encode_base64(
$StorableObject->Serialize( Data => $Value )
Expand Down
1 change: 1 addition & 0 deletions Kernel/System/Web/UploadCache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use warnings;

our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Web::FormCache',
);

=head1 NAME
Expand Down

0 comments on commit b9a6b40

Please sign in to comment.