1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Importing migration data via HTTP (#3365)

* Accept migration over HTTP

* Comment wip tests
This commit is contained in:
Benjamin Beganović 2020-02-24 22:15:07 +01:00 committed by GitHub
parent af0cad05e9
commit 8121a0166d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 18 deletions

View File

@ -184,20 +184,13 @@ class MigrationController extends BaseController
* ),
* )
*/
public function startMigration(UploadMigrationFileRequest $request)
public function startMigration(Request $request, Company $company)
{
$file = $request->file('migration')->storeAs(
'migrations', $request->file('migration')->getClientOriginalName()
);
if(!auth()->user()->company)
return response()->json(['message' => 'Company doesn\'t exists.'], 402);
if($request->has('force'))
$this->purgeCompany(auth()->user()->company);
$this->purgeCompany($company);
if(app()->environment() !== 'testing') {
StartMigration::dispatchNow($file, auth()->user(), auth()->user()->company);
StartMigration::dispatchNow($request->file('migration'), auth()->user(), $company);
}
return response()->json([], 200);

View File

@ -29,7 +29,7 @@ class UploadMigrationFileRequest extends FormRequest
/** We'll skip mime validation while running tests. */
if(app()->environment() !== 'testing') {
$rules['migration'] = ['required', 'mimes:zip'];
$rules['migration'] = ['required', 'file', 'mimes:zip'];
}
return $rules;

View File

@ -2,15 +2,15 @@
namespace App\Jobs\Util;
use App\Exceptions\ProcessingMigrationArchiveFailed;
use App\Libraries\MultiDB;
use App\Models\Company;
use App\Models\User;
use App\Models\Company;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Exceptions\ProcessingMigrationArchiveFailed;
class StartMigration implements ShouldQueue
{
@ -50,7 +50,6 @@ class StartMigration implements ShouldQueue
*/
public function handle()
{
MultiDB::setDb($this->company->db);
$zip = new \ZipArchive();
@ -62,6 +61,14 @@ class StartMigration implements ShouldQueue
if ($archive) {
$zip->extractTo(storage_path("migrations/{$filename}"));
$zip->close();
$migration_file = storage_path("migrations/$filename/migration.json");
$handle = fopen($migration_file, "r");
$migration_file = fread($handle, filesize($migration_file));
fclose($handle);
$data = json_decode($migration_file,1);
Import::dispatchNow($data, $this->company, $this->user);
} else {
throw new ProcessingMigrationArchiveFailed();
}

View File

@ -99,7 +99,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::post('migration/purge/{company}', 'MigrationController@purgeCompany')->middleware('password_protected');
Route::post('migration/purge_save_settings/{company}', 'MigrationController@purgeCompanySaveSettings')->middleware('password_protected');
Route::post('migration/start', 'MigrationController@startMigration')->middleware('password_protected');
Route::post('migration/start/{company}', 'MigrationController@startMigration');
Route::resource('companies', 'CompanyController');// name = (companies. index / create / show / update / destroy / edit

View File

@ -116,5 +116,6 @@ class MigrationTest extends TestCase
// $response->assertStatus(200);
// $this->assertTrue(file_exists(base_path('storage/migrations/migration/migration.json')));
// }
}