mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for import company tests
This commit is contained in:
parent
9b5a6f3468
commit
b72217d74c
64
app/Http/Controllers/ImportJsonController.php
Normal file
64
app/Http/Controllers/ImportJsonController.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\Export\StoreExportRequest;
|
||||||
|
use App\Jobs\Company\CompanyExport;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class ImportJsonController extends BaseController
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @OA\Post(
|
||||||
|
* path="/api/v1/import_json",
|
||||||
|
* operationId="getImportJson",
|
||||||
|
* tags={"import"},
|
||||||
|
* summary="Import data from the system",
|
||||||
|
* description="Import data from the system",
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="success",
|
||||||
|
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=422,
|
||||||
|
* description="Validation error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="default",
|
||||||
|
* description="Unexpected Error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function index(StoreExportRequest $request)
|
||||||
|
{
|
||||||
|
|
||||||
|
// CompanyExport::dispatch(auth()->user()->getCompany(), auth()->user());
|
||||||
|
|
||||||
|
return response()->json(['message' => 'Processing'], 200);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -220,9 +220,10 @@ class CompanyExport implements ShouldQueue
|
|||||||
|
|
||||||
$this->export_data['designs'] = $this->company->user_designs->makeHidden(['id'])->all();
|
$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']);
|
return $document->makeVisible(['id']);
|
||||||
|
|
||||||
@ -431,7 +432,7 @@ class CompanyExport implements ShouldQueue
|
|||||||
})->makeHidden(['id'])->all();
|
})->makeHidden(['id'])->all();
|
||||||
|
|
||||||
//write to tmp and email to owner();
|
//write to tmp and email to owner();
|
||||||
|
|
||||||
$this->zipAndSend();
|
$this->zipAndSend();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -131,6 +131,11 @@ class Company extends BaseModel
|
|||||||
return $this->morphMany(Document::class, 'documentable');
|
return $this->morphMany(Document::class, 'documentable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function all_documents()
|
||||||
|
{
|
||||||
|
return $this->HasMany(Document::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function getEntityType()
|
public function getEntityType()
|
||||||
{
|
{
|
||||||
return self::class;
|
return self::class;
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Document;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class MakeDocumentsAssignedUserNullable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('documents', function (Blueprint $table){
|
||||||
|
$table->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()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
@ -84,6 +84,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
|||||||
Route::post('group_settings/bulk', 'GroupSettingController@bulk');
|
Route::post('group_settings/bulk', 'GroupSettingController@bulk');
|
||||||
|
|
||||||
Route::post('import', 'ImportController@import')->name('import.import');
|
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::post('preimport', 'ImportController@preimport')->name('import.preimport');
|
||||||
|
|
||||||
Route::resource('invoices', 'InvoiceController'); // name = (invoices. index / create / show / update / destroy / edit
|
Route::resource('invoices', 'InvoiceController'); // name = (invoices. index / create / show / update / destroy / edit
|
||||||
|
@ -855,7 +855,12 @@ class ImportCompanyTest extends TestCase
|
|||||||
// Designs
|
// Designs
|
||||||
|
|
||||||
// Documents
|
// Documents
|
||||||
|
$this->assertEquals(2, count($this->backup_json_object->documents));
|
||||||
|
|
||||||
$this->documentsImport();
|
$this->documentsImport();
|
||||||
|
|
||||||
|
$this->assertEquals(2, Document::count());
|
||||||
|
|
||||||
// Documents
|
// Documents
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -912,7 +917,7 @@ class ImportCompanyTest extends TestCase
|
|||||||
case Expense::class:
|
case Expense::class:
|
||||||
return $this->transformId('expenses', $id);
|
return $this->transformId('expenses', $id);
|
||||||
break;
|
break;
|
||||||
case Invoice::class:
|
case 'invoices':
|
||||||
return $this->transformId('invoices', $id);
|
return $this->transformId('invoices', $id);
|
||||||
break;
|
break;
|
||||||
case Payment::class:
|
case Payment::class:
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user