diff --git a/.env.example b/.env.example index 895e0c40f432..a9c2da28c840 100644 --- a/.env.example +++ b/.env.example @@ -56,4 +56,4 @@ SELF_UPDATER_USE_BRANCH = v2 SELF_UPDATER_MAILTO_ADDRESS = user@example.com SELF_UPDATER_MAILTO_NAME = "John Doe" COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}' - +SENTRY_LARAVEL_DSN=https://cc7e8e2c678041689e53e409b7dba236@sentry.invoicing.co/5 \ No newline at end of file diff --git a/app/Designs/Designer.php b/app/Designs/Designer.php index 73bf62c9b5f1..e2d28d660630 100644 --- a/app/Designs/Designer.php +++ b/app/Designs/Designer.php @@ -175,7 +175,6 @@ class Designer if (strlen($this->exported_variables['$product_table_body']) == 0) { $this->exported_variables['$product_table_header'] = ''; } - //\Log::error("Exporting variables took = ".(microtime(true)-$s)); return $this; } diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 9ed08fa97b26..3a190c827900 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -92,10 +92,8 @@ class InvoiceController extends Controller */ public function bulk(ProcessInvoicesInBulkRequest $request) { -// \Log::error($request->all()); - $transformed_ids = $this->transformKeys($request->invoices); - //\Log::error($transformed_ids); + $transformed_ids = $this->transformKeys($request->invoices); if ($request->input('action') == 'payment') { return $this->makePayment((array)$transformed_ids); @@ -112,7 +110,6 @@ class InvoiceController extends Controller $invoices = Invoice::whereIn('id', $ids) ->whereClientId(auth()->user()->client->id) ->get(); - //\Log::error($invoices); $total = $invoices->sum('balance'); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 0671607026ae..ed56eb57b90d 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -687,7 +687,7 @@ class InvoiceController extends BaseController }); if ($invoice->invitations->count() > 0) { - \Log::error("more than one invitation to send"); + event(new InvoiceWasEmailed($invoice->invitations->first())); } diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 1371b6ed4cc2..4ac725813822 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -151,8 +151,6 @@ class PreviewController extends BaseController $design_object = json_decode(json_encode(request()->input('design'))); - //\Log::error(print_r($design_object,1)); - if (!is_object($design_object)) { return response()->json(['message' => 'Invalid custom design object'], 400); } diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php index 56c105388813..04b3efbe85fc 100644 --- a/app/Http/Requests/Company/UpdateCompanyRequest.php +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -11,13 +11,16 @@ namespace App\Http\Requests\Company; +use App\DataMapper\CompanySettings; use App\Http\Requests\Request; use App\Http\ValidationRules\ValidSettingsRule; +use App\Utils\Traits\MakesHash; use Illuminate\Support\Facades\Log; use Illuminate\Validation\Rule; class UpdateCompanyRequest extends Request { + use MakesHash; /** * Determine if the user is authorized to make this request. * @@ -53,4 +56,5 @@ class UpdateCompanyRequest extends Request protected function prepareForValidation() { } + } diff --git a/app/Http/ViewComposers/PortalComposer.php b/app/Http/ViewComposers/PortalComposer.php index 812fb958a1fe..597ff721cefa 100644 --- a/app/Http/ViewComposers/PortalComposer.php +++ b/app/Http/ViewComposers/PortalComposer.php @@ -49,8 +49,6 @@ class PortalComposer $data['client'] = auth()->user()->client; $data['settings'] = auth()->user()->client->getMergedSettings(); - //\Log::error(print_r($data['settings'],1)); - return $data; } diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index 0101089f89b6..6e00a5a59906 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -34,13 +34,15 @@ class CreateAccount { if(config('ninja.environment') == 'selfhost' && Account::all()->count() == 0) { - $this->create(); + return $this->create(); }elseif (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) { - return response()->json(array('message' => Ninja::selfHostedMessage()), 400); + return response()->json(array('message' => Ninja::selfHostedMessage()), 400); } elseif (!Ninja::boot()) { - return response()->json(array('message' => Ninja::parse()), 401); + return response()->json(array('message' => Ninja::parse()), 401); } + return $this->create(); + } private function create() @@ -48,28 +50,35 @@ class CreateAccount $sp794f3f = Account::create($this->request); $sp794f3f->referral_code = Str::random(32); - + if(!$sp794f3f->key) $sp794f3f->key = Str::random(32); - + $sp794f3f->save(); - + $sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f); $sp035a66->load('account'); $sp794f3f->default_company_id = $sp035a66->id; $sp794f3f->save(); + $spaa9f78 = CreateUser::dispatchNow($this->request, $sp794f3f, $sp035a66, true); + if ($spaa9f78) { auth()->login($spaa9f78, false); } + $spaa9f78->setCompany($sp035a66); $spafe62e = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT'); $sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e); + if ($spaa9f78) { event(new AccountCreated($spaa9f78)); } + $spaa9f78->fresh(); + $sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja(); + return $sp794f3f; } diff --git a/app/Jobs/Credit/CreateCreditPdf.php b/app/Jobs/Credit/CreateCreditPdf.php index 8492601c329d..bce5a33d9681 100644 --- a/app/Jobs/Credit/CreateCreditPdf.php +++ b/app/Jobs/Credit/CreateCreditPdf.php @@ -87,13 +87,10 @@ class CreateCreditPdf implements ShouldQueue //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0755); - //\Log::error($html); $pdf = $this->makePdf(null, null, $html); $instance = Storage::disk($this->disk)->put($file_path, $pdf); - //$instance= Storage::disk($this->disk)->path($file_path); - // return $file_path; } } diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 82d8233dec42..2b43fa683e93 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -86,7 +86,6 @@ class CreateInvoicePdf implements ShouldQueue //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0755); - //\Log::error($html); $pdf = $this->makePdf(null, null, $html); $instance = Storage::disk($this->disk)->put($file_path, $pdf); diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index b0ca2ba05f26..4f1cce5e79a9 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -2,6 +2,7 @@ namespace App\Jobs\Util; +use App\DataMapper\CompanySettings; use App\Exceptions\MigrationValidatorFailed; use App\Exceptions\ResourceDependencyMissing; use App\Exceptions\ResourceNotAvailableForMigration; @@ -41,6 +42,7 @@ use App\Repositories\ProductRepository; use App\Repositories\QuoteRepository; use App\Repositories\UserRepository; use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver; +use App\Utils\Traits\MakesHash; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -54,6 +56,7 @@ class Import implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use CompanyGatewayFeesAndLimitsSaver; + use MakesHash; /** * @var array @@ -129,7 +132,7 @@ class Import implements ShouldQueue public function handle() { foreach ($this->data as $key => $resource) { - \Log::error("importing {$key}"); + if (!in_array($key, $this->available_imports)) { throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration."); } @@ -138,7 +141,6 @@ class Import implements ShouldQueue $this->{$method}($resource); - info("$key done!!"); } info('CompletedπŸš€πŸš€πŸš€πŸš€πŸš€ at ' . now()); @@ -152,12 +154,14 @@ class Import implements ShouldQueue { Company::unguard(); + $data = $this->transformCompanyData($data); + $rules = (new UpdateCompanyRequest())->rules(); $validator = Validator::make($data, $rules); if ($validator->fails()) { - // \Log::error($validator->errors()); + throw new MigrationValidatorFailed(json_encode($validator->errors())); } @@ -171,6 +175,32 @@ class Import implements ShouldQueue Company::reguard(); } + private function transformCompanyData(array $data): array + { + + $company_settings = CompanySettings::defaults(); + + if (array_key_exists('settings', $data) ) { + + foreach ($data['settings'] as $key => $value) { + + if($key == 'invoice_design_id' || $key == 'quote_design_id' || $key == 'credit_design_id') + { + $value = $this->encodePrimaryKey($value); + } + + $company_settings->{$key} = $value; + + } + + $data['settings'] = $company_settings; + + } + + return $data; + + } + /** * @param array $data * @throws \Exception diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index 89c283b94f6b..f300f4d12cd7 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -58,7 +58,7 @@ class StartMigration implements ShouldQueue */ public function handle() { - \Log::error("start handle"); + MultiDB::setDb($this->company->db); auth()->login($this->user, false); @@ -91,7 +91,6 @@ class StartMigration implements ShouldQueue } } - \Log::error("stop handle"); } @@ -101,7 +100,6 @@ class StartMigration implements ShouldQueue */ public function start(string $filename): void { - \Log::error("start start"); $file = storage_path("migrations/$filename/migration.json"); @@ -116,7 +114,5 @@ class StartMigration implements ShouldQueue $data = json_decode($file, 1); Import::dispatchNow($data, $this->company, $this->user); - - \Log::error("start stop"); } } diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 0dc397c3a15b..0920227a47ce 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -182,7 +182,6 @@ class MultiDB public static function findAndSetDbByDomain($subdomain) :bool { - //\Log::error("searching for {$domain}"); foreach (self::$dbs as $db) { if ($company = Company::on($db)->whereSubdomain($subdomain)->first()) { diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index a1a1f90964f0..032161cbc375 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -168,11 +168,5 @@ class EventServiceProvider extends ServiceProvider public function boot() { parent::boot(); - //$events->subscribe('*'); - // \Event::listen('event.*', function ($eventName, array $data) { - // \Log::error("Event Service Provider"); - // }); - - } } diff --git a/app/Providers/MultiDBProvider.php b/app/Providers/MultiDBProvider.php index 07a14e8da642..aa550d035c95 100644 --- a/app/Providers/MultiDBProvider.php +++ b/app/Providers/MultiDBProvider.php @@ -39,11 +39,6 @@ class MultiDBProvider extends ServiceProvider if (isset($event->job->payload()['db'])) { - //\Log::error("Provider Setting DB = ".$event->job->payload()['db']); - //\Log::error('Event Job '.$event->connectionName); -// \Log::error(print_r($event->job,1)); - //\Log::error(print_r($event->job->payload(),1)); - MultiDB::setDb($event->job->payload()['db']); } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 69318e71065a..2aeee0765b7d 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -209,7 +209,17 @@ class BaseRepository $data = array_merge($company_defaults, $data); } - $model->fill($data); + $tmp_data = $data; + + if(isset($tmp_data['invitations'])) + unset($tmp_data['invitations']); + + if(isset($tmp_data['client_contacts'])) + unset($tmp_data['client_contacts']); + +\Log::error(print_r($tmp_data,1)); + + $model->fill($tmp_data); $model->save(); $invitation_factory_class = sprintf("App\\Factory\\%sInvitationFactory", $resource); @@ -234,6 +244,8 @@ class BaseRepository foreach ($data['invitations'] as $invitation) { +\Log::error(print_r($invitation,1)); + //if no invitations are present - create one. if (! $this->getInvitation($invitation, $resource)) { if (isset($invitation['id'])) { @@ -242,7 +254,9 @@ class BaseRepository //make sure we are creating an invite for a contact who belongs to the client only! $contact = ClientContact::find($invitation['client_contact_id']); - + +\Log::error(print_r($contact,1)); + if ($model->client_id == $contact->client_id); { $new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id); diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 468496423e65..2bcdb2f195bc 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -74,8 +74,7 @@ class ClientTest extends TestCase $response->assertStatus(200); $acc = $response->json(); - - + $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id'])); $token = $account->default_company->tokens->first()->token;