diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index 2c48291dbd53..935b088c401b 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -453,18 +453,16 @@ class CompanyExport implements ShouldQueue Storage::disk(config('filesystems.default'))->put($path.$file_name, $tempStream); // fclose($fp); - nlog(Storage::disk(config('filesystems.default'))->url($path.$file_name)); - fclose($tempStream); - // $nmo = new NinjaMailerObject; - // $nmo->mailable = new DownloadBackup(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company); - // $nmo->to_user = $this->user; - // $nmo->settings = $this->company->settings; - // $nmo->company = $this->company; - - // NinjaMailerJob::dispatch($nmo); + $nmo = new NinjaMailerObject; + $nmo->mailable = new DownloadBackup(Storage::disk(config('filesystems.default'))->url($path.$file_name), $this->company); + $nmo->to_user = $this->user; + $nmo->company = $this->company; + $nmo->settings = $this->company->settings; + NinjaMailerJob::dispatch($nmo); + UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1)); } diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 6e8777750635..ee42f619cc54 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -21,6 +21,7 @@ use App\Libraries\Google\Google; use App\Libraries\MultiDB; use App\Mail\TemplateEmail; use App\Models\ClientContact; +use App\Models\Company; use App\Models\Invoice; use App\Models\Payment; use App\Models\SystemLog; @@ -72,6 +73,8 @@ class NinjaMailerJob implements ShouldQueue /*Set the correct database*/ MultiDB::setDb($this->nmo->company->db); + $company = Company::where('company_key', $this->nmo->company->company_key)->first(); + /* Set the email driver */ $this->setMailDriver(); @@ -86,7 +89,7 @@ class NinjaMailerJob implements ShouldQueue } else { - $this->nmo->mailable->replyTo($this->nmo->company->owner()->email, $this->nmo->company->owner()->present()->name()); + $this->nmo->mailable->replyTo($company->owner()->email, $company->owner()->present()->name()); } diff --git a/app/Mail/DownloadBackup.php b/app/Mail/DownloadBackup.php index 5b354a5db265..0dee339dda10 100644 --- a/app/Mail/DownloadBackup.php +++ b/app/Mail/DownloadBackup.php @@ -27,14 +27,17 @@ class DownloadBackup extends Mailable */ public function build() { + $company = Company::where('company_key', $this->company->company_key)->first(); + return $this->from(config('mail.from.address'), config('mail.from.name')) ->subject(ctrans('texts.download_backup_subject')) ->markdown( 'email.admin.download_files', [ 'url' => $this->file_path, - 'logo' => $this->company->present()->logo, - 'whitelabel' => $this->company->account->isPaid() ? true : false, + 'logo' => $company->present()->logo, + 'whitelabel' => $company->account->isPaid() ? true : false, + 'settings' => $company->settings ] ); } diff --git a/app/Models/Company.php b/app/Models/Company.php index 6b5d6c693d88..14c2335b2d51 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -432,12 +432,8 @@ class Company extends BaseModel } public function owner() - {nlog("in owner"); - $c = $this->company_users->where('is_owner', true)->first(); - -nlog($c); - - return User::find($c->user_id); + { + return $this->company_users->where('is_owner', true)->first()->user; } public function resolveRouteBinding($value, $field = null) diff --git a/app/Models/User.php b/app/Models/User.php index b33feb1d58e3..460f8a0bb2ea 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -170,12 +170,10 @@ class User extends Authenticatable implements MustVerifyEmail public function getCompany() { if ($this->company) { - nlog("company Found"); return $this->company; } if (request()->header('X-API-TOKEN')) { - nlog("no company - using token to resolve"); $company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first(); return $company_token->company;