[otrs-cvs] otrs/Kernel/System CustomerCompany.pm,1.2,1.2.2.1

cvs-log at otrs.org cvs-log at otrs.org
Fri Feb 1 12:22:32 GMT 2008


Comments:
Update of /home/cvs/otrs/Kernel/System
In directory lancelot:/tmp/cvs-serv13106/Kernel/System

Modified Files:
      Tag: rel-2_2
	CustomerCompany.pm 
Log Message:
Fixed ticket# 2008012242000417 - View performance problems if more then 1000 customer companies are in the database available.

Author: martin

Index: CustomerCompany.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/CustomerCompany.pm,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -C2 -d -r1.2 -r1.2.2.1
*** CustomerCompany.pm	21 Aug 2007 11:28:51 -0000	1.2
--- CustomerCompany.pm	1 Feb 2008 12:22:27 -0000	1.2.2.1
***************
*** 1,5 ****
  # --
  # Kernel/System/CustomerCompany.pm - All customer company related function should be here eventually
! # Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/
  # --
  # $Id$
--- 1,5 ----
  # --
  # Kernel/System/CustomerCompany.pm - All customer company related function should be here eventually
! # Copyright (C) 2001-2008 OTRS AG, http://otrs.org/
  # --
  # $Id$
***************
*** 7,11 ****
  # This software comes with ABSOLUTELY NO WARRANTY. For details, see
  # the enclosed file COPYING for license information (GPL). If you
! # did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
  # --
  
--- 7,11 ----
  # This software comes with ABSOLUTELY NO WARRANTY. For details, see
  # the enclosed file COPYING for license information (GPL). If you
! # did not receive this file, see http://www.gnu.org/licenses/gpl-2.0.txt.
  # --
  
***************
*** 13,21 ****
  
  use strict;
  use Kernel::System::Valid;
  
  use vars qw(@ISA $VERSION);
! $VERSION = '$Revision$';
! $VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
  
  =head1 NAME
--- 13,22 ----
  
  use strict;
+ use warnings;
+ 
  use Kernel::System::Valid;
  
  use vars qw(@ISA $VERSION);
! $VERSION = qw($Revision$) [1];
  
  =head1 NAME
***************
*** 64,74 ****
  
  sub new {
!     my $Type = shift;
!     my %Param = @_;
      # allocate new hash for object
      my $Self = {};
!     bless ($Self, $Type);
      # check needed objects
!     foreach (qw(DBObject ConfigObject LogObject MainObject)) {
          $Self->{$_} = $Param{$_} || die "Got no $_!";
      }
--- 65,76 ----
  
  sub new {
!     my ( $Type, %Param ) = @_;
! 
      # allocate new hash for object
      my $Self = {};
!     bless( $Self, $Type );
! 
      # check needed objects
!     for (qw(DBObject ConfigObject LogObject MainObject)) {
          $Self->{$_} = $Param{$_} || die "Got no $_!";
      }
***************
*** 78,98 ****
      $Self->{CustomerCompanyTable} = $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{Table}
          || die "Need CustomerCompany->Params->Table in Kernel/Config.pm!";
!     $Self->{CustomerCompanyKey} = $Self->{ConfigObject}->Get('CustomerCompany')->{CustomerCompanyKey}
          || $Self->{ConfigObject}->Get('CustomerCompany')->{Key}
          || die "Need CustomerCompany->CustomerCompanyKey in Kernel/Config.pm!";
      $Self->{CustomerCompanyMap} = $Self->{ConfigObject}->Get('CustomerCompany')->{Map}
          || die "Need CustomerCompany->Map in Kernel/Config.pm!";
  
      # create new db connect if DSN is given
!     if ($Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{DSN}) {
          $Self->{DBObject} = Kernel::System::DB->new(
!             LogObject => $Param{LogObject},
              ConfigObject => $Param{ConfigObject},
!             MainObject => $Param{MainObject},
!             DatabaseDSN => $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{DSN},
              DatabaseUser => $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{User},
!             DatabasePw => $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{Password},
!             Type => $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{Type} || '',
!         ) || die ('Can\'t connect to database!');
          # remember that we have the DBObject not from parent call
          $Self->{NotParentDBObject} = 1;
--- 80,110 ----
      $Self->{CustomerCompanyTable} = $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{Table}
          || die "Need CustomerCompany->Params->Table in Kernel/Config.pm!";
!     $Self->{CustomerCompanyKey}
!         = $Self->{ConfigObject}->Get('CustomerCompany')->{CustomerCompanyKey}
          || $Self->{ConfigObject}->Get('CustomerCompany')->{Key}
          || die "Need CustomerCompany->CustomerCompanyKey in Kernel/Config.pm!";
      $Self->{CustomerCompanyMap} = $Self->{ConfigObject}->Get('CustomerCompany')->{Map}
          || die "Need CustomerCompany->Map in Kernel/Config.pm!";
+     $Self->{SearchPrefix} = $Self->{ConfigObject}->Get('CustomerCompany')->{'CustomerCompanySearchPrefix'};
+     if (!defined($Self->{SearchPrefix})) {
+         $Self->{SearchPrefix} = '';
+     }
+     $Self->{SearchSuffix} = $Self->{ConfigObject}->Get('CustomerCompany')->{'CustomerCompanySearchSuffix'};
+     if (!defined($Self->{SearchSuffix})) {
+         $Self->{SearchSuffix} = '*';
+     }
  
      # create new db connect if DSN is given
!     if ( $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{DSN} ) {
          $Self->{DBObject} = Kernel::System::DB->new(
!             LogObject    => $Param{LogObject},
              ConfigObject => $Param{ConfigObject},
!             MainObject   => $Param{MainObject},
!             DatabaseDSN  => $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{DSN},
              DatabaseUser => $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{User},
!             DatabasePw   => $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{Password},
!             Type         => $Self->{ConfigObject}->Get('CustomerCompany')->{Params}->{Type} || '',
!         ) || die('Can\'t connect to database!');
! 
          # remember that we have the DBObject not from parent call
          $Self->{NotParentDBObject} = 1;
***************
*** 121,130 ****
  
  sub CustomerCompanyAdd {
!     my $Self = shift;
!     my %Param = @_;
      # check needed stuff
!     foreach (qw(CustomerID UserID)) {
!         if (!$Param{$_}) {
!             $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
              return;
          }
--- 133,142 ----
  
  sub CustomerCompanyAdd {
!     my ( $Self, %Param ) = @_;
! 
      # check needed stuff
!     for (qw(CustomerID UserID)) {
!         if ( !$Param{$_} ) {
!             $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
              return;
          }
***************
*** 133,155 ****
      # build insert
      my $SQL = "INSERT INTO $Self->{CustomerCompanyTable} (";
!     foreach my $Entry (@{$Self->{CustomerCompanyMap}}) {
          $SQL .= " $Entry->[2], ";
      }
      $SQL .= "create_time, create_by, change_time, change_by)";
      $SQL .= " VALUES (";
!     foreach my $Entry (@{$Self->{CustomerCompanyMap}}) {
!         if ($Entry->[5] =~ /^int$/i) {
!             $SQL .= " ".$Self->{DBObject}->Quote($Param{$Entry->[0]}).", ";
          }
          else {
!             $SQL .= " '".$Self->{DBObject}->Quote($Param{$Entry->[0]})."', ";
          }
      }
      $SQL .= "current_timestamp, $Param{UserID}, current_timestamp, $Param{UserID})";
!     if ($Self->{DBObject}->Do(SQL => $SQL)) {
          # log notice
          $Self->{LogObject}->Log(
              Priority => 'notice',
!             Message => "CustomerCompany: '$Param{CustomerCompanyName}/$Param{CustomerID}' created successfully ($Param{UserID})!",
          );
          return $Param{CustomerID};
--- 145,169 ----
      # build insert
      my $SQL = "INSERT INTO $Self->{CustomerCompanyTable} (";
!     for my $Entry ( @{ $Self->{CustomerCompanyMap} } ) {
          $SQL .= " $Entry->[2], ";
      }
      $SQL .= "create_time, create_by, change_time, change_by)";
      $SQL .= " VALUES (";
!     for my $Entry ( @{ $Self->{CustomerCompanyMap} } ) {
!         if ( $Entry->[5] =~ /^int$/i ) {
!             $SQL .= " " . $Self->{DBObject}->Quote( $Param{ $Entry->[0] } ) . ", ";
          }
          else {
!             $SQL .= " '" . $Self->{DBObject}->Quote( $Param{ $Entry->[0] } ) . "', ";
          }
      }
      $SQL .= "current_timestamp, $Param{UserID}, current_timestamp, $Param{UserID})";
!     if ( $Self->{DBObject}->Do( SQL => $SQL ) ) {
! 
          # log notice
          $Self->{LogObject}->Log(
              Priority => 'notice',
!             Message =>
!                 "CustomerCompany: '$Param{CustomerCompanyName}/$Param{CustomerID}' created successfully ($Param{UserID})!",
          );
          return $Param{CustomerID};
***************
*** 171,200 ****
  
  sub CustomerCompanyGet {
!     my $Self = shift;
!     my %Param = @_;
      my %Data = ();
      # check needed stuff
!     if (!$Param{CustomerID}) {
!         $Self->{LogObject}->Log(Priority => 'error', Message => "Need CustomerID!");
          return;
      }
      # build select
      my $SQL = "SELECT ";
!     foreach my $Entry (@{$Self->{CustomerCompanyMap}}) {
          $SQL .= " $Entry->[2], ";
      }
!     $SQL .= $Self->{CustomerCompanyKey}.", change_time, create_time FROM $Self->{CustomerCompanyTable} WHERE ";
!     if ($Param{Name}) {
!         $SQL .= "LOWER($Self->{CustomerCompanyKey}) = LOWER('".$Self->{DBObject}->Quote($Param{Name})."')";
      }
!     elsif ($Param{CustomerID}) {
!         $SQL .= "LOWER($Self->{CustomerCompanyKey}) = LOWER('".$Self->{DBObject}->Quote($Param{CustomerID})."')";
      }
      # get initial data
!     $Self->{DBObject}->Prepare(SQL => $SQL);
!     while (my @Row = $Self->{DBObject}->FetchrowArray()) {
          my $MapCounter = 0;
!         foreach my $Entry (@{$Self->{CustomerCompanyMap}}) {
!             $Data{$Entry->[0]} = $Row[$MapCounter];
              $MapCounter++;
          }
--- 185,220 ----
  
  sub CustomerCompanyGet {
!     my ( $Self, %Param ) = @_;
! 
      my %Data = ();
+ 
      # check needed stuff
!     if ( !$Param{CustomerID} ) {
!         $Self->{LogObject}->Log( Priority => 'error', Message => "Need CustomerID!" );
          return;
      }
+ 
      # build select
      my $SQL = "SELECT ";
!     for my $Entry ( @{ $Self->{CustomerCompanyMap} } ) {
          $SQL .= " $Entry->[2], ";
      }
!     $SQL .= $Self->{CustomerCompanyKey}
!         . ", change_time, create_time FROM $Self->{CustomerCompanyTable} WHERE ";
!     if ( $Param{Name} ) {
!         $SQL .= "LOWER($Self->{CustomerCompanyKey}) = LOWER('"
!             . $Self->{DBObject}->Quote( $Param{Name} ) . "')";
      }
!     elsif ( $Param{CustomerID} ) {
!         $SQL .= "LOWER($Self->{CustomerCompanyKey}) = LOWER('"
!             . $Self->{DBObject}->Quote( $Param{CustomerID} ) . "')";
      }
+ 
      # get initial data
!     $Self->{DBObject}->Prepare( SQL => $SQL );
!     while ( my @Row = $Self->{DBObject}->FetchrowArray() ) {
          my $MapCounter = 0;
!         for my $Entry ( @{ $Self->{CustomerCompanyMap} } ) {
!             $Data{ $Entry->[0] } = $Row[$MapCounter];
              $MapCounter++;
          }
***************
*** 204,207 ****
--- 224,228 ----
          $Data{CreateTime} = $Row[$MapCounter];
      }
+ 
      # return data
      return %Data;
***************
*** 227,258 ****
  
  sub CustomerCompanyUpdate {
!     my $Self = shift;
!     my %Param = @_;
      # check needed stuff
!     foreach my $Entry (@{$Self->{CustomerCompanyMap}}) {
!         if (!$Param{$Entry->[0]} && $Entry->[4] && $Entry->[0] ne 'UserPassword') {
!             $Self->{LogObject}->Log(Priority => 'error', Message => "Need $Entry->[0]!");
              return;
          }
      }
      # update db
      my $SQL = "UPDATE $Self->{CustomerCompanyTable} SET ";
!     foreach my $Entry (@{$Self->{CustomerCompanyMap}}) {
!         if ($Entry->[5] =~ /^int$/i) {
!             $SQL .= " $Entry->[2] = ".$Self->{DBObject}->Quote($Param{$Entry->[0]}).", ";
          }
!         elsif ($Entry->[0] !~ /^UserPassword$/i) {
!             $SQL .= " $Entry->[2] = '".$Self->{DBObject}->Quote($Param{$Entry->[0]})."', ";
          }
      }
      $SQL .= " change_time = current_timestamp, ";
      $SQL .= " change_by = $Param{UserID} ";
!     $SQL .= " WHERE LOWER($Self->{CustomerCompanyKey}) = LOWER('".$Self->{DBObject}->Quote($Param{CustomerID})."')";
  
-     if ($Self->{DBObject}->Do(SQL => $SQL)) {
          # log notice
          $Self->{LogObject}->Log(
              Priority => 'notice',
!             Message => "CustomerCompany: '$Param{CustomerCompanyName}/$Param{CustomerID}' updated successfully ($Param{UserID})!",
          );
          return 1;
--- 248,283 ----
  
  sub CustomerCompanyUpdate {
!     my ( $Self, %Param ) = @_;
! 
      # check needed stuff
!     for my $Entry ( @{ $Self->{CustomerCompanyMap} } ) {
!         if ( !$Param{ $Entry->[0] } && $Entry->[4] && $Entry->[0] ne 'UserPassword' ) {
!             $Self->{LogObject}->Log( Priority => 'error', Message => "Need $Entry->[0]!" );
              return;
          }
      }
+ 
      # update db
      my $SQL = "UPDATE $Self->{CustomerCompanyTable} SET ";
!     for my $Entry ( @{ $Self->{CustomerCompanyMap} } ) {
!         if ( $Entry->[5] =~ /^int$/i ) {
!             $SQL .= " $Entry->[2] = " . $Self->{DBObject}->Quote( $Param{ $Entry->[0] } ) . ", ";
          }
!         elsif ( $Entry->[0] !~ /^UserPassword$/i ) {
!             $SQL .= " $Entry->[2] = '" . $Self->{DBObject}->Quote( $Param{ $Entry->[0] } ) . "', ";
          }
      }
      $SQL .= " change_time = current_timestamp, ";
      $SQL .= " change_by = $Param{UserID} ";
!     $SQL .= " WHERE LOWER($Self->{CustomerCompanyKey}) = LOWER('"
!         . $Self->{DBObject}->Quote( $Param{CustomerID} ) . "')";
! 
!     if ( $Self->{DBObject}->Do( SQL => $SQL ) ) {
  
          # log notice
          $Self->{LogObject}->Log(
              Priority => 'notice',
!             Message =>
!                 "CustomerCompany: '$Param{CustomerCompanyName}/$Param{CustomerID}' updated successfully ($Param{UserID})!",
          );
          return 1;
***************
*** 273,288 ****
      );
  
  =cut
  
  sub CustomerCompanyList {
!     my $Self = shift;
!     my %Param = @_;
      my $Valid = 1;
      # check needed stuff
!     if (!$Param{Valid} && defined($Param{Valid})) {
          $Valid = 0;
      }
      my $What = '';
!     foreach (@{$Self->{ConfigObject}->Get('CustomerCompany')->{CustomerCompanyListFields}}) {
          if ($What) {
              $What .= ', ';
--- 298,320 ----
      );
  
+     my %List = $ProjectObject->ProjectList(
+         Search => '*sometext*',
+         Limit => 10,
+     );
+ 
  =cut
  
  sub CustomerCompanyList {
!     my ( $Self, %Param ) = @_;
! 
      my $Valid = 1;
+ 
      # check needed stuff
!     if ( !$Param{Valid} && defined( $Param{Valid} ) ) {
          $Valid = 0;
      }
+ 
      my $What = '';
!     for ( @{ $Self->{ConfigObject}->Get('CustomerCompany')->{CustomerCompanyListFields} } ) {
          if ($What) {
              $What .= ', ';
***************
*** 290,310 ****
          $What .= "$_";
      }
      # sql
      return $Self->{DBObject}->GetTableData(
!         What => "$Self->{CustomerCompanyKey}, $What",
          Valid => $Valid,
          Clamp => 1,
          Table => $Self->{CustomerCompanyTable},
      );
  }
  
  sub DESTROY {
!     my $Self = shift;
      # disconnect if it's not a parent DBObject
!     if ($Self->{NotParentDBObject}) {
!         if ($Self->{DBObject}) {
              $Self->{DBObject}->Disconnect();
          }
      }
  }
  
--- 322,375 ----
          $What .= "$_";
      }
+     # where
+     my $SQL = '';
+     if ($Param{Search}) {
+         my $Count = 0;
+         my @Parts = split(/\+/, $Param{Search}, 6);
+         foreach my $Part (@Parts) {
+             $Part = $Self->{SearchPrefix}.$Part.$Self->{SearchSuffix};
+             $Part =~ s/\*/%/g;
+             $Part =~ s/%%/%/g;
+             if ($Count) {
+                 $SQL .= " AND ";
+             }
+             $Count ++;
+             if ($Self->{ConfigObject}->Get('CustomerCompany')->{CustomerCompanySearchFields}) {
+                 my $SQLExt = '';
+                 foreach (@{$Self->{ConfigObject}->Get('CustomerCompany')->{CustomerCompanySearchFields}}) {
+                     if ($SQLExt) {
+                         $SQLExt .= ' OR ';
+                     }
+                     $SQLExt .= " LOWER($_) LIKE LOWER('".$Self->{DBObject}->Quote($Part)."') ";
+                 }
+                 if ($SQLExt) {
+                     $SQL .= "($SQLExt)";
+                 }
+             }
+             else {
+                 $SQL .= " LOWER($Self->{CustomerKey}) LIKE LOWER('".$Self->{DBObject}->Quote($Part)."') ";
+             }
+         }
+     }
      # sql
      return $Self->{DBObject}->GetTableData(
!         What  => "$Self->{CustomerCompanyKey}, $What",
          Valid => $Valid,
          Clamp => 1,
          Table => $Self->{CustomerCompanyTable},
+         Where => $SQL,
      );
  }
  
  sub DESTROY {
!     my ($Self) = @_;
! 
      # disconnect if it's not a parent DBObject
!     if ( $Self->{NotParentDBObject} ) {
!         if ( $Self->{DBObject} ) {
              $Self->{DBObject}->Disconnect();
          }
      }
+     return 1;
  }
  
***************
*** 319,323 ****
  This software comes with ABSOLUTELY NO WARRANTY. For details, see
  the enclosed file COPYING for license information (GPL). If you
! did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
  
  =cut
--- 384,388 ----
  This software comes with ABSOLUTELY NO WARRANTY. For details, see
  the enclosed file COPYING for license information (GPL). If you
! did not receive this file, see http://www.gnu.org/licenses/gpl-2.0.txt.
  
  =cut


More information about the cvs-log mailing list