From 83692ed61858f31e4b85e23e32396336e04d8a53 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Feb 2022 18:48:22 +1100 Subject: [PATCH 1/3] refactor queries --- VERSION.txt | 2 +- app/Http/Controllers/Auth/LoginController.php | 2 +- .../ClientPortal/EntityViewController.php | 10 ++++++++-- .../ClientPortal/InvitationController.php | 4 ---- .../Controllers/ClientPortal/PaymentController.php | 2 +- app/Http/Middleware/ContactTokenAuth.php | 2 +- app/Http/Middleware/TokenAuth.php | 2 +- .../Payments/PaymentResponseRequest.php | 2 +- app/Libraries/MultiDB.php | 4 ++-- app/Models/User.php | 2 +- .../Authorize/AuthorizeCreditCard.php | 2 +- app/PaymentDrivers/PayFastPaymentDriver.php | 2 +- app/Repositories/BaseRepository.php | 2 +- app/Repositories/CreditRepository.php | 2 +- app/Repositories/InvoiceRepository.php | 2 +- app/Repositories/QuoteRepository.php | 2 +- app/Repositories/RecurringInvoiceRepository.php | 2 +- app/Transformers/UserTransformer.php | 2 +- app/Utils/PhantomJS/Phantom.php | 2 +- config/ninja.php | 4 ++-- database/schema/db-ninja-01-schema.dump | 14 ++++++++++++++ tests/Feature/PaymentTest.php | 2 +- 22 files changed, 43 insertions(+), 27 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 72e2dd4be49c..a4c570d1143d 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.3.61 \ No newline at end of file +5.3.62 \ No newline at end of file diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index c0c53faa0bd3..9e097983bedd 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -310,7 +310,7 @@ class LoginController extends BaseController */ public function refresh(Request $request) { - $company_token = CompanyToken::whereRaw('BINARY `token`= ?', [$request->header('X-API-TOKEN')])->first(); + $company_token = CompanyToken::where('token', $request->header('X-API-TOKEN'))->first(); $cu = CompanyUser::query() ->where('user_id', $company_token->user_id); diff --git a/app/Http/Controllers/ClientPortal/EntityViewController.php b/app/Http/Controllers/ClientPortal/EntityViewController.php index 014faf172d7d..8060391fd8d1 100644 --- a/app/Http/Controllers/ClientPortal/EntityViewController.php +++ b/app/Http/Controllers/ClientPortal/EntityViewController.php @@ -45,10 +45,15 @@ class EntityViewController extends Controller $key = $entity_type.'_id'; - $invitation = $invitation_entity::whereRaw('BINARY `key`= ?', [$invitation_key]) + + $invitation = $invitation_entity::where('key', $invitation_key) ->with('contact.client') ->firstOrFail(); + // $invitation = $invitation_entity::whereRaw('BINARY `key`= ?', [$invitation_key]) + // ->with('contact.client') + // ->firstOrFail(); + $contact = $invitation->contact; $client = $contact->client; $entity = $invitation->{$entity_type}; @@ -105,7 +110,8 @@ class EntityViewController extends Controller $key = $entity_type.'_id'; - $invitation = $invitation_entity::whereRaw('BINARY `key`= ?', [$invitation_key])->firstOrFail(); + $invitation = $invitation_entity::where('key', $invitation_key)->firstOrFail(); + // $invitation = $invitation_entity::whereRaw('BINARY `key`= ?', [$invitation_key])->firstOrFail(); $contact = $invitation->contact; diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index c12a1dd9dd61..f8706897956d 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -181,10 +181,6 @@ class InvitationController extends Controller $entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation'; - // $invitation = $entity_obj::whereRaw('BINARY `key`= ?', [$invitation_key]) - // ->with('contact.client') - // ->firstOrFail(); - $invitation = $entity_obj::where('key', $invitation_key) ->with('contact.client') ->firstOrFail(); diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 220276dd784c..3f9b0079e908 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -114,7 +114,7 @@ class PaymentController extends Controller public function credit_response(Request $request) { - $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->first(); + $payment_hash = PaymentHash::where('hash', $request->input('payment_hash'))->first(); /* Hydrate the $payment */ if ($payment_hash->payment()->exists()) { diff --git a/app/Http/Middleware/ContactTokenAuth.php b/app/Http/Middleware/ContactTokenAuth.php index ff8b42e7fadb..c575d5d40109 100644 --- a/app/Http/Middleware/ContactTokenAuth.php +++ b/app/Http/Middleware/ContactTokenAuth.php @@ -29,7 +29,7 @@ class ContactTokenAuth */ public function handle($request, Closure $next) { - if ($request->header('X-API-TOKEN') && ($client_contact = ClientContact::with(['company'])->whereRaw('BINARY `token`= ?', [$request->header('X-API-TOKEN')])->first())) { + if ($request->header('X-API-TOKEN') && ($client_contact = ClientContact::with(['company'])->where('token', $request->header('X-API-TOKEN'))->first())) { $error = [ 'message' => 'Authentication disabled for user.', 'errors' => new stdClass, diff --git a/app/Http/Middleware/TokenAuth.php b/app/Http/Middleware/TokenAuth.php index fce88c82037d..c4122f731129 100644 --- a/app/Http/Middleware/TokenAuth.php +++ b/app/Http/Middleware/TokenAuth.php @@ -30,7 +30,7 @@ class TokenAuth */ public function handle($request, Closure $next) { - if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with(['user', 'company'])->whereRaw('BINARY `token`= ?', [$request->header('X-API-TOKEN')])->first())) { + if ($request->header('X-API-TOKEN') && ($company_token = CompanyToken::with(['user', 'company'])->where('token', $request->header('X-API-TOKEN'))->first())) { $user = $company_token->user; $error = [ diff --git a/app/Http/Requests/ClientPortal/Payments/PaymentResponseRequest.php b/app/Http/Requests/ClientPortal/Payments/PaymentResponseRequest.php index e9a9851a1839..fbfe24f90a4f 100644 --- a/app/Http/Requests/ClientPortal/Payments/PaymentResponseRequest.php +++ b/app/Http/Requests/ClientPortal/Payments/PaymentResponseRequest.php @@ -34,7 +34,7 @@ class PaymentResponseRequest extends FormRequest { $input = $this->all(); - return PaymentHash::whereRaw('BINARY `hash`= ?', [$input['payment_hash']])->first(); + return PaymentHash::where('hash', $input['payment_hash'])->first(); } public function shouldStoreToken(): bool diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 00a988d78b7f..7250e9f81fae 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -205,7 +205,7 @@ class MultiDB $current_db = config('database.default'); foreach (self::$dbs as $db) { - if (ClientContact::on($db)->whereRaw('BINARY `token`= ?', [$token])->exists()) { + if (ClientContact::on($db)->where('token', $token)->exists()) { self::setDb($db); return true; } @@ -257,7 +257,7 @@ class MultiDB $current_db = config('database.default'); foreach (self::$dbs as $db) { - if (CompanyToken::on($db)->whereRaw('BINARY `token`= ?', [$token])->exists()) { + if (CompanyToken::on($db)->where('token', $token)->exists()) { self::setDb($db); return true; } diff --git a/app/Models/User.php b/app/Models/User.php index 0960745a4d63..f9871a9f3191 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -177,7 +177,7 @@ class User extends Authenticatable implements MustVerifyEmail } elseif (request()->header('X-API-TOKEN')) { - $company_token = CompanyToken::with(['company'])->whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first(); + $company_token = CompanyToken::with(['company'])->where('token', request()->header('X-API-TOKEN'))->first(); return $company_token->company; } diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 612e1cf5649e..5579a22ed892 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -223,7 +223,7 @@ class AuthorizeCreditCard private function processSuccessfulResponse($data, $request) { - $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->firstOrFail(); + $payment_hash = PaymentHash::where('hash', $request->input('payment_hash'))->firstOrFail(); $payment = $this->storePayment($payment_hash, $data); $vars = [ diff --git a/app/PaymentDrivers/PayFastPaymentDriver.php b/app/PaymentDrivers/PayFastPaymentDriver.php index 8d3ab1e6d062..333ecb7ea465 100644 --- a/app/PaymentDrivers/PayFastPaymentDriver.php +++ b/app/PaymentDrivers/PayFastPaymentDriver.php @@ -224,7 +224,7 @@ class PayFastPaymentDriver extends BaseDriver default: - $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$data['m_payment_id']])->first(); + $payment_hash = PaymentHash::where('hash', $data['m_payment_id'])->first(); $this->setPaymentMethod(GatewayType::CREDIT_CARD) ->setPaymentHash($payment_hash) diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 6ae4bcae40fe..2cd20f1522b4 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -142,7 +142,7 @@ class BaseRepository $invitation_class = sprintf('App\\Models\\%sInvitation', $resource); - $invitation = $invitation_class::whereRaw('BINARY `key`= ?', [$invitation['key']])->first(); + $invitation = $invitation_class::where('key', $invitation['key'])->first(); return $invitation; } diff --git a/app/Repositories/CreditRepository.php b/app/Repositories/CreditRepository.php index f05e7ee3b0bc..d7f50ebda4d0 100644 --- a/app/Repositories/CreditRepository.php +++ b/app/Repositories/CreditRepository.php @@ -42,6 +42,6 @@ class CreditRepository extends BaseRepository public function getInvitationByKey($key) :?CreditInvitation { - return CreditInvitation::whereRaw('BINARY `key`= ?', [$key])->first(); + return CreditInvitation::where('key', $key)->first(); } } diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index fbf7d6e90428..fee83b5b594c 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -50,7 +50,7 @@ class InvoiceRepository extends BaseRepository public function getInvitationByKey($key) :?InvoiceInvitation { - return InvoiceInvitation::whereRaw('BINARY `key`= ?', [$key])->first(); + return InvoiceInvitation::where('key', $key)->first(); } /** diff --git a/app/Repositories/QuoteRepository.php b/app/Repositories/QuoteRepository.php index 3d336891cf53..069068dea3e7 100644 --- a/app/Repositories/QuoteRepository.php +++ b/app/Repositories/QuoteRepository.php @@ -26,6 +26,6 @@ class QuoteRepository extends BaseRepository public function getInvitationByKey($key) :?QuoteInvitation { - return QuoteInvitation::whereRaw('BINARY `key`= ?', [$key])->first(); + return QuoteInvitation::where('key', $key)->first(); } } diff --git a/app/Repositories/RecurringInvoiceRepository.php b/app/Repositories/RecurringInvoiceRepository.php index c58a4f9d4d33..62dfef0acd07 100644 --- a/app/Repositories/RecurringInvoiceRepository.php +++ b/app/Repositories/RecurringInvoiceRepository.php @@ -30,6 +30,6 @@ class RecurringInvoiceRepository extends BaseRepository public function getInvitationByKey($key) :?RecurringInvoiceInvitation { - return RecurringInvoiceInvitation::whereRaw('BINARY `key`= ?', [$key])->first(); + return RecurringInvoiceInvitation::where('key', $key)->first(); } } diff --git a/app/Transformers/UserTransformer.php b/app/Transformers/UserTransformer.php index 238db3a08a2e..d30725a553fb 100644 --- a/app/Transformers/UserTransformer.php +++ b/app/Transformers/UserTransformer.php @@ -96,7 +96,7 @@ class UserTransformer extends EntityTransformer public function includeCompanyUser(User $user) { if (!$user->company_id && request()->header('X-API-TOKEN')) { - $company_token = CompanyToken::whereRaw('BINARY `token`= ?', [request()->header('X-API-TOKEN')])->first(); + $company_token = CompanyToken::where('token', request()->header('X-API-TOKEN'))->first(); $user->company_id = $company_token->company_id; } diff --git a/app/Utils/PhantomJS/Phantom.php b/app/Utils/PhantomJS/Phantom.php index 1c6c4d05f36e..079ea78671b5 100644 --- a/app/Utils/PhantomJS/Phantom.php +++ b/app/Utils/PhantomJS/Phantom.php @@ -169,7 +169,7 @@ class Phantom $key = $entity.'_id'; $invitation_instance = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation'; - $invitation = $invitation_instance::whereRaw('BINARY `key`= ?', [$invitation_key])->first(); + $invitation = $invitation_instance::where('key', $invitation_key)->first(); $entity_obj = $invitation->{$entity}; diff --git a/config/ninja.php b/config/ninja.php index 5bbe097f9a7a..3106ed149025 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,8 +14,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => '5.3.61', - 'app_tag' => '5.3.61', + 'app_version' => '5.3.62', + 'app_tag' => '5.3.62', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), diff --git a/database/schema/db-ninja-01-schema.dump b/database/schema/db-ninja-01-schema.dump index a3ff1e7ba57a..2a9b312c852e 100644 --- a/database/schema/db-ninja-01-schema.dump +++ b/database/schema/db-ninja-01-schema.dump @@ -37,6 +37,10 @@ CREATE TABLE `accounts` ( `is_onboarding` tinyint(1) NOT NULL DEFAULT '0', `onboarding` mediumtext COLLATE utf8mb4_unicode_ci, `is_migrated` tinyint(1) NOT NULL DEFAULT '0', + `platform` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `hosted_client_count` int(10) unsigned DEFAULT NULL, + `hosted_company_count` int(10) unsigned DEFAULT NULL, + `inapp_transaction_id` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `accounts_payment_id_index` (`payment_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; @@ -385,6 +389,7 @@ CREATE TABLE `companies` ( `use_comma_as_decimal_place` tinyint(1) NOT NULL DEFAULT '0', `report_include_drafts` tinyint(1) NOT NULL DEFAULT '0', `client_registration_fields` mediumtext COLLATE utf8mb4_unicode_ci, + `convert_rate_to_client` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `companies_company_key_unique` (`company_key`), KEY `companies_industry_id_foreign` (`industry_id`), @@ -2116,3 +2121,12 @@ INSERT INTO `migrations` VALUES (113,'2021_11_08_131308_onboarding',6); INSERT INTO `migrations` VALUES (114,'2021_11_09_115919_update_designs',6); INSERT INTO `migrations` VALUES (115,'2021_11_10_184847_add_is_migrate_column_to_accounts_table',6); INSERT INTO `migrations` VALUES (116,'2021_11_11_163121_add_instant_bank_transfer',7); +INSERT INTO `migrations` VALUES (117,'2021_12_20_095542_add_serbian_language_translations',8); +INSERT INTO `migrations` VALUES (118,'2022_01_02_022421_add_slovak_language',8); +INSERT INTO `migrations` VALUES (119,'2022_01_06_061231_add_app_domain_id_to_gateways_table',8); +INSERT INTO `migrations` VALUES (120,'2022_01_18_004856_add_estonian_language',8); +INSERT INTO `migrations` VALUES (121,'2022_01_19_085907_add_platform_column_to_accounts_table',8); +INSERT INTO `migrations` VALUES (122,'2022_01_19_232436_add_kyd_currency',8); +INSERT INTO `migrations` VALUES (123,'2022_01_27_223617_add_client_count_to_accounts_table',8); +INSERT INTO `migrations` VALUES (124,'2022_02_06_091629_add_client_currency_conversion_to_companies_table',8); +INSERT INTO `migrations` VALUES (125,'2022_02_25_015411_update_stripe_apple_domain_config',9); diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index dd926406300f..a277b3126e4f 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -297,7 +297,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->service()->markSent()->save(); + $this->invoice->service()->markSent()->createInvitations()->save(); $data = [ 'amount' => 2.0, From a004a71218c05d89dfe050101725860206bd0681 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Feb 2022 23:08:57 +1100 Subject: [PATCH 2/3] refactor for missing invitation --- app/Mail/TemplateEmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 273d4b19749d..d18328c6537b 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -97,7 +97,7 @@ class TemplateEmail extends Mailable 'footer' => $this->build_email->getFooter(), 'whitelabel' => $this->client->user->account->isPaid() ? true : false, 'settings' => $settings, - 'unsubscribe_link' => $this->invitation->getUnsubscribeLink(), + 'unsubscribe_link' => $this->invitation ? $this->invitation->getUnsubscribeLink() : '', ]) ->view($template_name, [ 'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]), From c2b899c791a87926e41f8de3de34013ef682ac03 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Feb 2022 23:12:14 +1100 Subject: [PATCH 3/3] refactor for missing invitation --- tests/Feature/MultiPaymentDeleteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/MultiPaymentDeleteTest.php b/tests/Feature/MultiPaymentDeleteTest.php index c41a54b28fbc..f9d682668e28 100644 --- a/tests/Feature/MultiPaymentDeleteTest.php +++ b/tests/Feature/MultiPaymentDeleteTest.php @@ -121,7 +121,7 @@ class MultiPaymentDeleteTest extends TestCase $this->assertEquals(0, $invoice->balance); //mark sent - $invoice = $invoice->service()->markSent()->save(); + $invoice = $invoice->service()->markSent()->createInvitations()->save(); $invoice->fresh(); $invoice->client->fresh();