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

« back to all changes in this revision

Viewing changes to Kernel/System/Ticket/ArticleStorageFS.pm

  • 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
# --
2
2
# Kernel/System/Ticket/ArticleStorageFS.pm - article storage module for OTRS kernel
3
 
# Copyright (C) 2001-2005 Martin Edenhofer <martin+code@otrs.org>
 
3
# Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/
4
4
# --
5
 
# $Id: ArticleStorageFS.pm,v 1.28 2005/11/08 06:59:06 martin Exp $
 
5
# $Id: ArticleStorageFS.pm,v 1.34.2.1 2007/04/05 14:31:09 martin Exp $
6
6
# --
7
7
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
8
8
# the enclosed file COPYING for license information (GPL). If you
17
17
use MIME::Words qw(:all);
18
18
use MIME::Base64;
19
19
 
20
 
# --
21
20
# to get it writable for the otrs group (just in case)
22
 
# --
23
21
umask 002;
24
22
 
25
23
use vars qw($VERSION);
26
 
$VERSION = '$Revision: 1.28 $';
 
24
$VERSION = '$Revision: 1.34.2.1 $';
27
25
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
28
26
 
29
 
# --
30
27
sub ArticleStorageInit {
31
28
    my $Self = shift;
32
29
    my %Param = @_;
64
61
    }
65
62
    return 1;
66
63
}
67
 
# --
 
64
 
68
65
sub ArticleDelete {
69
66
    my $Self = shift;
70
67
    my %Param = @_;
78
75
    # delete attachments and plain emails
79
76
    my @Articles = $Self->ArticleIndex(TicketID => $Param{TicketID});
80
77
    foreach (@Articles) {
 
78
        # delete time accounting
 
79
        $Self->ArticleAccountedTimeDelete(
 
80
            ArticleID => $_,
 
81
            UserID => $Param{UserID},
 
82
        );
81
83
        # delete attachments
82
84
        $Self->ArticleDeleteAttachment(
83
85
            ArticleID => $_,
111
113
        return;
112
114
    }
113
115
}
114
 
# --
 
116
 
115
117
sub _ArticleDeleteDirectory {
116
118
    my $Self = shift;
117
119
    my %Param = @_;
136
138
    }
137
139
    return 1;
138
140
}
139
 
# --
 
141
 
140
142
sub ArticleDeletePlain {
141
143
    my $Self = shift;
142
144
    my %Param = @_;
166
168
    }
167
169
    return 1;
168
170
}
169
 
# --
 
171
 
170
172
sub ArticleDeleteAttachment {
171
173
    my $Self = shift;
172
174
    my %Param = @_;
201
203
    }
202
204
    return 1;
203
205
}
204
 
# --
 
206
 
205
207
sub ArticleWritePlain {
206
208
    my $Self = shift;
207
209
    my %Param = @_;
238
240
        return;
239
241
    }
240
242
}
241
 
# --
 
243
 
242
244
sub ArticleWriteAttachment {
243
245
    my $Self = shift;
244
246
    my %Param = @_;
255
257
    my $ContentPath = $Self->ArticleGetContentPath(ArticleID => $Param{ArticleID});
256
258
    # define path
257
259
    $Param{Path} = $Self->{ArticleDataDir}.'/'.$ContentPath.'/'.$Param{ArticleID};
258
 
    # check used name (we want just uniq names)
259
 
    $Param{Filename} = decode_mimewords($Param{Filename});
260
260
    # strip spaces from filenames
261
261
    $Param{Filename} =~ s/ /_/g;
262
262
    # strip dots from filenames
303
303
        return;
304
304
    }
305
305
}
306
 
# --
 
306
 
307
307
sub ArticlePlain {
308
308
    my $Self = shift;
309
309
    my %Param = @_;
353
353
        return $Data;
354
354
    }
355
355
}
356
 
# --
 
356
 
357
357
sub ArticleAttachmentIndex {
358
358
    my $Self = shift;
359
359
    my %Param = @_;
373
373
    # try fs
374
374
    my @List = glob("$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}/*");
375
375
    foreach my $Filename (@List) {
376
 
        $Counter++;
377
376
        my $FileSize = -s $Filename;
 
377
        # convert the file name in utf-8 if utf-8 is used
 
378
        $Filename = $Self->{EncodeObject}->Decode(
 
379
            Text => $Filename,
 
380
            From => 'utf-8',
 
381
        );
378
382
        # human readable file size
379
383
        if ($FileSize) {
380
384
            # remove meta data in files
406
410
        $Filename =~ s!^.*/!!;
407
411
        if ($Filename ne 'plain.txt') {
408
412
            # add the info the the hash
 
413
            $Counter++;
409
414
            $Index{$Counter} = {
410
415
                Filename => $Filename,
411
416
                Filesize => $FileSize,
424
429
          " article_id = $Param{ArticleID} ORDER BY id";
425
430
        $Self->{DBObject}->Prepare(SQL => $SQL);
426
431
        while (my @Row = $Self->{DBObject}->FetchrowArray()) {
427
 
           $Counter++;
428
432
            # human readable file size
429
433
            if ($Row[2]) {
430
434
                if ($Row[2] > (1024*1024)) {
438
442
                }
439
443
            }
440
444
            # add the info the the hash
 
445
            $Counter++;
441
446
            $Index{$Counter} = {
442
447
                Filename => $Row[0],
443
448
                ContentType => $Row[1],
447
452
    }
448
453
    return %Index;
449
454
}
450
 
# --
 
455
 
451
456
sub ArticleAttachment {
452
457
    my $Self = shift;
453
458
    my %Param = @_;
467
472
    my $ContentPath = $Self->ArticleGetContentPath(ArticleID => $Param{ArticleID});
468
473
    my %Data = %{$Index{$Param{FileID}}};;
469
474
    my $Counter = 0;
470
 
    if (open (DATA, "< $Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}/$Data{Filename}")) {
471
 
        binmode(DATA);
472
 
        while (<DATA>) {
473
 
            $Data{ContentType} = $_ if ($Counter == 0);
474
 
            $Data{Content} .= $_ if ($Counter > 0);
475
 
            $Counter++;
 
475
    my @List = glob("$Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}/*");
 
476
    if (@List) {
 
477
        foreach my $Filename (@List) {
 
478
            if ($Filename !~ /\/plain.txt/) {
 
479
                # add the info the the hash
 
480
                $Counter++;
 
481
                if ($Counter == $Param{FileID}) {
 
482
                    if (open (DATA, $Filename)) {
 
483
                        my $Counter = 0;
 
484
                        binmode(DATA);
 
485
                        while (<DATA>) {
 
486
                            $Data{ContentType} = $_ if ($Counter == 0);
 
487
                            $Data{Content} .= $_ if ($Counter > 0);
 
488
                            $Counter++;
 
489
                        }
 
490
                        close (DATA);
 
491
                        if ($Data{ContentType} =~ /(utf\-8|utf8)/i) {
 
492
                            $Self->{EncodeObject}->Encode(\$Data{Content});
 
493
                        }
 
494
                        chomp ($Data{ContentType});
 
495
                        return %Data;
 
496
                    }
 
497
                    else {
 
498
                        $Self->{LogObject}->Log(
 
499
                          Priority => 'error',
 
500
                          Message => "$!: $Filename!",
 
501
                        );
 
502
                        return;
 
503
                    }
 
504
                }
 
505
            }
476
506
        }
477
 
        close (DATA);
478
 
        chomp ($Data{ContentType});
479
 
        return %Data;
480
507
    }
481
508
    else {
482
509
        # try database
503
530
        else {
504
531
            $Self->{LogObject}->Log(
505
532
              Priority => 'error',
506
 
              Message => "$!: $Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}/$Index{$Param{FileID}}!",
 
533
              Message => "$!: $Self->{ArticleDataDir}/$ContentPath/$Param{ArticleID}/$Data{Filename}!",
507
534
            );
508
535
            return;
509
536
        }
510
537
    }
511
538
}
512
 
# --
513
539
 
514
540
1;