diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 2efffd5daf5a..1d6676407a22 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -47,27 +47,27 @@ class Handler extends ExceptionHandler * @var array */ protected $dontReport = [ - PDOException::class, - MaxAttemptsExceededException::class, - CommandNotFoundException::class, - ValidationException::class, - ModelNotFoundException::class, - NotFoundHttpException::class, + // PDOException::class, + // MaxAttemptsExceededException::class, + // CommandNotFoundException::class, + // ValidationException::class, + // ModelNotFoundException::class, + // NotFoundHttpException::class, ]; protected $selfHostDontReport = [ - FilePermissionsFailure::class, - PDOException::class, - MaxAttemptsExceededException::class, - CommandNotFoundException::class, - ValidationException::class, - ModelNotFoundException::class, - NotFoundHttpException::class, - UnableToCreateDirectory::class, - GuzzleHttp\Exception\ConnectException::class, - Symfony\Component\Process\Exception\RuntimeException::class, - InvalidArgumentException::class, - RuntimeException::class, + // FilePermissionsFailure::class, + // PDOException::class, + // MaxAttemptsExceededException::class, + // CommandNotFoundException::class, + // ValidationException::class, + // ModelNotFoundException::class, + // NotFoundHttpException::class, + // UnableToCreateDirectory::class, + // GuzzleHttp\Exception\ConnectException::class, + // Symfony\Component\Process\Exception\RuntimeException::class, + // InvalidArgumentException::class, + // RuntimeException::class, ]; protected $hostedDontReport = [ diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 666a01509886..b8432f54293d 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -422,16 +422,6 @@ class InvoiceController extends BaseController event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - // $transaction = [ - // 'invoice' => $invoice->transaction_event(), - // 'payment' => [], - // 'client' => $invoice->client->transaction_event(), - // 'credit' => [], - // 'metadata' => [], - // ]; - - // TransactionLog::dispatch(TransactionEvent::INVOICE_UPDATED, $transaction, $invoice->company->db); - return $this->itemResponse($invoice); } diff --git a/app/Jobs/Inventory/AdjustProductInventory.php b/app/Jobs/Inventory/AdjustProductInventory.php index 56ebe417e784..95ba7cc9150c 100644 --- a/app/Jobs/Inventory/AdjustProductInventory.php +++ b/app/Jobs/Inventory/AdjustProductInventory.php @@ -160,9 +160,5 @@ class AdjustProductInventory implements ShouldQueue }); - // $nmo->to_user = $this->company->owner(); - - // NinjaMailerJob::dispatch($nmo); - } } diff --git a/app/Jobs/Product/UpdateOrCreateProduct.php b/app/Jobs/Product/UpdateOrCreateProduct.php index 187e7381020f..02a6d7e6b5bb 100644 --- a/app/Jobs/Product/UpdateOrCreateProduct.php +++ b/app/Jobs/Product/UpdateOrCreateProduct.php @@ -131,7 +131,7 @@ class UpdateOrCreateProduct implements ShouldQueue $product->company_id = $this->invoice->company_id; $product->project_id = $this->invoice->project_id; $product->vendor_id = $this->invoice->vendor_id; - $product->save(); + $product->saveQuietly(); } } diff --git a/app/Jobs/Util/WebhookSingle.php b/app/Jobs/Util/WebhookSingle.php index 5ecbad2aad4a..31cc4fbf747a 100644 --- a/app/Jobs/Util/WebhookSingle.php +++ b/app/Jobs/Util/WebhookSingle.php @@ -15,11 +15,14 @@ use App\Jobs\Util\SystemLogger; use App\Libraries\MultiDB; use App\Models\Client as ClientModel; use App\Models\Company; +use App\Models\Product; use App\Models\SystemLog; use App\Models\Webhook; use App\Transformers\ArraySerializer; use GuzzleHttp\Client; use GuzzleHttp\Exception\BadResponseException; +use GuzzleHttp\Exception\ClientException; +use GuzzleHttp\Exception\ServerException; use GuzzleHttp\RequestOptions; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -28,8 +31,6 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use League\Fractal\Manager; use League\Fractal\Resource\Item; -use GuzzleHttp\Exception\ClientException; -use GuzzleHttp\Exception\ServerException; class WebhookSingle implements ShouldQueue { @@ -78,9 +79,15 @@ class WebhookSingle implements ShouldQueue MultiDB::setDb($this->db); $subscription = Webhook::with('company')->find($this->subscription_id); + + if($subscription) + nlog("firing event ID {$subscription->event_id}"); if(!$subscription){ $this->fail(); + + nlog("failed to fire event, could not find webhook ID {$this->subscription_id}"); + return; } @@ -237,17 +244,19 @@ class WebhookSingle implements ShouldQueue private function resolveClient() { //make sure it isn't an instance of the Client Model - if ((! $this->entity instanceof ClientModel) && $this->entity->client()->exists()) { + if (! $this->entity instanceof ClientModel && ! $this->entity instanceof Product && $this->entity->client()->exists()) { return $this->entity->client; } - return $this->company->clients()->first(); + return false; } public function failed($exception = null) { - if($exception) + if($exception){ + nlog("failed in webhooksingle"); nlog($exception->getMessage()); + } } } diff --git a/app/Listeners/Invoice/CreateInvoicePdf.php b/app/Listeners/Invoice/CreateInvoicePdf.php index f78cdc315bb6..6921f0d93c7a 100644 --- a/app/Listeners/Invoice/CreateInvoicePdf.php +++ b/app/Listeners/Invoice/CreateInvoicePdf.php @@ -38,21 +38,18 @@ class CreateInvoicePdf implements ShouldQueue if (isset($event->invoice)) { $event->invoice->invitations->each(function ($invitation) { - // CreateEntityPdf::dispatch($invitation->load('invoice', 'contact.client.company')); (new CreateEntityPdf($invitation->load('invoice', 'contact.client.company')))->handle(); }); } if (isset($event->quote)) { $event->quote->invitations->each(function ($invitation) { - // CreateEntityPdf::dispatch($invitation->load('quote', 'contact.client.company')); (new CreateEntityPdf($invitation->load('quote', 'contact.client.company')))->handle(); }); } if (isset($event->credit)) { $event->credit->invitations->each(function ($invitation) { -// CreateEntityPdf::dispatch($invitation->load('credit', 'contact.client.company')); (new CreateEntityPdf($invitation->load('credit', 'contact.client.company')))->handle(); }); diff --git a/app/Models/Quote.php b/app/Models/Quote.php index a9dee7fd7060..03c09ae60a77 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -212,7 +212,7 @@ class Quote extends BaseModel $this->invitations->each(function ($invitation) { if (! isset($invitation->sent_date)) { $invitation->sent_date = Carbon::now(); - $invitation->save(); + $invitation->saveQuietly(); } }); } diff --git a/app/Models/Webhook.php b/app/Models/Webhook.php index 367f2f44664c..aedd148c2a97 100644 --- a/app/Models/Webhook.php +++ b/app/Models/Webhook.php @@ -18,11 +18,11 @@ class Webhook extends BaseModel use SoftDeletes; use Filterable; - const EVENT_CREATE_CLIENT = 1; + const EVENT_CREATE_CLIENT = 1; //tested - const EVENT_CREATE_INVOICE = 2; + const EVENT_CREATE_INVOICE = 2; //tested - const EVENT_CREATE_QUOTE = 3; + const EVENT_CREATE_QUOTE = 3; //tested const EVENT_CREATE_PAYMENT = 4; @@ -32,9 +32,9 @@ class Webhook extends BaseModel const EVENT_DELETE_QUOTE = 7; - const EVENT_UPDATE_INVOICE = 8; + const EVENT_UPDATE_INVOICE = 8; //tested - const EVENT_DELETE_INVOICE = 9; + const EVENT_DELETE_INVOICE = 9; //tested const EVENT_UPDATE_CLIENT = 10; @@ -82,7 +82,7 @@ class Webhook extends BaseModel const EVENT_ARCHIVE_PAYMENT = 32; - const EVENT_ARCHIVE_INVOICE = 33; + const EVENT_ARCHIVE_INVOICE = 33; //tested const EVENT_ARCHIVE_QUOTE = 34; diff --git a/app/Observers/ClientObserver.php b/app/Observers/ClientObserver.php index af7ee3ec9e3d..7bece9b40364 100644 --- a/app/Observers/ClientObserver.php +++ b/app/Observers/ClientObserver.php @@ -17,6 +17,7 @@ use App\Models\Webhook; class ClientObserver { + public $afterCommit = true; /** * Handle the client "created" event. diff --git a/app/Observers/CreditObserver.php b/app/Observers/CreditObserver.php index d457ac67628d..9645251a756b 100644 --- a/app/Observers/CreditObserver.php +++ b/app/Observers/CreditObserver.php @@ -19,6 +19,9 @@ use App\Models\Webhook; class CreditObserver { + + public $afterCommit = true; + /** * Handle the client "created" event. * diff --git a/app/Observers/ExpenseObserver.php b/app/Observers/ExpenseObserver.php index b2b4ce4700ad..10c0b79d4387 100644 --- a/app/Observers/ExpenseObserver.php +++ b/app/Observers/ExpenseObserver.php @@ -17,6 +17,8 @@ use App\Models\Webhook; class ExpenseObserver { + public $afterCommit = true; + /** * Handle the expense "created" event. * diff --git a/app/Observers/PaymentObserver.php b/app/Observers/PaymentObserver.php index 205ba9307748..744ca853bfa4 100644 --- a/app/Observers/PaymentObserver.php +++ b/app/Observers/PaymentObserver.php @@ -17,6 +17,9 @@ use App\Models\Webhook; class PaymentObserver { + + public $afterCommit = true; + /** * Handle the payment "created" event. * diff --git a/app/Observers/ProductObserver.php b/app/Observers/ProductObserver.php index b94ffcc597da..64254260014c 100644 --- a/app/Observers/ProductObserver.php +++ b/app/Observers/ProductObserver.php @@ -17,6 +17,9 @@ use App\Models\Webhook; class ProductObserver { + + public $afterCommit = true; + /** * Handle the product "created" event. * diff --git a/app/Observers/PurchaseOrderObserver.php b/app/Observers/PurchaseOrderObserver.php index 14fa2f10edbc..d7e83bd44fce 100644 --- a/app/Observers/PurchaseOrderObserver.php +++ b/app/Observers/PurchaseOrderObserver.php @@ -17,6 +17,9 @@ use App\Models\Webhook; class PurchaseOrderObserver { + + public $afterCommit = true; + /** * Handle the client "created" event. * diff --git a/app/Observers/QuoteObserver.php b/app/Observers/QuoteObserver.php index ba9248ede383..bc2f50c0373a 100644 --- a/app/Observers/QuoteObserver.php +++ b/app/Observers/QuoteObserver.php @@ -17,6 +17,9 @@ use App\Models\Webhook; class QuoteObserver { + + public $afterCommit = true; + /** * Handle the quote "created" event. * @@ -42,7 +45,7 @@ class QuoteObserver * @return void */ public function updated(Quote $quote) - { + {nlog("updated"); $event = Webhook::EVENT_UPDATE_QUOTE; diff --git a/app/Observers/TaskObserver.php b/app/Observers/TaskObserver.php index bc51069a0d69..8d314ba1195f 100644 --- a/app/Observers/TaskObserver.php +++ b/app/Observers/TaskObserver.php @@ -17,6 +17,9 @@ use App\Models\Webhook; class TaskObserver { + + public $afterCommit = true; + /** * Handle the task "created" event. * diff --git a/app/Observers/VendorObserver.php b/app/Observers/VendorObserver.php index 461c6f117397..89344ac4a538 100644 --- a/app/Observers/VendorObserver.php +++ b/app/Observers/VendorObserver.php @@ -17,6 +17,9 @@ use App\Models\Webhook; class VendorObserver { + + public $afterCommit = true; + /** * Handle the vendor "created" event. * diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 56e379018e35..713559736639 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -231,8 +231,9 @@ class BaseRepository $invitation_class = sprintf('App\\Models\\%sInvitation', $resource); $invitation = $invitation_class::where('key', $invitation)->first(); - if ($invitation) + if ($invitation){ $invitation->delete(); + } }); @@ -257,7 +258,6 @@ class BaseRepository ->first(); if ($new_invitation && $new_invitation->trashed()) { - $new_invitation->restore(); } else { @@ -267,7 +267,7 @@ class BaseRepository $new_invitation->{$lcfirst_resource_id} = $model->id; $new_invitation->client_contact_id = $contact->id; $new_invitation->key = $this->createDbHash($model->company->db); - $new_invitation->save(); + $new_invitation->saveQuietly(); } } @@ -350,7 +350,6 @@ class BaseRepository $model = $model->calc()->getQuote(); - if($this->new_model) event('eloquent.created: App\Models\Quote', $model); else @@ -371,9 +370,7 @@ class BaseRepository event('eloquent.updated: App\Models\RecurringInvoice', $model); } - $model->save(); - -// nlog("save time = ". microtime(true) - $start); + $model->saveQuietly(); return $model->fresh(); } diff --git a/app/Services/Invoice/MarkInvoiceDeleted.php b/app/Services/Invoice/MarkInvoiceDeleted.php index 145af4ea543b..e685efe8f15d 100644 --- a/app/Services/Invoice/MarkInvoiceDeleted.php +++ b/app/Services/Invoice/MarkInvoiceDeleted.php @@ -156,8 +156,8 @@ class MarkInvoiceDeleted extends AbstractService $this->invoice->number = $number; //wipe references to invoices from related entities. - $this->invoice->tasks()->update(['invoice_id' => null]); - $this->invoice->expenses()->update(['invoice_id' => null]); + $this->invoice->tasks()->updateQuietly(['invoice_id' => null]); + $this->invoice->expenses()->updateQuietly(['invoice_id' => null]); return $this; } diff --git a/app/Services/Quote/ApplyNumber.php b/app/Services/Quote/ApplyNumber.php index 22ce28ba8267..f8f2a0fa7316 100644 --- a/app/Services/Quote/ApplyNumber.php +++ b/app/Services/Quote/ApplyNumber.php @@ -37,12 +37,10 @@ class ApplyNumber switch ($this->client->getSetting('counter_number_applied')) { case 'when_saved': $quote = $this->trySaving($quote); - // $quote->number = $this->getNextQuoteNumber($this->client, $quote); break; case 'when_sent': if ($quote->status_id == Quote::STATUS_SENT) { $quote = $this->trySaving($quote); - // $quote->number = $this->getNextQuoteNumber($this->client, $quote); } break; diff --git a/app/Services/Quote/CreateInvitations.php b/app/Services/Quote/CreateInvitations.php index 52ee0d6ceb9d..34468adaacfd 100644 --- a/app/Services/Quote/CreateInvitations.php +++ b/app/Services/Quote/CreateInvitations.php @@ -52,7 +52,7 @@ class CreateInvitations $ii->key = $this->createDbHash($this->quote->company->db); $ii->quote_id = $this->quote->id; $ii->client_contact_id = $contact->id; - $ii->save(); + $ii->saveQuietly(); } elseif ($invitation && ! $contact->send_email) { $invitation->delete(); } @@ -81,7 +81,7 @@ class CreateInvitations $ii->key = $this->createDbHash($this->quote->company->db); $ii->quote_id = $this->quote->id; $ii->client_contact_id = $contact->id; - $ii->save(); + $ii->saveQuietly(); } return $this->quote->fresh(); @@ -93,6 +93,6 @@ class CreateInvitations $new_contact->client_id = $this->quote->client_id; $new_contact->contact_key = Str::random(40); $new_contact->is_primary = true; - $new_contact->save(); + $new_contact->saveQuietly(); } } diff --git a/tests/Feature/ClientApiTest.php b/tests/Feature/ClientApiTest.php index 8bc5fb4dc3c6..734aa4cef8f0 100644 --- a/tests/Feature/ClientApiTest.php +++ b/tests/Feature/ClientApiTest.php @@ -58,6 +58,7 @@ class ClientApiTest extends TestCase } + public function testCrossCompanyBulkActionsFail() { diff --git a/tests/Feature/WebhookAPITest.php b/tests/Feature/WebhookAPITest.php index 6f9f9c022518..5f56dfc240b8 100644 --- a/tests/Feature/WebhookAPITest.php +++ b/tests/Feature/WebhookAPITest.php @@ -11,6 +11,7 @@ namespace Tests\Feature; +use App\Jobs\Util\WebhookHandler; use App\Repositories\ClientContactRepository; use App\Repositories\ClientRepository; use App\Utils\Traits\MakesHash; @@ -48,6 +49,33 @@ class WebhookAPITest extends TestCase $this->withoutExceptionHandling(); } + // public function testClientWebhooks() + // { + // // client archived = 37 + // $data = [ + // 'target_url' => 'http://hook.com', + // 'event_id' => 37, + // 'rest_method' => 'post', + // 'format' => 'JSON', + // ]; + + // $response = $this->withHeaders([ + // 'X-API-SECRET' => config('ninja.api_secret'), + // 'X-API-TOKEN' => $this->token, + // ])->post('/api/v1/webhooks', $data); + + // $repo = new ClientRepository(new ClientContactRepository()); + + // $repo->archive($this->client); + + // \Illuminate\Support\Facades\Queue::after(function (WebhookHandler $event) { + // $this->assertTrue($event->job->isReleased()); + // }); + + // \Illuminate\Support\Facades\Queue::assertPushed(WebhookHandler::class); + + // } + public function testWebhookGetFilter() { $response = $this->withHeaders([