[otrs-cvs] ITSMConfigurationManagement/Kernel/System/ITSMConfigItem Definition.pm, 1.10, 1.11

"CVS commits notifications of OTRS.org" <[email protected]> Fri, 14 Jun 2013 10:51:08 +0000
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/ITSMConfigurationManagement/Kernel/System/ITSMConfigItem
In directory lancelot:/tmp/cvs-serv25018/Kernel/System/ITSMConfigItem

Modified Files:
	Definition.pm 
Log Message:
Fixed bug# 5333 - CI erroneous definition no longer editable.

Author: ub

Index: Definition.pm
===================================================================
RCS file: /home/cvs/ITSMConfigurationManagement/Kernel/System/ITSMConfigItem/Definition.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -2 -u -d -r1.10 -r1.11
--- Definition.pm	31 Aug 2012 09:51:50 -0000	1.10
+++ Definition.pm	14 Jun 2013 10:51:03 -0000	1.11
@@ -1,5 +1,5 @@
 # --
 # Kernel/System/ITSMConfigItem/Definition.pm - sub module of ITSMConfigItem.pm with definition functions
-# Copyright (C) 2001-2012 OTRS AG, http://otrs.org/
+# Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
 # --
 # $Id$
@@ -317,5 +317,6 @@
 
     my $True = $ConfigItemObject->DefinitionCheck(
-        Definition => 'the definition code',
+        Definition      => 'the definition code',
+        CheckSubElement => 1,                 # (optional, default 0, to check sub elements recursively)
     );
 
@@ -334,6 +335,15 @@
     }
 
-    my $Definition = eval $Param{Definition};
+    # if check sub elements is enabled, we must not evaluate the expression
+    # because this has been done in an earlier recursion step already
+    my $Definition;
+    if ( $Param{CheckSubElement} ) {
+        $Definition = $Param{Definition};
+    }
+    else {
+        $Definition = eval $Param{Definition};
+    }
 
+    # check if definition exists at all
     if ( !$Definition ) {
         $Self->{LogObject}->Log(
@@ -344,4 +354,5 @@
     }
 
+    # definition must be an array
     if ( ref $Definition ne 'ARRAY' ) {
         $Self->{LogObject}->Log(
@@ -352,5 +363,41 @@
     }
 
-    # recursion check
+    # check each definition attribute
+    for my $Attribute ( @{$Definition} ) {
+
+        # each definition attribute must be a hash reference with data
+        if ( !$Attribute || ref $Attribute ne 'HASH' || !%{$Attribute} ) {
+            $Self->{LogObject}->Log(
+                Priority => 'error',
+                Message =>
+                    'Invalid Definition! At least one definition attribute is not a hash reference.',
+            );
+            return;
+        }
+
+        # recursion check for Sub-Elements
+        for my $Key ( sort keys %{$Attribute} ) {
+
+            my $Value = $Attribute->{$Key};
+
+            if ( $Key eq 'Sub' && ref $Value eq 'ARRAY' ) {
+
+                # check the sub array
+                my $Check = $Self->DefinitionCheck(
+                    Definition      => $Value,
+                    CheckSubElement => 1,
+                );
+
+                if ( !$Check ) {
+                    $Self->{LogObject}->Log(
+                        Priority => 'error',
+                        Message =>
+                            "Invalid Sub-Definition of element with the key '$Attribute->{Key}'.",
+                    );
+                    return;
+                }
+            }
+        }
+    }
 
     return 1;
---------------------------------------------------------------------
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