2019-11-20 06:41:49 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-11-20 06:41:49 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\Account\CreateAccountRequest;
|
2020-01-23 21:35:00 +01:00
|
|
|
use App\Http\Requests\Migration\UploadMigrationFileRequest;
|
2019-11-20 06:41:49 +01:00
|
|
|
use App\Jobs\Account\CreateAccount;
|
2020-01-23 21:35:00 +01:00
|
|
|
use App\Jobs\Util\StartMigration;
|
2019-11-20 06:41:49 +01:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\CompanyUser;
|
|
|
|
use App\Transformers\AccountTransformer;
|
|
|
|
use App\Transformers\CompanyUserTransformer;
|
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
class MigrationController extends BaseController
|
|
|
|
{
|
|
|
|
use DispatchesJobs;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Purge Company
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-11-20 06:41:49 +01:00
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/migration/purge/{company}",
|
|
|
|
* operationId="postPurgeCompany",
|
|
|
|
* tags={"migration"},
|
|
|
|
* summary="Attempts to purge a company record and all its child records",
|
|
|
|
* description="Attempts to purge a company record and all its child records",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="company",
|
|
|
|
* in="path",
|
|
|
|
* description="The Company Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Success",
|
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-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(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-11-20 06:41:49 +01:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function purgeCompany(Company $company)
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
$company->delete();
|
2019-11-20 06:41:49 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return response()->json(['message'=>'Company purged'], 200);
|
2019-11-20 06:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Purge Company but save settings
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2019-11-20 06:41:49 +01:00
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/migration/purge_save_settings/{company}",
|
|
|
|
* operationId="postPurgeCompanySaveSettings",
|
|
|
|
* tags={"migration"},
|
|
|
|
* summary="Attempts to purge a companies child records but save the company record and its settings",
|
|
|
|
* description="Attempts to purge a companies child records but save the company record and its settings",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(
|
|
|
|
* name="company",
|
|
|
|
* in="path",
|
|
|
|
* description="The Company Hashed ID",
|
|
|
|
* example="D2J234DFA",
|
|
|
|
* required=true,
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="string",
|
|
|
|
* format="string",
|
|
|
|
* ),
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Success",
|
|
|
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-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(
|
2019-12-30 22:59:12 +01:00
|
|
|
* response="default",
|
2019-11-20 06:41:49 +01:00
|
|
|
* description="Unexpected Error",
|
|
|
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function purgeCompanySaveSettings(Company $company)
|
|
|
|
{
|
2019-11-20 21:55:16 +01:00
|
|
|
$company->client->delete();
|
|
|
|
$company->save();
|
2019-11-20 06:41:49 +01:00
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return response()->json(['message'=>'Settings preserved'], 200);
|
2019-11-20 06:41:49 +01:00
|
|
|
}
|
2020-01-23 21:35:00 +01:00
|
|
|
|
|
|
|
public function uploadMigrationFile(UploadMigrationFileRequest $request)
|
|
|
|
{
|
|
|
|
$file = $request->file('migration')->storeAs(
|
|
|
|
'migrations', $request->file('migration')->getClientOriginalName()
|
|
|
|
);
|
|
|
|
|
|
|
|
/** Not tested. */
|
|
|
|
StartMigration::dispatchNow($file, auth()->user(), auth()->user()->company);
|
|
|
|
|
|
|
|
return response()->json([], 200);
|
|
|
|
}
|
2019-11-20 06:41:49 +01:00
|
|
|
}
|