~ubuntu-branches/ubuntu/natty/otrs2/natty-updates

« back to all changes in this revision

Viewing changes to bin/xml2sql.pl

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2007-04-14 17:58:55 UTC
  • mto: (20.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: package-import@ubuntu.com-20070414175855-9ne0w01yu1q44ch0
Tags: upstream-2.1.7
ImportĀ upstreamĀ versionĀ 2.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/perl -w
2
2
# --
3
3
# xml2sql.pl - a xml 2 sql processor
4
 
# Copyright (C) 2001-2005 Martin Edenhofer <martin+code@otrs.org>
 
4
# Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/
5
5
# --
6
 
# $Id: xml2sql.pl,v 1.4 2005/10/30 12:34:53 martin Exp $
 
6
# $Id: xml2sql.pl,v 1.9 2006/11/26 21:16:08 martin Exp $
7
7
# --
8
8
# This program is free software; you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
34
34
use Kernel::System::Time;
35
35
use Kernel::System::DB;
36
36
use Kernel::System::Log;
 
37
use Kernel::System::Main;
37
38
use Kernel::System::XML;
38
39
 
39
 
my $VERSION = '$Revision: 1.4 $';
 
40
my $VERSION = '$Revision: 1.9 $';
40
41
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
41
42
 
42
43
my %Opts = ();
43
44
getopt('hton', \%Opts);
44
45
if ($Opts{'h'}) {
45
46
    print "xml2sql.pl <Revision $VERSION> - xml2sql\n";
46
 
    print "Copyright (c) 2001-2004 Martin Edenhofer <martin\@otrs.org>\n";
 
47
    print "Copyright (c) 2001-2006 OTRS GmbH, http://otrs.org/\n";
47
48
    print "usage: xml2sql.pl -t <DATABASE_TYPE> [-o <OUTPUTDIR> -n <NAME>]\n";
48
49
    exit 1;
49
50
}
61
62
    die "ERROR: Need -t <DATABASE_TYPE>";
62
63
}
63
64
 
64
 
# --
65
65
# create common objects
66
 
# --
 
66
 
67
67
my %CommonObject = ();
68
68
$CommonObject{ConfigObject} = Kernel::Config->new();
69
69
$CommonObject{ConfigObject}->Set(Key => 'Database::Type', Value => $Opts{t});
70
70
$CommonObject{ConfigObject}->Set(Key => 'Database::ShellOutput', Value => 1);
71
 
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
72
71
$CommonObject{LogObject} = Kernel::System::Log->new(
73
72
    LogPrefix => 'OTRS-xml2sql',
74
73
    %CommonObject,
75
74
);
 
75
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
 
76
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
76
77
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
77
78
$CommonObject{XMLObject} = Kernel::System::XML->new(%CommonObject);
78
79
 
87
88
my @XMLARRAY = $CommonObject{XMLObject}->XMLParse(String => $FileString);
88
89
 
89
90
# remember header
90
 
my $Head = $CommonObject{DBObject}->{"DB::Comment"}."----------------------------------------------------------\n";
91
 
$Head .= $CommonObject{DBObject}->{"DB::Comment"}." database: $Opts{t}, generated: ".scalar(localtime())."\n";
92
 
$Head .= $CommonObject{DBObject}->{"DB::Comment"}."----------------------------------------------------------\n";
 
91
my $Head = $CommonObject{DBObject}->{Backend}->{"DB::Comment"}."----------------------------------------------------------\n";
 
92
$Head .= $CommonObject{DBObject}->{Backend}->{"DB::Comment"}." database: $Opts{t}, generated: ".scalar(localtime())."\n";
 
93
$Head .= $CommonObject{DBObject}->{Backend}->{"DB::Comment"}."----------------------------------------------------------\n";
93
94
 
94
95
# get database sql from parsed xml
95
96
my @SQL = $CommonObject{DBObject}->SQLProcessor(Database => \@XMLARRAY);
103
104
}
104
105
print OUT $Head;
105
106
foreach (@SQL) {
106
 
    print OUT "$_".$CommonObject{DBObject}->{"DB::ShellCommit"}."\n";
 
107
    print OUT "$_".$CommonObject{DBObject}->{Backend}->{"DB::ShellCommit"}."\n";
107
108
}
108
109
if ($Opts{o}) {
109
110
    close (OUT);
126
127
if ($Opts{o}) {
127
128
    close (OUT);
128
129
}
129