mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Reorder DB transaction initialization
This commit is contained in:
parent
0e1f17c6ea
commit
acbb692150
@ -177,48 +177,44 @@ class PreviewController extends BaseController
|
|||||||
|
|
||||||
if($request->input('entity') == 'invoice'){
|
if($request->input('entity') == 'invoice'){
|
||||||
$repo = new InvoiceRepository();
|
$repo = new InvoiceRepository();
|
||||||
$factory = InvoiceFactory::create($company->id, auth()->user()->id);
|
$entity_obj = InvoiceFactory::create($company->id, auth()->user()->id);
|
||||||
$class = Invoice::class;
|
$class = Invoice::class;
|
||||||
}
|
}
|
||||||
elseif($request->input('entity') == 'quote'){
|
elseif($request->input('entity') == 'quote'){
|
||||||
$repo = new QuoteRepository();
|
$repo = new QuoteRepository();
|
||||||
$factory = QuoteFactory::create($company->id, auth()->user()->id);
|
$entity_obj = QuoteFactory::create($company->id, auth()->user()->id);
|
||||||
$class = Quote::class;
|
$class = Quote::class;
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif($request->input('entity') == 'credit'){
|
elseif($request->input('entity') == 'credit'){
|
||||||
$repo = new CreditRepository();
|
$repo = new CreditRepository();
|
||||||
$factory = CreditFactory::create($company->id, auth()->user()->id);
|
$entity_obj = CreditFactory::create($company->id, auth()->user()->id);
|
||||||
$class = Credit::class;
|
$class = Credit::class;
|
||||||
}
|
}
|
||||||
elseif($request->input('entity') == 'recurring_invoice'){
|
elseif($request->input('entity') == 'recurring_invoice'){
|
||||||
$repo = new RecurringInvoiceRepository();
|
$repo = new RecurringInvoiceRepository();
|
||||||
$factory = RecurringInvoiceFactory::create($company->id, auth()->user()->id);
|
$entity_obj = RecurringInvoiceFactory::create($company->id, auth()->user()->id);
|
||||||
$class = RecurringInvoice::class;
|
$class = RecurringInvoice::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DB::connection(config('database.default'))->beginTransaction();
|
|
||||||
|
|
||||||
if($request->has('entity_id')){
|
if($request->has('entity_id')){
|
||||||
|
|
||||||
$entity_obj = $class::where('id', $this->decodePrimaryKey($request->input('entity_id')))
|
$entity_obj = $class::on(config('database.default'))
|
||||||
|
->where('id', $this->decodePrimaryKey($request->input('entity_id')))
|
||||||
->where('company_id', $company->id)
|
->where('company_id', $company->id)
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if($entity_obj)
|
}
|
||||||
info("found a valid entity object");
|
|
||||||
|
DB::connection(config('database.default'))->beginTransaction();
|
||||||
|
|
||||||
$entity_obj = $repo->save($request->all(), $entity_obj);
|
$entity_obj = $repo->save($request->all(), $entity_obj);
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$entity_obj = $repo->save($request->all(), $factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
$entity_obj->load('client');
|
$entity_obj->load('client');
|
||||||
|
|
||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
@ -301,8 +297,6 @@ class PreviewController extends BaseController
|
|||||||
->batch();
|
->batch();
|
||||||
}
|
}
|
||||||
|
|
||||||
DB::connection()->getDoctrineConnection()->close();
|
|
||||||
DB::disconnect();
|
|
||||||
|
|
||||||
$response = Response::make($file_path, 200);
|
$response = Response::make($file_path, 200);
|
||||||
$response->header('Content-Type', 'application/pdf');
|
$response->header('Content-Type', 'application/pdf');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user