diff --git a/app/Http/Controllers/ImportJsonController.php b/app/Http/Controllers/ImportJsonController.php new file mode 100644 index 000000000000..5a95fa23a813 --- /dev/null +++ b/app/Http/Controllers/ImportJsonController.php @@ -0,0 +1,64 @@ +user()->getCompany(), auth()->user()); + + return response()->json(['message' => 'Processing'], 200); + + } +} diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index 3794be9dd6c6..fd26f3a33ce6 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -220,9 +220,10 @@ class CompanyExport implements ShouldQueue $this->export_data['designs'] = $this->company->user_designs->makeHidden(['id'])->all(); - $this->export_data['documents'] = $this->company->documents->map(function ($document){ + $this->export_data['documents'] = $this->company->all_documents->map(function ($document){ - $document = $this->transformArrayOfKeys($document, ['user_id', 'assigned_user_id', 'company_id', 'project_id', 'vendor_id']); + $document = $this->transformArrayOfKeys($document, ['user_id', 'assigned_user_id', 'company_id', 'project_id', 'vendor_id','documentable_id']); + $document->hashed_id = $this->encodePrimaryKey($document->id); return $document->makeVisible(['id']); @@ -431,7 +432,7 @@ class CompanyExport implements ShouldQueue })->makeHidden(['id'])->all(); //write to tmp and email to owner(); - + $this->zipAndSend(); return true; diff --git a/app/Models/Company.php b/app/Models/Company.php index e197b6de4da4..50096c00abe4 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -131,6 +131,11 @@ class Company extends BaseModel return $this->morphMany(Document::class, 'documentable'); } + public function all_documents() + { + return $this->HasMany(Document::class); + } + public function getEntityType() { return self::class; diff --git a/database/migrations/2021_05_30_100933_make_documents_assigned_user_nullable.php b/database/migrations/2021_05_30_100933_make_documents_assigned_user_nullable.php new file mode 100644 index 000000000000..6b4f3b3ea5f8 --- /dev/null +++ b/database/migrations/2021_05_30_100933_make_documents_assigned_user_nullable.php @@ -0,0 +1,41 @@ +unsignedInteger('assigned_user_id')->nullable()->change(); + }); + + Document::where('assigned_user_id', 0)->update(['assigned_user_id' => null]); + + if(config('ninja.db.multi_db_enabled')){ + Document::on('db-ninja-01')->where('assigned_user_id', 0)->update(['assigned_user_id' => null]); + Document::on('db-ninja-02')->where('assigned_user_id', 0)->update(['assigned_user_id' => null]); + } + else{ + Document::where('assigned_user_id', 0)->update(['assigned_user_id' => null]); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/routes/api.php b/routes/api.php index ea1477edd5a8..1ce7f9bc8ce3 100644 --- a/routes/api.php +++ b/routes/api.php @@ -84,6 +84,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('group_settings/bulk', 'GroupSettingController@bulk'); Route::post('import', 'ImportController@import')->name('import.import'); + Route::post('import_json', 'ImportJsonController@import')->name('import.import_json'); Route::post('preimport', 'ImportController@preimport')->name('import.preimport'); Route::resource('invoices', 'InvoiceController'); // name = (invoices. index / create / show / update / destroy / edit diff --git a/tests/Feature/Import/ImportCompanyTest.php b/tests/Feature/Import/ImportCompanyTest.php index f9addafd91ed..d4918b3a1150 100644 --- a/tests/Feature/Import/ImportCompanyTest.php +++ b/tests/Feature/Import/ImportCompanyTest.php @@ -855,7 +855,12 @@ class ImportCompanyTest extends TestCase // Designs // Documents + $this->assertEquals(2, count($this->backup_json_object->documents)); + $this->documentsImport(); + + $this->assertEquals(2, Document::count()); + // Documents } @@ -912,7 +917,7 @@ class ImportCompanyTest extends TestCase case Expense::class: return $this->transformId('expenses', $id); break; - case Invoice::class: + case 'invoices': return $this->transformId('invoices', $id); break; case Payment::class: diff --git a/tests/Feature/Import/backup.zip b/tests/Feature/Import/backup.zip index 33cbe23c9ab0..66f5bfdc7e50 100644 Binary files a/tests/Feature/Import/backup.zip and b/tests/Feature/Import/backup.zip differ