[otrs-cvs] ImportExport/Kernel/System ImportExport.pm,1.12,1.13

cvs-log at otrs.org cvs-log at otrs.org
Wed Feb 6 17:47:31 GMT 2008


Comments:
Update of /home/cvs/ImportExport/Kernel/System
In directory lancelot:/tmp/cvs-serv30966/Kernel/System

Modified Files:
	ImportExport.pm 
Log Message:
Improved import/export features.

Author: mh

Index: ImportExport.pm
===================================================================
RCS file: /home/cvs/ImportExport/Kernel/System/ImportExport.pm,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** ImportExport.pm	5 Feb 2008 19:23:56 -0000	1.12
--- ImportExport.pm	6 Feb 2008 17:47:26 -0000	1.13
***************
*** 1078,1081 ****
--- 1078,1093 ----
      if ( defined $Param{MappingID} ) {
  
+         # delete existing object mapping data
+         $Self->MappingObjectDataDelete(
+             MappingID => $Param{MappingID},
+             UserID    => $Param{UserID},
+         );
+ 
+         # delete existing format mapping data
+         $Self->MappingFormatDataDelete(
+             MappingID => $Param{MappingID},
+             UserID    => $Param{UserID},
+         );
+ 
          # quote
          $Param{MappingID} = $Self->{DBObject}->Quote( $Param{MappingID}, 'Integer' );
***************
*** 1096,1099 ****
--- 1108,1132 ----
      else {
  
+         # get mapping list
+         my $MappingList = $Self->MappingList(
+             TemplateID => $Param{TemplateID},
+             UserID     => $Param{UserID},
+         );
+ 
+         for my $MappingID ( @{$MappingList} ) {
+ 
+             # delete existing object mapping data
+             $Self->MappingObjectDataDelete(
+                 MappingID => $MappingID,
+                 UserID    => $Param{UserID},
+             );
+ 
+             # delete existing format mapping data
+             $Self->MappingFormatDataDelete(
+                 MappingID => $MappingID,
+                 UserID    => $Param{UserID},
+             );
+         }
+ 
          # delete all mapping rows of this template
          return $Self->{DBObject}->Do(
***************
*** 1328,1331 ****
--- 1361,1526 ----
  }
  
+ =item MappingObjectDataDelete()
+ 
+ delete the existing object data of a mapping
+ 
+     my $True = $ImportExportObject->MappingObjectDataDelete(
+         MappingID => 123,
+         UserID    => 1,
+     );
+ 
+     or
+ 
+     my $True = $ImportExportObject->MappingObjectDataDelete(
+         MappingID => [1,44,166,5],
+         UserID    => 1,
+     );
+ 
+ =cut
+ 
+ sub MappingObjectDataDelete {
+     my ( $Self, %Param ) = @_;
+ 
+     # check needed stuff
+     for my $Argument (qw(MappingID UserID)) {
+         if ( !$Param{$Argument} ) {
+             $Self->{LogObject}->Log(
+                 Priority => 'error',
+                 Message  => "Need $Argument!"
+             );
+             return;
+         }
+     }
+ 
+     if ( !ref $Param{MappingID} ) {
+         $Param{MappingID} = [ $Param{MappingID} ];
+     }
+     elsif ( ref $Param{MappingID} ne 'ARRAY' ) {
+         $Self->{LogObject}->Log(
+             Priority => 'error',
+             Message  => 'MappingID must be an array reference or a string!',
+         );
+         return;
+     }
+ 
+     # quote
+     for my $MappingID ( @{ $Param{MappingID} } ) {
+         $MappingID = $Self->{DBObject}->Quote( $MappingID, 'Integer' );
+     }
+ 
+     # create the mapping id string
+     my $MappingIDString = join ',', @{ $Param{MappingID} };
+ 
+     # delete mapping object data
+     return $Self->{DBObject}->Do(
+         SQL => "DELETE FROM imexport_mapping_object WHERE mapping_id IN ( $MappingIDString )",
+     );
+ }
+ 
+ =item MappingObjectDataSave()
+ 
+ save the object data of a mapping
+ 
+     my $True = $ImportExportObject->MappingObjectDataSave(
+         MappingID         => 123,
+         MappingObjectData => $HashRef,
+         UserID            => 1,
+     );
+ 
+ =cut
+ 
+ sub MappingObjectDataSave {
+     my ( $Self, %Param ) = @_;
+ 
+     # check needed stuff
+     for my $Argument (qw(MappingID MappingObjectData UserID)) {
+         if ( !$Param{$Argument} ) {
+             $Self->{LogObject}->Log(
+                 Priority => 'error',
+                 Message  => "Need $Argument!"
+             );
+             return;
+         }
+     }
+ 
+     if ( ref $Param{MappingObjectData} ne 'HASH' ) {
+         $Self->{LogObject}->Log(
+             Priority => 'error',
+             Message  => 'MappingObjectData must be an hash reference!',
+         );
+         return;
+     }
+ 
+     # delete existing object mapping data
+     $Self->MappingObjectDataDelete(
+         MappingID => $Param{MappingID},
+         UserID    => $Param{UserID},
+     );
+ 
+     DATAKEY:
+     for my $DataKey ( keys %{ $Param{MappingObjectData} } ) {
+ 
+         # quote
+         my $QDataKey   = $Self->{DBObject}->Quote($DataKey);
+         my $QDataValue = $Self->{DBObject}->Quote( $Param{MappingObjectData}->{$DataKey} );
+ 
+         next DATAKEY if !defined $QDataKey;
+         next DATAKEY if !defined $QDataValue;
+ 
+         # insert one mapping object row
+         $Self->{DBObject}->Do(
+             SQL => "INSERT INTO imexport_mapping_object "
+                 . "(mapping_id, data_key, data_value) VALUES "
+                 . "($Param{MappingID}, '$QDataKey', '$QDataValue')"
+         );
+     }
+ 
+     return 1;
+ }
+ 
+ =item MappingObjectDataGet()
+ 
+ get the object data of a mapping
+ 
+     my $ObjectDataRef = $ImportExportObject->MappingObjectDataGet(
+         MappingID => 123,
+         UserID    => 1,
+     );
+ 
+ =cut
+ 
+ sub MappingObjectDataGet {
+     my ( $Self, %Param ) = @_;
+ 
+     # check needed stuff
+     for my $Argument (qw(MappingID UserID)) {
+         if ( !$Param{$Argument} ) {
+             $Self->{LogObject}->Log(
+                 Priority => 'error',
+                 Message  => "Need $Argument!"
+             );
+             return;
+         }
+     }
+ 
+     # quote
+     $Param{MappingID} = $Self->{DBObject}->Quote( $Param{MappingID}, 'Integer' );
+ 
+     # create sql string
+     my $SQL = "SELECT data_key, data_value FROM imexport_mapping_object WHERE "
+         . "mapping_id = $Param{MappingID}";
+ 
+     # ask database
+     $Self->{DBObject}->Prepare( SQL => $SQL );
+ 
+     # fetch the result
+     my %MappingObjectData;
+     while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
+         $MappingObjectData{ $Row[0] } = $Row[1];
+     }
+ 
+     return \%MappingObjectData;
+ }
+ 
  =item MappingFormatAttributesGet()
  
***************
*** 1375,1378 ****
--- 1570,1735 ----
  }
  
+ =item MappingFormatDataDelete()
+ 
+ delete the existing format data of a mapping
+ 
+     my $True = $ImportExportObject->MappingFormatDataDelete(
+         MappingID => 123,
+         UserID    => 1,
+     );
+ 
+     or
+ 
+     my $True = $ImportExportObject->MappingFormatDataDelete(
+         MappingID => [1,44,166,5],
+         UserID    => 1,
+     );
+ 
+ =cut
+ 
+ sub MappingFormatDataDelete {
+     my ( $Self, %Param ) = @_;
+ 
+     # check needed stuff
+     for my $Argument (qw(MappingID UserID)) {
+         if ( !$Param{$Argument} ) {
+             $Self->{LogObject}->Log(
+                 Priority => 'error',
+                 Message  => "Need $Argument!"
+             );
+             return;
+         }
+     }
+ 
+     if ( !ref $Param{MappingID} ) {
+         $Param{MappingID} = [ $Param{MappingID} ];
+     }
+     elsif ( ref $Param{MappingID} ne 'ARRAY' ) {
+         $Self->{LogObject}->Log(
+             Priority => 'error',
+             Message  => 'MappingID must be an array reference or a string!',
+         );
+         return;
+     }
+ 
+     # quote
+     for my $MappingID ( @{ $Param{MappingID} } ) {
+         $MappingID = $Self->{DBObject}->Quote( $MappingID, 'Integer' );
+     }
+ 
+     # create the mapping id string
+     my $MappingIDString = join ',', @{ $Param{MappingID} };
+ 
+     # delete mapping format data
+     return $Self->{DBObject}->Do(
+         SQL => "DELETE FROM imexport_mapping_format WHERE mapping_id IN ( $MappingIDString )",
+     );
+ }
+ 
+ =item MappingFormatDataSave()
+ 
+ save the format data of a mapping
+ 
+     my $True = $ImportExportObject->MappingFormatDataSave(
+         MappingID         => 123,
+         MappingFormatData => $HashRef,
+         UserID            => 1,
+     );
+ 
+ =cut
+ 
+ sub MappingFormatDataSave {
+     my ( $Self, %Param ) = @_;
+ 
+     # check needed stuff
+     for my $Argument (qw(MappingID MappingFormatData UserID)) {
+         if ( !$Param{$Argument} ) {
+             $Self->{LogObject}->Log(
+                 Priority => 'error',
+                 Message  => "Need $Argument!"
+             );
+             return;
+         }
+     }
+ 
+     if ( ref $Param{MappingFormatData} ne 'HASH' ) {
+         $Self->{LogObject}->Log(
+             Priority => 'error',
+             Message  => 'MappingFormatData must be an hash reference!',
+         );
+         return;
+     }
+ 
+     # delete existing format mapping data
+     $Self->MappingFormatDataDelete(
+         MappingID => $Param{MappingID},
+         UserID    => $Param{UserID},
+     );
+ 
+     DATAKEY:
+     for my $DataKey ( keys %{ $Param{MappingFormatData} } ) {
+ 
+         # quote
+         my $QDataKey   = $Self->{DBObject}->Quote($DataKey);
+         my $QDataValue = $Self->{DBObject}->Quote( $Param{MappingFormatData}->{$DataKey} );
+ 
+         next DATAKEY if !defined $QDataKey;
+         next DATAKEY if !defined $QDataValue;
+ 
+         # insert one mapping format row
+         $Self->{DBObject}->Do(
+             SQL => "INSERT INTO imexport_mapping_format "
+                 . "(mapping_id, data_key, data_value) VALUES "
+                 . "($Param{MappingID}, '$QDataKey', '$QDataValue')"
+         );
+     }
+ 
+     return 1;
+ }
+ 
+ =item MappingFormatDataGet()
+ 
+ get the format data of a mapping
+ 
+     my $ObjectDataRef = $ImportExportObject->MappingFormatDataGet(
+         MappingID => 123,
+         UserID    => 1,
+     );
+ 
+ =cut
+ 
+ sub MappingFormatDataGet {
+     my ( $Self, %Param ) = @_;
+ 
+     # check needed stuff
+     for my $Argument (qw(MappingID UserID)) {
+         if ( !$Param{$Argument} ) {
+             $Self->{LogObject}->Log(
+                 Priority => 'error',
+                 Message  => "Need $Argument!"
+             );
+             return;
+         }
+     }
+ 
+     # quote
+     $Param{MappingID} = $Self->{DBObject}->Quote( $Param{MappingID}, 'Integer' );
+ 
+     # create sql string
+     my $SQL = "SELECT data_key, data_value FROM imexport_mapping_format WHERE "
+         . "mapping_id = $Param{MappingID}";
+ 
+     # ask database
+     $Self->{DBObject}->Prepare( SQL => $SQL );
+ 
+     # fetch the result
+     my %MappingFormatData;
+     while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
+         $MappingFormatData{ $Row[0] } = $Row[1];
+     }
+ 
+     return \%MappingFormatData;
+ }
+ 
  =item _LoadBackend()
  


More information about the cvs-log mailing list