1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Jobs/Util/StartMigration.php
Benjamin Beganović 11cc40d23a Migrate commits from 2-migration-with-json into v2 (#3241)
* Scaffold test case

* Import.php tests:
- Basic test scaffold
- Test if exception is thrown when unknown resource
- Company update test

* Migration importer & exception classes

* Company migration test
- Added 3rd parameter for accepting custom resources
- Wip tax_rates migration

* Tax rate migration

* Tax rate update
- Added company_id & user_id property modifiers

* Users migration

* Save IDs for users importing

* Add 'transformIds' method

* Importing clients
- An exception for resource not migration
- Dependency logic
- Removing id on insert

* Exception for unresolved dependency

* Import clients

* Method for inspecting user_id

* Importing invoices

* Importing quotes

* Fix tests & wrap with try-catch

* Fix tax_rates user_id transform

* Working on migration

* Tests for migration

* fixes for test

* Tests for Import.php
- Added ext-json to composer.json

* Tests for Import.php
- Added ext-json to composer.json

* Change migration exceptions to MigrationValidatorFailed

* Fixes for tests and counters

* Unzipping the migration archive
- Changed .gitignore to ignore all local migrations

* Comparing local data with inserted

* Ignore verification - wip

* Fix formatting for api.php

* Uploading file test (wip)

* Fix typo

Co-authored-by: David Bomba <turbo124@gmail.com>
2020-01-24 07:35:00 +11:00

71 lines
1.6 KiB
PHP

<?php
namespace App\Jobs\Util;
use App\Exceptions\ProcessingMigrationArchiveFailed;
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()
{
$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..
}
}