[otrs-cvs] CVS: otrs/Kernel/System CSV.pm, 1.8, 1.9 Stats.pm, 1.14,
1.15
cvs-log at otrs.org
cvs-log at otrs.org
Thu Jan 11 11:54:10 CET 2007
Update of /home/cvs/otrs/Kernel/System
In directory lancelot:/tmp/cvs-serv18878/Kernel/System
Modified Files:
CSV.pm Stats.pm
Log Message:
improved the cvs functionallity
Index: CSV.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/CSV.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** CSV.pm 14 Dec 2006 12:07:58 -0000 1.8
--- CSV.pm 11 Jan 2007 10:54:08 -0000 1.9
***************
*** 1,5 ****
# --
# Kernel/System/CSV.pm - all csv functions
! # Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/
# --
# $Id$
--- 1,5 ----
# --
# Kernel/System/CSV.pm - all csv functions
! # Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/
# --
# $Id$
***************
*** 68,72 ****
$CSV = $CSVObject->Array2CSV(
! Head => ['RowA', 'RowB', ],
Data => [
[1,4],
--- 68,72 ----
$CSV = $CSVObject->Array2CSV(
! Head => ['RowA', 'RowB', ], # optional
Data => [
[1,4],
***************
*** 139,143 ****
my %Param = @_;
my @Array = ();
- my @Lines = split(/\n/, $Param{String});
# get separator
--- 139,142 ----
***************
*** 145,162 ****
$Param{Separator} = ';';
}
! foreach (@Lines) {
! my @Fields = split(/$Param{Separator}/, $_);
! push(@Array, \@Fields);
}
! # text quoting
! if (defined($Param{Quote}) && $Param{Quote} ne '') {
! foreach my $Field (@Array) {
! foreach my $Index (0..scalar@{$Field}) {
! if (defined($Field->[$Index]) && $Field->[$Index] =~ /^$Param{Quote}(.*)$Param{Quote}$/) {
! $Field->[$Index] = $1;
! }
! }
! }
}
--- 144,166 ----
$Param{Separator} = ';';
}
!
! # a better solution can be the use of
! # use Text::ParseWords;
! # for more information read "PerlKochbuch" page 32
!
! # get separator
! if (!defined($Param{Quote})) {
! $Param{Quote} = '"';
}
! # if you change the split options, remember that each value can include \n
! my @Lines = split(/$Param{Quote}$Param{Separator}\n/, $Param{String});
!
! foreach (@Lines) {
! my @Fields = split(/$Param{Quote}$Param{Separator}$Param{Quote}/, $_);
! $Fields[0] =~ s/^$Param{Quote}//mgs;
! #$Fields[$#Fields] =~ s/$Param{Quote}$//mgs;
!
! push(@Array, \@Fields);
}
Index: Stats.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/Stats.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** Stats.pm 7 Dec 2006 08:37:27 -0000 1.14
--- Stats.pm 11 Jan 2007 10:54:08 -0000 1.15
***************
*** 1,5 ****
# --
# Kernel/System/Stats.pm - all advice functions
! # Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/
# --
# $Id$
--- 1,5 ----
# --
# Kernel/System/Stats.pm - all advice functions
! # Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/
# --
# $Id$
***************
*** 69,73 ****
}
# check needed objects
! foreach (qw(ConfigObject LogObject UserID GroupObject UserObject TimeObject MainObject)) {
$Self->{$_} = $Param{$_} || die "Got no $_!";
}
--- 69,73 ----
}
# check needed objects
! foreach (qw(ConfigObject LogObject UserID GroupObject UserObject TimeObject MainObject CSVObject)) {
$Self->{$_} = $Param{$_} || die "Got no $_!";
}
***************
*** 1022,1035 ****
if ($Param{Cache}) {
my $Path = $Self->{ConfigObject}->Get('TempDir');
my $File = 'Stats' . $Param{StatID} . "-" . $TitleTimeStart . "-" . $TitleTimeStop . ".cache";
$File =~ s/ /-/g;
if (open (DATA, "< $Path/$File")) {
while (<DATA>) {
! my @Row = split(/;;/, $_);
! push (@StatArray, \@Row);
}
close (DATA);
}
if (@StatArray) {
return @StatArray;
--- 1022,1042 ----
if ($Param{Cache}) {
my $Path = $Self->{ConfigObject}->Get('TempDir');
+ my $CSVString = '';
my $File = 'Stats' . $Param{StatID} . "-" . $TitleTimeStart . "-" . $TitleTimeStop . ".cache";
$File =~ s/ /-/g;
+
if (open (DATA, "< $Path/$File")) {
while (<DATA>) {
! $CSVString .= $_;
}
close (DATA);
}
+ @StatArray = @{$Self->{CSVObject}->CSV2Array(
+ String => $CSVString,
+ Separator => ';',
+ Quote => '"',
+ )};
+
if (@StatArray) {
return @StatArray;
***************
*** 1090,1100 ****
my $File = 'Stats' . $Param{StatID} . "-" . $TitleTimeStart . "-" . $TitleTimeStop . ".cache";
$File =~ s/ /-/g;
if (open (DATA, "> $Path/$File")) {
! foreach my $Row (@StatArray) {
! foreach (@{$Row}) {
! print DATA "$_;;";
! }
! print DATA "\n";
! }
close (DATA);
}
--- 1097,1107 ----
my $File = 'Stats' . $Param{StatID} . "-" . $TitleTimeStart . "-" . $TitleTimeStop . ".cache";
$File =~ s/ /-/g;
+
+ my $CSVString = $Self->{CSVObject}->Array2CSV(
+ Data => \@StatArray,
+ );
+
if (open (DATA, "> $Path/$File")) {
! print DATA $CSVString;
close (DATA);
}
***************
*** 1727,1737 ****
$File .= ".cache";
# write cache file
if (open (DATA, "> $Path/$File")) {
! foreach my $Row (@Data) {
! foreach (@{$Row}) {
! print DATA "$_;;";
! }
! print DATA "\n";
! }
close (DATA);
}
--- 1734,1743 ----
$File .= ".cache";
# write cache file
+ my $CSVString = $Self->{CSVObject}->Array2CSV(
+ Data => \@Data,
+ );
+
if (open (DATA, "> $Path/$File")) {
! print DATA $CSVString;
close (DATA);
}
***************
*** 1769,1779 ****
}
$File .= ".cache";
if (open (DATA, "< $Path/$File")) {
while (<DATA>) {
! my @Row = split(/;;/, $_);
! push (@Data, \@Row);
}
close (DATA);
}
# otherwise you get error waring in the shell
#else {
--- 1775,1792 ----
}
$File .= ".cache";
+ my $CSVString = '';
if (open (DATA, "< $Path/$File")) {
while (<DATA>) {
! $CSVString .= $_;
}
close (DATA);
}
+
+ @Data = @{$Self->{CSVObject}->CSV2Array(
+ String => $CSVString,
+ Separator => ';',
+ Quote => '"',
+ )};
+
# otherwise you get error waring in the shell
#else {
More information about the cvs-log
mailing list