[otrs-cvs] ITSMConfigurationManagement/Kernel/Modules AgentITSMConfigItemEdit.pm, 1.33, 1.34

"CVS commits notifications of OTRS.org" <[email protected]>
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/ITSMConfigurationManagement/Kernel/Modules
In directory lancelot:/tmp/cvs-serv32293/Kernel/Modules

Modified Files:
	AgentITSMConfigItemEdit.pm 
Log Message:
Added new optional sysconfig option to check if config item names are unique.

Author: ub

Index: AgentITSMConfigItemEdit.pm
===================================================================
RCS file: /home/cvs/ITSMConfigurationManagement/Kernel/Modules/AgentITSMConfigItemEdit.pm,v
retrieving revision 1.33
retrieving revision 1.34
diff -2 -u -d -r1.33 -r1.34
--- AgentITSMConfigItemEdit.pm	30 Nov 2012 17:10:41 -0000	1.33
+++ AgentITSMConfigItemEdit.pm	30 Nov 2012 19:49:09 -0000	1.34
@@ -18,4 +18,5 @@
 use Kernel::System::GeneralCatalog;
 use Kernel::System::Web::UploadCache;
+use Kernel::System::VariableCheck qw(:all);
 
 use vars qw($VERSION);
@@ -184,4 +185,5 @@
     # get xml data
     my $Version = {};
+    my $NameDuplicates;
     if ( $Self->{Subaction} eq 'VersionSave' ) {
 
@@ -236,4 +238,42 @@
         );
 
+        # check, whether the feature to check for a unique name is enabled
+        if (
+            IsStringWithData( $Version->{Name} )
+            && $Self->{ConfigObject}->Get('UniqueCIName::EnableUniquenessCheck')
+            )
+        {
+
+            if ( $Self->{ConfigObject}->{Debug} > 0 ) {
+                $Self->{LogObject}->Log(
+                    Priority => 'debug',
+                    Message  => "Checking for duplicate names (ClassID: $ConfigItem->{ClassID}, "
+                        . "Name: $Version->{Name}, ConfigItemID: $ConfigItem->{ConfigItemID})",
+                );
+            }
+
+            $NameDuplicates = $Self->{ConfigItemObject}->UniqueNameCheck(
+                ConfigItemID => $ConfigItem->{ConfigItemID},
+                ClassID      => $ConfigItem->{ClassID},
+                Name         => $Version->{Name},
+            );
+
+            # stop processing if the name is not unique
+            if ( IsArrayRefWithData($NameDuplicates) ) {
+
+                $AllRequired = 0;
+
+                # build a string of all duplicate IDs
+                my $NameDuplicatesString = join ', ', @{$NameDuplicates};
+
+                $Self->{LogObject}->Log(
+                    Priority => 'error',
+                    Message =>
+                        "The name $Version->{Name} is already in use by the ConfigItemID(s): "
+                        . $NameDuplicatesString,
+                );
+            }
+        }
+
         # save version to database
         if ( $SubmitSave && $AllRequired ) {
@@ -384,4 +424,9 @@
     }
 
+    # check for name duplicates
+    if ( IsArrayRefWithData($NameDuplicates) ) {
+        $RowNameInvalid = 'ServerError';
+    }
+
     # output name block
     $Self->{LayoutObject}->Block(
@@ -393,4 +438,36 @@
     );
 
+    if ( IsStringWithData($RowNameInvalid) && !IsArrayRefWithData($NameDuplicates) ) {
+
+        if ( $Self->{ConfigObject}->{Debug} > 0 ) {
+            $Self->{LogObject}->Log(
+                Priority => 'debug',
+                Message  => "Rendering default error block",
+            );
+        }
+
+        $Self->{LayoutObject}->Block(
+            Name => 'RowNameErrorDefault',
+        );
+    }
+    elsif ( IsArrayRefWithData($NameDuplicates) ) {
+
+        my $DuplicateString = join ', ', @{$NameDuplicates};
+
+        if ( $Self->{ConfigObject}->{Debug} > 0 ) {
+            $Self->{LogObject}->Log(
+                Priority => 'debug',
+                Message  => "Rendering block for duplicates (IDs: $DuplicateString) error message",
+            );
+        }
+
+        $Self->{LayoutObject}->Block(
+            Name => 'RowNameErrorDuplicates',
+            Data => {
+                Duplicates => $DuplicateString,
+            },
+        );
+    }
+
     # get deployment state list
     my $DeplStateList = $Self->{GeneralCatalogObject}->ItemList(
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.