Fix various bits for import
This commit is contained in:
parent
a45c354834
commit
71189d18fc
8 changed files with 111 additions and 69 deletions
|
@ -2,10 +2,15 @@ package Pear::LocalLoop::Controller::Admin::ImportFrom;
|
|||
use Mojo::Base 'Mojolicious::Controller';
|
||||
use Moo;
|
||||
use Try::Tiny;
|
||||
use Mojo::File qw/ path /;
|
||||
use Mojo::File qw/path/;
|
||||
|
||||
sub index {
|
||||
my $c = shift;
|
||||
$c->stash->{org_entities} = [
|
||||
map {
|
||||
{ id => $_->entity_id, name => $_->name }
|
||||
} $c->schema->resultset('Organisation')->all
|
||||
];
|
||||
|
||||
$c->app->max_request_size(104857600);
|
||||
}
|
||||
|
@ -14,56 +19,61 @@ sub post_suppliers {
|
|||
my $c = shift;
|
||||
|
||||
unless ($c->param('suppliers_csv')) {
|
||||
$c->flash( error => "No CSV file given" );
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
$c->flash(error => "No CSV file given");
|
||||
return $c->redirect_to('/admin/import_from');
|
||||
}
|
||||
|
||||
# Check file size
|
||||
if ($c->req->is_limit_exceeded) {
|
||||
$c->flash( error => "CSV file size is too large" );
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
$c->flash(error => "CSV file size is too large");
|
||||
return $c->redirect_to('/admin/import_from');
|
||||
}
|
||||
|
||||
my $file = $c->param('suppliers_csv');
|
||||
|
||||
my $filename = path($c->app->config->{upload_path}, time.'suppliers.csv' );
|
||||
my $filename = path($c->app->config->{upload_path}, time . 'suppliers.csv');
|
||||
|
||||
$file->move_to($filename);
|
||||
|
||||
my $job_id = $c->minion->enqueue('csv_supplier_import' => [$filename] );
|
||||
my $job_id = $c->minion->enqueue('csv_supplier_import' => [ $filename ]);
|
||||
|
||||
my $job_url = $c->url_for("/admin/minion/jobs?id=$job_id")->to_abs;
|
||||
|
||||
$c->flash(success => "CSV import started, see status of minion job at: $job_url");
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
return $c->redirect_to('/admin/import_from');
|
||||
}
|
||||
|
||||
sub post_transactions {
|
||||
my $c = shift;
|
||||
|
||||
unless ($c->param('entity_id') ne '') {
|
||||
$c->flash(error => "Please Choose an organisation");
|
||||
return $c->redirect_to('/admin/import_from');
|
||||
}
|
||||
|
||||
unless ($c->param('transactions_csv')) {
|
||||
$c->flash( error => "No CSV file given" );
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
$c->flash(error => "No CSV file given");
|
||||
return $c->redirect_to('/admin/import_from');
|
||||
}
|
||||
|
||||
# Check file size
|
||||
if ($c->req->is_limit_exceeded) {
|
||||
$c->flash( error => "CSV file size is too large" );
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
$c->flash(error => "CSV file size is too large");
|
||||
return $c->redirect_to('/admin/import_from');
|
||||
}
|
||||
|
||||
my $file = $c->param('transactions_csv');
|
||||
|
||||
my $filename = path($c->app->config->{upload_path}, time.'transactions.csv' );
|
||||
my $filename = path($c->app->config->{upload_path}, time . 'transactions.csv');
|
||||
|
||||
$file->move_to($filename);
|
||||
|
||||
my $job_id = $c->minion->enqueue('csv_transaction_import' => [$filename] );
|
||||
my $job_id = $c->minion->enqueue('csv_transaction_import' => [ $filename, $c->param('entity_id') ]);
|
||||
|
||||
my $job_url = $c->url_for("/admin/minion/jobs?id=$job_id")->to_abs;
|
||||
|
||||
$c->flash(success => "CSV import started, see status of minion job at: $job_url");
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
return $c->redirect_to('/admin/import_from');
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Reference in a new issue