mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor for company import
This commit is contained in:
parent
c095a49603
commit
b654639ad3
@ -15,6 +15,7 @@ use App\Exceptions\NonExistingMigrationFile;
|
||||
use App\Http\Requests\Import\ImportJsonRequest;
|
||||
use App\Jobs\Company\CompanyExport;
|
||||
use App\Jobs\Company\CompanyImport;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
@ -63,15 +64,12 @@ class ImportJsonController extends BaseController
|
||||
|
||||
$import_file = $request->file('files');
|
||||
|
||||
$contents = $this->unzipFile($import_file->getPathname());
|
||||
$file_location = $this->unzipFile($import_file->getPathname());
|
||||
|
||||
$hash = Str::random(32);
|
||||
|
||||
nlog($hash);
|
||||
|
||||
Cache::put( $hash, base64_encode( $contents ), 3600 );
|
||||
|
||||
CompanyImport::dispatch(auth()->user()->getCompany(), auth()->user(), $hash, $request->except('files'))->delay(now()->addMinutes(1))->onQueue('himem');;
|
||||
if(Ninja::isHosted())
|
||||
CompanyImport::dispatch(auth()->user()->getCompany(), auth()->user(), $file_location, $request->except('files'))->onQueue('himem');
|
||||
else
|
||||
CompanyImport::dispatch(auth()->user()->getCompany(), auth()->user(), $file_location, $request->except('files'));
|
||||
|
||||
return response()->json(['message' => 'Processing'], 200);
|
||||
|
||||
@ -90,11 +88,12 @@ class ImportJsonController extends BaseController
|
||||
if (! file_exists($file_location))
|
||||
throw new NonExistingMigrationFile('Backup file does not exist, or is corrupted.');
|
||||
|
||||
$data = file_get_contents($file_location);
|
||||
//$data = file_get_contents($file_location);
|
||||
|
||||
unlink($file_contents);
|
||||
unlink($file_location);
|
||||
return $file_location;
|
||||
//unlink($file_contents);
|
||||
//unlink($file_location);
|
||||
|
||||
return $data;
|
||||
//return $data;
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ class CompanyImport implements ShouldQueue
|
||||
|
||||
public $user;
|
||||
|
||||
private $hash;
|
||||
private $file_location;
|
||||
|
||||
public $backup_file;
|
||||
|
||||
@ -146,11 +146,11 @@ class CompanyImport implements ShouldQueue
|
||||
* @param string $hash - the cache hash of the import data.
|
||||
* @param array $request->all()
|
||||
*/
|
||||
public function __construct(Company $company, User $user, string $hash, array $request_array)
|
||||
public function __construct(Company $company, User $user, string $file_location, array $request_array)
|
||||
{
|
||||
$this->company = $company;
|
||||
$this->user = $user;
|
||||
$this->hash = $hash;
|
||||
$this->file_location = $file_location;
|
||||
$this->request_array = $request_array;
|
||||
$this->current_app_version = config('ninja.app_version');
|
||||
}
|
||||
@ -164,14 +164,14 @@ class CompanyImport implements ShouldQueue
|
||||
$this->company_owner = $this->company->owner();
|
||||
|
||||
nlog("Company ID = {$this->company->id}");
|
||||
nlog("Hash ID = {$this->hash}");
|
||||
nlog("file_location ID = {$this->file_location}");
|
||||
|
||||
$this->backup_file = Cache::get($this->hash);
|
||||
// $this->backup_file = Cache::get($this->hash);
|
||||
|
||||
if ( empty( $this->backup_file ) )
|
||||
if ( empty( $this->file_location ) )
|
||||
throw new \Exception('No import data found, has the cache expired?');
|
||||
|
||||
$this->backup_file = json_decode(base64_decode($this->backup_file));
|
||||
$this->backup_file = json_decode(file_get_contents($this->file_location));
|
||||
|
||||
// nlog($this->backup_file);
|
||||
$this->checkUserCount();
|
||||
@ -198,6 +198,8 @@ class CompanyImport implements ShouldQueue
|
||||
|
||||
}
|
||||
|
||||
unlink($this->file_location);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user