mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
9e9cd37b87
* Working on Quotes * Naming refactor for Quotes * Quote Actions * Quote Pdfs * Quote PDFs * Refunds in Stripe * Fixes tests * Company Ledger work
75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Util;
|
|
|
|
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
|
use App\Libraries\MultiDB;
|
|
use App\Models\Company;
|
|
use App\Models\User;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class StartMigration implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
private $filepath;
|
|
|
|
/**
|
|
* @var User
|
|
*/
|
|
|
|
private $user;
|
|
|
|
/**
|
|
* @var Company
|
|
*/
|
|
private $company;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @param $filepath
|
|
* @param User $user
|
|
* @param Company $company
|
|
*/
|
|
public function __construct($filepath, User $user, Company $company)
|
|
{
|
|
$this->filepath = $filepath;
|
|
$this->user = $user;
|
|
$this->company = $company;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
|
|
MultiDB::setDb($this->company->db);
|
|
|
|
$zip = new \ZipArchive();
|
|
$archive = $zip->open($this->filepath);
|
|
|
|
$filename = pathinfo($this->filepath, PATHINFO_FILENAME);
|
|
|
|
try {
|
|
if ($archive) {
|
|
$zip->extractTo(storage_path("migrations/{$filename}"));
|
|
$zip->close();
|
|
} else {
|
|
throw new ProcessingMigrationArchiveFailed();
|
|
}
|
|
} catch (ProcessingMigrationArchiveFailed $e) {
|
|
// TODO: Break the code, stop the migration.. send an e-mail.
|
|
}
|
|
|
|
// Rest of the migration..
|
|
}
|
|
}
|