Revision a051b91b
Von Martin Helmling martin.helmling@octosoft.eu vor mehr als 7 Jahren hinzugefügt
SL/Controller/File.pm | ||
---|---|---|
$self->js->flash('error',$::locale->text('File not exists !'))->render();
|
||
return;
|
||
}
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "object_id=".$file->object_id." object_type=".$file->object_type." dbfile=".$file);
|
||
my $sessionfile = $::form->{sessionfile};
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "sessionfile=".$sessionfile);
|
||
if ( $sessionfile && -f $sessionfile ) {
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "file=".$file->file_name." to=".$::form->{to}." sessionfile=".$sessionfile);
|
||
# new uploaded file
|
||
if ( $::form->{to} eq $file->file_name ) {
|
||
# no rename so use as new version
|
||
... | ... | |
|
||
eval {
|
||
$res = $file->rename($::form->{to});
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "rename result=".$res);
|
||
1;
|
||
} or do {
|
||
$self->js->flash( 'error', t8('internal error (see details)'))
|
||
... | ... | |
my ($self) = @_;
|
||
|
||
my $source = 'uploaded';
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "file_upload UPLOAD=".$::form->{ATTACHMENTS}->{uploadfiles});
|
||
my @existing;
|
||
if ( $::form->{ATTACHMENTS}->{uploadfiles} ) {
|
||
my @upfiles = @{ $::form->{ATTACHMENTS}->{uploadfiles} };
|
||
foreach my $idx (0 .. scalar(@upfiles) - 1) {
|
||
eval {
|
||
my $fname = uri_unescape($upfiles[$idx]->{filename});
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "file_upload name=".$fname);
|
||
## normalize and find basename
|
||
# first split with unix rules
|
||
# after that split with windows rules
|
||
... | ... | |
$mime_type = File::MimeInfo::Magic::mimetype($basefile);
|
||
$mime_type = 'application/octet-stream' if $mime_type eq 'application/pdf' || !$mime_type;
|
||
}
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "mime_type=".$mime_type);
|
||
if ( $self->file_type eq 'image' && $self->file_probe_image_type($mime_type, $basefile)) {
|
||
next;
|
||
}
|
||
... | ... | |
file_name => $basefile,
|
||
);
|
||
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "store1 exist=".$existobj);
|
||
if ($existobj) {
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "id=".$existobj->id." sessionfile=". $sfile->file_name);
|
||
push @existing, $existobj->id.'_'.$sfile->file_name;
|
||
} else {
|
||
my $fileobj = SL::File->save(object_id => $self->object_id,
|
||
... | ... | |
#file_contents => ${$upfiles[$idx]->{data}},
|
||
file_path => $sfile->file_name
|
||
);
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "obj=".$fileobj);
|
||
unlink($sfile->file_name);
|
||
}
|
||
1;
|
||
... | ... | |
$self->object_id($id);
|
||
$self->object_model($file_types{$type}->{model});
|
||
$self->object_right($file_types{$type}->{right});
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "checked: object_id=".$self->object_id." object_type=".$self->object_type." is_global=".$self->is_global);
|
||
|
||
# $::auth->assert($self->object_right);
|
||
|
||
... | ... | |
sub _do_list {
|
||
my ($self,$json) = @_;
|
||
my @files;
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "do_list: object_id=".$self->object_id." object_type=".$self->object_type." file_type=".$self->file_type." json=".$json);
|
||
if ( $self->file_type eq 'document' ) {
|
||
my @object_types;
|
||
push @object_types, $self->object_type;
|
||
... | ... | |
object_type => \@object_types,
|
||
file_type => $self->file_type );
|
||
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "cnt1=".scalar(@files));
|
||
}
|
||
elsif ( $self->file_type eq 'attachment' || $self->file_type eq 'image' ) {
|
||
@files = SL::File->get_all(object_id => $self->object_id ,
|
||
object_type => $self->object_type,
|
||
file_type => $self->file_type );
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "cnt2=".scalar(@files));
|
||
}
|
||
$self->files(\@files);
|
||
$self->_mk_render('file/list',1,0,$json);
|
||
... | ... | |
my ($self,$path) = @_;
|
||
my @foundfiles ;
|
||
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "import path=".$path);
|
||
my $language = $::lx_office_conf{system}->{language};
|
||
my $timezone = $::locale->get_local_time_zone()->name;
|
||
if (opendir my $dir, $path) {
|
||
... | ... | |
foreach my $file ( @files) {
|
||
next if (($file eq '.') || ($file eq '..'));
|
||
$file = Encode::decode('utf-8', $file);
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "file=".$file);
|
||
|
||
next if( -d "$path/$file");
|
||
|
||
my $tmppath = File::Spec->catfile( $path, $file );
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "tmppath=".$tmppath." file=".$file);
|
||
next if( ! -f $tmppath);
|
||
|
||
my $st = stat($tmppath);
|
||
... | ... | |
|
||
}
|
||
}
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "return ".scalar(@foundfiles)." files");
|
||
return @foundfiles;
|
||
}
|
||
|
||
... | ... | |
##TODO here a configurable code must be implemented
|
||
|
||
my $title;
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "mk_render: object_id=".$self->object_id." object_type=".$self->object_type.
|
||
" file_type=".$self->file_type." json=".$json." filecount=".scalar(@{ $self->files })." is_global=".$self->is_global);
|
||
my @sources = $self->_get_sources();
|
||
foreach my $source ( @sources ) {
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "mk_render: source name=".$source->{name});
|
||
@{$source->{files}} = grep { $_->source eq $source->{name}} @{ $self->files };
|
||
}
|
||
if ( $self->file_type eq 'document' ) {
|
||
... | ... | |
if ( $self->existing && scalar(@{$self->existing}) > 0) {
|
||
my $first = shift @{$self->existing};
|
||
my ($first_id,$sfile) = split('_',$first,2);
|
||
#$main::lxdebug->message(LXDebug->DEBUG2(), "id=".$first_id." sessionfile=". $sfile);
|
||
my $file = SL::File->get(id => $first_id );
|
||
$self->js->run('kivi.File.askForRename',$first_id,$file->file_name,$sfile,join (',', @{$self->existing}), $self->is_global);
|
||
}
|
||
... | ... | |
sub _get_sources {
|
||
my ($self) = @_;
|
||
my @sources;
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "get_sources file_type=". $self->file_type);
|
||
if ( $self->file_type eq 'document' ) {
|
||
##TODO statt gen neue attribute in filetypes :
|
||
if (($file_types{$self->object_type}->{gen}*1 & 1)==1) {
|
||
... | ... | |
}
|
||
if (($file_types{$self->object_type}->{gen}*1 & 2)==2) {
|
||
my @others = SL::File->get_other_sources();
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "other cnt=". scalar(@others));
|
||
foreach my $scanner_or_mailrx (@others) {
|
||
my $other = {
|
||
'name' => $scanner_or_mailrx->{name},
|
||
... | ... | |
};
|
||
push @sources , $attdata;
|
||
}
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "get_sources count=".scalar(@sources));
|
||
return @sources;
|
||
}
|
||
|
SL/File/Backend/Filesystem.pm | ||
---|---|---|
|
||
sub delete {
|
||
my ($self, %params) = @_;
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "del in backend " . $self . " file " . $params{dbfile});
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "file id=" . ($params{dbfile}->id * 1));
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "last=" . $params{last}." all_bnl=". $params{all_but_notlast});
|
||
die "no dbfile in backend delete" unless $params{dbfile};
|
||
my $backend_data = $params{dbfile}->backend_data;
|
||
$backend_data = 0 if $params{last};
|
||
$backend_data = $params{dbfile}->backend_data-1 if $params{all_but_notlast};
|
||
|
||
if ($backend_data > 0 ) {
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "backend_data=" .$backend_data);
|
||
for my $version ( 1..$backend_data) {
|
||
my $file_path = $self->_filesystem_path($params{dbfile},$version);
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "unlink " .$file_path);
|
||
unlink($file_path);
|
||
}
|
||
if ($params{all_but_notlast}) {
|
||
... | ... | |
$params{dbfile}->backend_data(0);
|
||
my $dir_path = $self->_filesystem_path($params{dbfile});
|
||
rmdir($dir_path);
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "rmdir " .$dir_path);
|
||
}
|
||
} else {
|
||
my $file_path = $self->_filesystem_path($params{dbfile},$params{dbfile}->backend_data);
|
||
... | ... | |
sub get_mtime {
|
||
my ($self, %params) = @_;
|
||
die "no dbfile" unless $params{dbfile};
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "version=" .$params{version});
|
||
die "unknown version" if $params{version} &&
|
||
($params{version} < 0 || $params{version} > $params{dbfile}->backend_data) ;
|
||
my $path = $self->_filesystem_path($params{dbfile},$params{version});
|
||
die "no file found in backend get_mtime" if !-f $path;
|
||
my @st = stat($path);
|
||
my $dt = DateTime->from_epoch(epoch => $st[9])->clone();
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "dt=" .$dt);
|
||
return $dt;
|
||
}
|
||
|
||
... | ... | |
$version = $dbfile->backend_data if !$version || $version < 1 || $version > $dbfile->backend_data;
|
||
my $iddir = sprintf("%04d", $dbfile->id % 1000);
|
||
my $path = File::Spec->catdir($::lx_office_conf{paths}->{document_path}, $::auth->client->{id}, $iddir, $dbfile->id);
|
||
$main::lxdebug->message(LXDebug->DEBUG2(), "file path=" .$path." id=" .$dbfile->id." version=".$version." basename=".$dbfile->id . '_' . $version);
|
||
if (!-d $path) {
|
||
File::Path::make_path($path, { chmod => 0770 });
|
||
}
|
Auch abrufbar als: Unified diff
Filemanagement: DEBUG2 herausgenommen