$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
} else {
# normal rename
+ my $res;
+
eval {
- my $res = $file->rename($::form->{to});
- $main::lxdebug->message(LXDebug->DEBUG2(), "rename result=".$res);
- if ($res > SL::File::RENAME_OK) {
- $self->js->flash('error',
- $res == SL::File::RENAME_EXISTS ? $::locale->text('File still exists !')
- : $res == SL::File::RENAME_SAME ? $::locale->text('Same Filename !')
- : $::locale->text('File not exists !'))->render;
- return 1;
- }
+ $res = $file->rename($::form->{to});
1;
} or do {
$self->js->flash( 'error', t8('internal error (see details)'))
->flash_detail('error', $@)->render;
return;
+ };
+
+ if ($res != SL::File::RENAME_OK) {
+ $self->js->flash('error',
+ $res == SL::File::RENAME_EXISTS ? $::locale->text('File still exists !')
+ : $res == SL::File::RENAME_SAME ? $::locale->text('Same Filename !')
+ : $::locale->text('File not exists !'))
+ ->render;
+ return;
}
}
$self->is_global($::form->{is_global});
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;
sub check_object_params {
my ($self) = @_;
- my $id = $::form->{object_id} +0;
- my $draftid = $::form->{draft_id} +0;
+ my $id = ($::form->{object_id} // 0) * 1;
+ my $draftid = ($::form->{draft_id} // 0) * 1;
my $gldoc = 0;
my $type = undef;
$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;
+ push @object_types, ('dunning','dunning1','dunning2','dunning3') if $self->object_type eq 'invoice';
@files = SL::File->get_all_versions(object_id => $self->object_id ,
- object_type => $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;
}
=head1 DESCRIPTION
-This is a controller for handling files in a storage independant way.
+This is a controller for handling files in a storage independent way.
The storage may be a Filesystem,a WebDAV, a Database or DMS.
These backends must be configered in ClientConfig.
This Controller use as intermediate layer for storage C<SL::File>.
=head2 C<action_list>
This loads a list of files on a webpage. This can be done with a normal submit or via an ajax/json call.
-Dependant of file_type different sources are available.
+Dependent of file_type different sources are available.
For documents there are the 'created' source and the imports from scanners or email.
For attachments and images only the 'uploaded' source available.
=head2 C<action_ajax_unimport>
-Some files can be unimported, dependant of the source of the file. This means they are moved
+Some files can be unimported, dependent of the source of the file. This means they are moved
back to the directory of the source
Available C<FORM PARAMS>:
Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
=cut
-