mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-22 12:40:54 -04:00
refactor queries
This commit is contained in:
parent
f89bb1c1af
commit
83692ed618
@ -1 +1 @@
|
|||||||
5.3.61
|
5.3.62
|
@ -310,7 +310,7 @@ class LoginController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function refresh(Request $request)
|
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()
|
$cu = CompanyUser::query()
|
||||||
->where('user_id', $company_token->user_id);
|
->where('user_id', $company_token->user_id);
|
||||||
|
@ -45,10 +45,15 @@ class EntityViewController extends Controller
|
|||||||
|
|
||||||
$key = $entity_type.'_id';
|
$key = $entity_type.'_id';
|
||||||
|
|
||||||
$invitation = $invitation_entity::whereRaw('BINARY `key`= ?', [$invitation_key])
|
|
||||||
|
$invitation = $invitation_entity::where('key', $invitation_key)
|
||||||
->with('contact.client')
|
->with('contact.client')
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
|
// $invitation = $invitation_entity::whereRaw('BINARY `key`= ?', [$invitation_key])
|
||||||
|
// ->with('contact.client')
|
||||||
|
// ->firstOrFail();
|
||||||
|
|
||||||
$contact = $invitation->contact;
|
$contact = $invitation->contact;
|
||||||
$client = $contact->client;
|
$client = $contact->client;
|
||||||
$entity = $invitation->{$entity_type};
|
$entity = $invitation->{$entity_type};
|
||||||
@ -105,7 +110,8 @@ class EntityViewController extends Controller
|
|||||||
|
|
||||||
$key = $entity_type.'_id';
|
$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;
|
$contact = $invitation->contact;
|
||||||
|
|
||||||
|
@ -181,10 +181,6 @@ class InvitationController extends Controller
|
|||||||
|
|
||||||
$entity_obj = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation';
|
$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)
|
$invitation = $entity_obj::where('key', $invitation_key)
|
||||||
->with('contact.client')
|
->with('contact.client')
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
@ -114,7 +114,7 @@ class PaymentController extends Controller
|
|||||||
public function credit_response(Request $request)
|
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 */
|
/* Hydrate the $payment */
|
||||||
if ($payment_hash->payment()->exists()) {
|
if ($payment_hash->payment()->exists()) {
|
||||||
|
@ -29,7 +29,7 @@ class ContactTokenAuth
|
|||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
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 = [
|
$error = [
|
||||||
'message' => 'Authentication disabled for user.',
|
'message' => 'Authentication disabled for user.',
|
||||||
'errors' => new stdClass,
|
'errors' => new stdClass,
|
||||||
|
@ -30,7 +30,7 @@ class TokenAuth
|
|||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
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;
|
$user = $company_token->user;
|
||||||
|
|
||||||
$error = [
|
$error = [
|
||||||
|
@ -34,7 +34,7 @@ class PaymentResponseRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
$input = $this->all();
|
$input = $this->all();
|
||||||
|
|
||||||
return PaymentHash::whereRaw('BINARY `hash`= ?', [$input['payment_hash']])->first();
|
return PaymentHash::where('hash', $input['payment_hash'])->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shouldStoreToken(): bool
|
public function shouldStoreToken(): bool
|
||||||
|
@ -205,7 +205,7 @@ class MultiDB
|
|||||||
$current_db = config('database.default');
|
$current_db = config('database.default');
|
||||||
|
|
||||||
foreach (self::$dbs as $db) {
|
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);
|
self::setDb($db);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ class MultiDB
|
|||||||
$current_db = config('database.default');
|
$current_db = config('database.default');
|
||||||
|
|
||||||
foreach (self::$dbs as $db) {
|
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);
|
self::setDb($db);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
|
|
||||||
}
|
}
|
||||||
elseif (request()->header('X-API-TOKEN')) {
|
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;
|
return $company_token->company;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ class AuthorizeCreditCard
|
|||||||
|
|
||||||
private function processSuccessfulResponse($data, $request)
|
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);
|
$payment = $this->storePayment($payment_hash, $data);
|
||||||
|
|
||||||
$vars = [
|
$vars = [
|
||||||
|
@ -224,7 +224,7 @@ class PayFastPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
default:
|
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)
|
$this->setPaymentMethod(GatewayType::CREDIT_CARD)
|
||||||
->setPaymentHash($payment_hash)
|
->setPaymentHash($payment_hash)
|
||||||
|
@ -142,7 +142,7 @@ class BaseRepository
|
|||||||
|
|
||||||
$invitation_class = sprintf('App\\Models\\%sInvitation', $resource);
|
$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;
|
return $invitation;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,6 @@ class CreditRepository extends BaseRepository
|
|||||||
|
|
||||||
public function getInvitationByKey($key) :?CreditInvitation
|
public function getInvitationByKey($key) :?CreditInvitation
|
||||||
{
|
{
|
||||||
return CreditInvitation::whereRaw('BINARY `key`= ?', [$key])->first();
|
return CreditInvitation::where('key', $key)->first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class InvoiceRepository extends BaseRepository
|
|||||||
|
|
||||||
public function getInvitationByKey($key) :?InvoiceInvitation
|
public function getInvitationByKey($key) :?InvoiceInvitation
|
||||||
{
|
{
|
||||||
return InvoiceInvitation::whereRaw('BINARY `key`= ?', [$key])->first();
|
return InvoiceInvitation::where('key', $key)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,6 +26,6 @@ class QuoteRepository extends BaseRepository
|
|||||||
|
|
||||||
public function getInvitationByKey($key) :?QuoteInvitation
|
public function getInvitationByKey($key) :?QuoteInvitation
|
||||||
{
|
{
|
||||||
return QuoteInvitation::whereRaw('BINARY `key`= ?', [$key])->first();
|
return QuoteInvitation::where('key', $key)->first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,6 @@ class RecurringInvoiceRepository extends BaseRepository
|
|||||||
|
|
||||||
public function getInvitationByKey($key) :?RecurringInvoiceInvitation
|
public function getInvitationByKey($key) :?RecurringInvoiceInvitation
|
||||||
{
|
{
|
||||||
return RecurringInvoiceInvitation::whereRaw('BINARY `key`= ?', [$key])->first();
|
return RecurringInvoiceInvitation::where('key', $key)->first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ class UserTransformer extends EntityTransformer
|
|||||||
public function includeCompanyUser(User $user)
|
public function includeCompanyUser(User $user)
|
||||||
{
|
{
|
||||||
if (!$user->company_id && request()->header('X-API-TOKEN')) {
|
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;
|
$user->company_id = $company_token->company_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ class Phantom
|
|||||||
$key = $entity.'_id';
|
$key = $entity.'_id';
|
||||||
|
|
||||||
$invitation_instance = 'App\Models\\'.ucfirst(Str::camel($entity)).'Invitation';
|
$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};
|
$entity_obj = $invitation->{$entity};
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ return [
|
|||||||
'require_https' => env('REQUIRE_HTTPS', true),
|
'require_https' => env('REQUIRE_HTTPS', true),
|
||||||
'app_url' => rtrim(env('APP_URL', ''), '/'),
|
'app_url' => rtrim(env('APP_URL', ''), '/'),
|
||||||
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
|
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
|
||||||
'app_version' => '5.3.61',
|
'app_version' => '5.3.62',
|
||||||
'app_tag' => '5.3.61',
|
'app_tag' => '5.3.62',
|
||||||
'minimum_client_version' => '5.0.16',
|
'minimum_client_version' => '5.0.16',
|
||||||
'terms_version' => '1.0.1',
|
'terms_version' => '1.0.1',
|
||||||
'api_secret' => env('API_SECRET', ''),
|
'api_secret' => env('API_SECRET', ''),
|
||||||
|
@ -37,6 +37,10 @@ CREATE TABLE `accounts` (
|
|||||||
`is_onboarding` tinyint(1) NOT NULL DEFAULT '0',
|
`is_onboarding` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
`onboarding` mediumtext COLLATE utf8mb4_unicode_ci,
|
`onboarding` mediumtext COLLATE utf8mb4_unicode_ci,
|
||||||
`is_migrated` tinyint(1) NOT NULL DEFAULT '0',
|
`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`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `accounts_payment_id_index` (`payment_id`)
|
KEY `accounts_payment_id_index` (`payment_id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
|
) 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',
|
`use_comma_as_decimal_place` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
`report_include_drafts` tinyint(1) NOT NULL DEFAULT '0',
|
`report_include_drafts` tinyint(1) NOT NULL DEFAULT '0',
|
||||||
`client_registration_fields` mediumtext COLLATE utf8mb4_unicode_ci,
|
`client_registration_fields` mediumtext COLLATE utf8mb4_unicode_ci,
|
||||||
|
`convert_rate_to_client` tinyint(1) NOT NULL DEFAULT '1',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `companies_company_key_unique` (`company_key`),
|
UNIQUE KEY `companies_company_key_unique` (`company_key`),
|
||||||
KEY `companies_industry_id_foreign` (`industry_id`),
|
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 (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 (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 (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);
|
||||||
|
@ -297,7 +297,7 @@ class PaymentTest extends TestCase
|
|||||||
|
|
||||||
$this->invoice = $this->invoice_calc->getInvoice();
|
$this->invoice = $this->invoice_calc->getInvoice();
|
||||||
$this->invoice->save();
|
$this->invoice->save();
|
||||||
$this->invoice->service()->markSent()->save();
|
$this->invoice->service()->markSent()->createInvitations()->save();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'amount' => 2.0,
|
'amount' => 2.0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user