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:
parent
af0cad05e9
commit
8121a0166d
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -116,5 +116,6 @@ class MigrationTest extends TestCase
|
||||
// $response->assertStatus(200);
|
||||
// $this->assertTrue(file_exists(base_path('storage/migrations/migration/migration.json')));
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user