Merge pull request #5790 from turbo124/v5-develop

Fixes for overriding ninja mailer
This commit is contained in:
David Bomba 2021-05-22 16:17:13 +10:00 committed by GitHub
commit 2f15246fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View File

@ -63,6 +63,7 @@ class NinjaMailerJob implements ShouldQueue
{
$this->nmo = $nmo;
$this->override = $override;
}

View File

@ -210,7 +210,7 @@ class Import implements ShouldQueue
$this->{$method}($data[$import]);
}
if(Ninja::isHosted())
if(Ninja::isHosted() && array_key_exists('ninja_tokens', $data))
$this->processNinjaTokens($data['ninja_tokens']);
$this->setInitialCompanyLedgerBalances();
@ -225,6 +225,7 @@ class Import implements ShouldQueue
->send(new MigrationCompleted($this->company, implode("<br>",$check_data)));
}
catch(\Exception $e) {
nlog($e->getMessage());
}
@ -1671,6 +1672,7 @@ class Import implements ShouldQueue
$ninja_client->postal_code = $local_company->settings->postal_code;
$ninja_client->state = $local_company->settings->state;
$ninja_client->country_id = $local_company->settings->country_id;
$ninja_client->custom_value1 = $local_company->company_key;
$ninja_client->save();
@ -1690,21 +1692,24 @@ class Import implements ShouldQueue
private function processNinjaTokens(array $data)
{
if(count($data) == 0)
$ninja_client = $this->buildNewUserPlan();
$current_db = config('database.default');
$local_company = Company::find($this->company->id);
MultiDB::setDb('db-ninja-01');
if($existing_client = Client::where('custom_value1', $local_company->company_key)->first())
$ninja_client = $existing_client;
else
$ninja_client = $this->buildNewUserPlan();
foreach($data as $token)
{
//get invoiceninja company_id
$ninja_company = Company::where('id', config('ninja.ninja_default_company_id'))->first();
$token['company_id'] = $ninja_client->company_id;
$token['client_id'] = $ninja_client->id;
$token['user_id'] = $ninja_client->user_id;
$token['company_id'] = $ninja_company->id;
$token['client_id'] = $ninja_client->id;/////
$token['user_id'] = $ninja_company->owner()->id;
$token['company_gateway_id'] = config('ninja.ninja_default_company_gateway_id');
//todo

View File

@ -20,6 +20,7 @@ use App\Libraries\MultiDB;
use App\Mail\MigrationFailed;
use App\Models\Company;
use App\Models\User;
use App\Utils\Ninja;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -139,6 +140,10 @@ class StartMigration implements ShouldQueue
$this->company->update_products = $update_product_flag;
$this->company->save();
if(Ninja::isHosted())
app('sentry')->captureException($e);
Mail::to($this->user->email, $this->user->name())->send(new MigrationFailed($e, $this->company->settings, $e->getMessage()));
if (app()->environment() !== 'production') {