From 8119832291024e3625ff439a41475ec75b8bac87 Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Thu, 25 Aug 2022 12:03:49 +0600 Subject: [PATCH 1/7] fixed issue when using custom table for authentication instead of users table --- src/resources/config/shopify-app.php | 5 +++++ .../migrations/2020_01_29_230905_create_shops_table.php | 8 ++++---- .../migrations/2020_01_29_231006_create_charges_table.php | 7 ++++--- ...4_21_103633_add_password_updated_at_to_users_table.php | 5 +++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/resources/config/shopify-app.php b/src/resources/config/shopify-app.php index 13338313..804a71b9 100644 --- a/src/resources/config/shopify-app.php +++ b/src/resources/config/shopify-app.php @@ -470,5 +470,10 @@ * The table name for Plan model. */ 'plans' => 'plans', + + /* + * The table name for the Shop. + */ + 'shops' => 'users', ] ]; diff --git a/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php b/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php index d7414bc4..33e3bd2e 100644 --- a/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php +++ b/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php @@ -14,13 +14,13 @@ class CreateShopsTable extends Migration */ public function up(): void { - Schema::table('users', function (Blueprint $table) { + Schema::table(Util::getShopifyConfig('table_names.shops'), function (Blueprint $table) { $table->boolean('shopify_grandfathered')->default(false); $table->string('shopify_namespace')->nullable(true)->default(null); $table->boolean('shopify_freemium')->default(false); $table->integer('plan_id')->unsigned()->nullable(); - if (! Schema::hasColumn('users', 'deleted_at')) { + if (! Schema::hasColumn(Util::getShopifyConfig('table_names.shops'), 'deleted_at')) { $table->softDeletes(); } @@ -35,8 +35,8 @@ public function up(): void */ public function down(): void { - Schema::table('users', function (Blueprint $table) { - $table->dropForeign('users_plan_id_foreign'); + Schema::table(Util::getShopifyConfig('table_names.shops'), function (Blueprint $table) { + $table->dropForeign(Util::getShopifyConfig('table_names.shops') . '_plan_id_foreign'); $table->dropColumn([ 'shopify_grandfathered', 'shopify_namespace', diff --git a/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php b/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php index 5f63d9d5..c386a5ae 100644 --- a/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php +++ b/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php @@ -5,6 +5,7 @@ use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Schema; use Osiset\ShopifyApp\Util; +use Illuminate\Support\Str; class CreateChargesTable extends Migration { @@ -79,13 +80,13 @@ public function up() $table->softDeletes(); if ($this->getLaravelVersion() < 5.8) { - $table->integer('user_id')->unsigned(); + $table->integer(Str::singular(Util::getShopifyConfig('table_names.shops')) . '_id')->unsigned(); } else { - $table->bigInteger('user_id')->unsigned(); + $table->bigInteger(Str::singular(Util::getShopifyConfig('table_names.shops')) . '_id')->unsigned(); } // Linking - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign(Str::singular(Util::getShopifyConfig('table_names.shops')) . '_id')->references('id')->on(Util::getShopifyConfig('table_names.shops'))->onDelete('cascade'); $table->foreign('plan_id')->references('id')->on(Util::getShopifyConfig('table_names.plans', 'plans')); }); } diff --git a/src/resources/database/migrations/2021_04_21_103633_add_password_updated_at_to_users_table.php b/src/resources/database/migrations/2021_04_21_103633_add_password_updated_at_to_users_table.php index ab3ff59b..1b14746b 100644 --- a/src/resources/database/migrations/2021_04_21_103633_add_password_updated_at_to_users_table.php +++ b/src/resources/database/migrations/2021_04_21_103633_add_password_updated_at_to_users_table.php @@ -3,6 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; +use Osiset\ShopifyApp\Util; class AddPasswordUpdatedAtToUsersTable extends Migration { @@ -13,7 +14,7 @@ class AddPasswordUpdatedAtToUsersTable extends Migration */ public function up() { - Schema::table('users', function (Blueprint $table) { + Schema::table(Util::getShopifyConfig('table_names.shops'), function (Blueprint $table) { $table->date('password_updated_at')->nullable(); }); } @@ -25,7 +26,7 @@ public function up() */ public function down() { - Schema::table('users', function (Blueprint $table) { + Schema::table(Util::getShopifyConfig('table_names.shops'), function (Blueprint $table) { $table->dropColumn('password_updated_at'); }); } From e00b49eb6d4e48013301bbddc93536c6d4eabf31 Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Wed, 7 Sep 2022 11:46:50 +0600 Subject: [PATCH 2/7] fixed charges model saving when using custom shop table --- src/Storage/Commands/Charge.php | 8 ++++++-- src/Storage/Models/Charge.php | 16 ++++++++++++++-- src/Storage/Queries/Charge.php | 6 +++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Storage/Commands/Charge.php b/src/Storage/Commands/Charge.php index 05ca3c20..672020dc 100644 --- a/src/Storage/Commands/Charge.php +++ b/src/Storage/Commands/Charge.php @@ -3,6 +3,7 @@ namespace Osiset\ShopifyApp\Storage\Commands; use Illuminate\Support\Carbon; +use Illuminate\Support\Str; use Osiset\ShopifyApp\Contracts\Commands\Charge as ChargeCommand; use Osiset\ShopifyApp\Contracts\Queries\Charge as ChargeQuery; use Osiset\ShopifyApp\Objects\Enums\ChargeStatus; @@ -50,10 +51,12 @@ public function make(ChargeTransfer $chargeObj): ChargeId return $obj instanceof Carbon; }; + $userTableId = Str::singular(Util::getShopifyConfig('table_names.shops', 'users')) . '_id'; + $chargeClass = Util::getShopifyConfig('models.charge', ChargeModel::class); $charge = new $chargeClass(); $charge->plan_id = $chargeObj->planId->toNative(); - $charge->user_id = $chargeObj->shopId->toNative(); + $charge->$userTableId = $chargeObj->shopId->toNative(); $charge->charge_id = $chargeObj->chargeReference->toNative(); $charge->type = $chargeObj->chargeType->toNative(); $charge->status = $chargeObj->chargeStatus->toNative(); @@ -89,10 +92,11 @@ public function delete(ChargeReference $chargeRef, ShopId $shopId): bool */ public function makeUsage(UsageChargeTransfer $chargeObj): ChargeId { + $userTableId = Str::singular(Util::getShopifyConfig('table_names.shops', 'users')) . '_id'; // Create the charge $chargeClass = Util::getShopifyConfig('models.charge', ChargeModel::class); $charge = new $chargeClass(); - $charge->user_id = $chargeObj->shopId->toNative(); + $charge->$userTableId = $chargeObj->shopId->toNative(); $charge->charge_id = $chargeObj->chargeReference->toNative(); $charge->type = $chargeObj->chargeType->toNative(); $charge->status = $chargeObj->chargeStatus->toNative(); diff --git a/src/Storage/Models/Charge.php b/src/Storage/Models/Charge.php index f9e10828..fddcdd81 100644 --- a/src/Storage/Models/Charge.php +++ b/src/Storage/Models/Charge.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Support\Str; use Osiset\ShopifyApp\Objects\Enums\ChargeStatus; use Osiset\ShopifyApp\Objects\Enums\ChargeType; use Osiset\ShopifyApp\Objects\Values\ChargeId; @@ -18,6 +19,8 @@ class Charge extends Model { use SoftDeletes; + protected $userTableId = 'user_id'; + /** * The attributes that are mass assignable. * @@ -25,7 +28,6 @@ class Charge extends Model */ protected $fillable = [ 'type', - 'user_id', 'charge_id', 'plan_id', 'status', @@ -49,6 +51,16 @@ class Charge extends Model */ protected $dates = ['deleted_at']; + public function __construct(array $attributes = []) + { + $this->userTableId = Str::singular(Util::getShopifyConfig('table_names.shops', 'users')) . '_id'; + $this->fillable[] = $this->userTableId; + + parent::__construct($attributes); + + + } + /** * Get table name. * @@ -88,7 +100,7 @@ public function shop(): BelongsTo { return $this->belongsTo( Util::getShopifyConfig('user_model'), - 'user_id', + $this->userTableId, 'id' ); } diff --git a/src/Storage/Queries/Charge.php b/src/Storage/Queries/Charge.php index 41a6235f..f1013764 100644 --- a/src/Storage/Queries/Charge.php +++ b/src/Storage/Queries/Charge.php @@ -2,6 +2,7 @@ namespace Osiset\ShopifyApp\Storage\Queries; +use Illuminate\Support\Str; use Osiset\ShopifyApp\Contracts\Queries\Charge as IChargeQuery; use Osiset\ShopifyApp\Objects\Values\ChargeId; use Osiset\ShopifyApp\Objects\Values\ChargeReference; @@ -21,6 +22,8 @@ class Charge implements IChargeQuery */ protected $chargeModel; + protected $userTableId; + /** * Init for charge command. */ @@ -28,6 +31,7 @@ public function __construct() { $chargeClass = Util::getShopifyConfig('models.charge', ChargeModel::class); $this->chargeModel = new $chargeClass(); + $this->userTableId = Str::singular(Util::getShopifyConfig('table_names.shops', 'users')) . '_id'; } @@ -61,7 +65,7 @@ public function getByReferenceAndShopId(ChargeReference $chargeRef, ShopId $shop { return $this->chargeModel->query() ->where('charge_id', $chargeRef->toNative()) - ->where('user_id', $shopId->toNative()) + ->where($this->userTableId, $shopId->toNative()) ->get() ->first(); } From 7ab1e9a60c9e2dcf59d4b5c6cad2392a6eb5d0bc Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Thu, 8 Sep 2022 23:00:57 +0600 Subject: [PATCH 3/7] refactor code for reusing shops table name and its foreign id --- src/Storage/Commands/Charge.php | 9 ++++----- src/Storage/Models/Charge.php | 8 ++------ src/Storage/Queries/Charge.php | 6 +----- src/Util.php | 19 +++++++++++++++++++ .../2020_01_29_230905_create_shops_table.php | 8 ++++---- ...2020_01_29_231006_create_charges_table.php | 7 +++---- ...add_password_updated_at_to_users_table.php | 4 ++-- 7 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/Storage/Commands/Charge.php b/src/Storage/Commands/Charge.php index 672020dc..ee669903 100644 --- a/src/Storage/Commands/Charge.php +++ b/src/Storage/Commands/Charge.php @@ -3,7 +3,6 @@ namespace Osiset\ShopifyApp\Storage\Commands; use Illuminate\Support\Carbon; -use Illuminate\Support\Str; use Osiset\ShopifyApp\Contracts\Commands\Charge as ChargeCommand; use Osiset\ShopifyApp\Contracts\Queries\Charge as ChargeQuery; use Osiset\ShopifyApp\Objects\Enums\ChargeStatus; @@ -51,12 +50,12 @@ public function make(ChargeTransfer $chargeObj): ChargeId return $obj instanceof Carbon; }; - $userTableId = Str::singular(Util::getShopifyConfig('table_names.shops', 'users')) . '_id'; + $shopTableId = Util::getShopsTable(true); $chargeClass = Util::getShopifyConfig('models.charge', ChargeModel::class); $charge = new $chargeClass(); $charge->plan_id = $chargeObj->planId->toNative(); - $charge->$userTableId = $chargeObj->shopId->toNative(); + $charge->$shopTableId = $chargeObj->shopId->toNative(); $charge->charge_id = $chargeObj->chargeReference->toNative(); $charge->type = $chargeObj->chargeType->toNative(); $charge->status = $chargeObj->chargeStatus->toNative(); @@ -92,11 +91,11 @@ public function delete(ChargeReference $chargeRef, ShopId $shopId): bool */ public function makeUsage(UsageChargeTransfer $chargeObj): ChargeId { - $userTableId = Str::singular(Util::getShopifyConfig('table_names.shops', 'users')) . '_id'; + $shopTableId = Util::getShopsTable(true); // Create the charge $chargeClass = Util::getShopifyConfig('models.charge', ChargeModel::class); $charge = new $chargeClass(); - $charge->$userTableId = $chargeObj->shopId->toNative(); + $charge->$shopTableId = $chargeObj->shopId->toNative(); $charge->charge_id = $chargeObj->chargeReference->toNative(); $charge->type = $chargeObj->chargeType->toNative(); $charge->status = $chargeObj->chargeStatus->toNative(); diff --git a/src/Storage/Models/Charge.php b/src/Storage/Models/Charge.php index fddcdd81..440a1777 100644 --- a/src/Storage/Models/Charge.php +++ b/src/Storage/Models/Charge.php @@ -5,7 +5,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Support\Str; use Osiset\ShopifyApp\Objects\Enums\ChargeStatus; use Osiset\ShopifyApp\Objects\Enums\ChargeType; use Osiset\ShopifyApp\Objects\Values\ChargeId; @@ -19,8 +18,6 @@ class Charge extends Model { use SoftDeletes; - protected $userTableId = 'user_id'; - /** * The attributes that are mass assignable. * @@ -53,8 +50,7 @@ class Charge extends Model public function __construct(array $attributes = []) { - $this->userTableId = Str::singular(Util::getShopifyConfig('table_names.shops', 'users')) . '_id'; - $this->fillable[] = $this->userTableId; + $this->fillable[] = Util::getShopsTable(true); parent::__construct($attributes); @@ -100,7 +96,7 @@ public function shop(): BelongsTo { return $this->belongsTo( Util::getShopifyConfig('user_model'), - $this->userTableId, + Util::getShopsTable(true), 'id' ); } diff --git a/src/Storage/Queries/Charge.php b/src/Storage/Queries/Charge.php index f1013764..75613f46 100644 --- a/src/Storage/Queries/Charge.php +++ b/src/Storage/Queries/Charge.php @@ -2,7 +2,6 @@ namespace Osiset\ShopifyApp\Storage\Queries; -use Illuminate\Support\Str; use Osiset\ShopifyApp\Contracts\Queries\Charge as IChargeQuery; use Osiset\ShopifyApp\Objects\Values\ChargeId; use Osiset\ShopifyApp\Objects\Values\ChargeReference; @@ -22,8 +21,6 @@ class Charge implements IChargeQuery */ protected $chargeModel; - protected $userTableId; - /** * Init for charge command. */ @@ -31,7 +28,6 @@ public function __construct() { $chargeClass = Util::getShopifyConfig('models.charge', ChargeModel::class); $this->chargeModel = new $chargeClass(); - $this->userTableId = Str::singular(Util::getShopifyConfig('table_names.shops', 'users')) . '_id'; } @@ -65,7 +61,7 @@ public function getByReferenceAndShopId(ChargeReference $chargeRef, ShopId $shop { return $this->chargeModel->query() ->where('charge_id', $chargeRef->toNative()) - ->where($this->userTableId, $shopId->toNative()) + ->where(Util::getShopsTable(true), $shopId->toNative()) ->get() ->first(); } diff --git a/src/Util.php b/src/Util.php index ee88ebe3..240669a7 100644 --- a/src/Util.php +++ b/src/Util.php @@ -209,4 +209,23 @@ public static function getGraphQLWebhookTopic(string $topic): string ->upper() ->replaceMatches('/[^A-Z_]/', '_'); } + + + /** + * Get the table name / table foreign_id for shop + * + * @param bool $foreignId + * + * @return string + */ + public static function getShopsTable(bool $foreignId = false): string + { + $shopTable = Util::getShopifyConfig('table_names.shops') ?? 'users'; + + if ($foreignId) { + return Str::singular($shopTable) . '_id' ; + } + + return $shopTable; + } } diff --git a/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php b/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php index 33e3bd2e..cd7cc26b 100644 --- a/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php +++ b/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php @@ -14,13 +14,13 @@ class CreateShopsTable extends Migration */ public function up(): void { - Schema::table(Util::getShopifyConfig('table_names.shops'), function (Blueprint $table) { + Schema::table(Util::getShopsTable(), function (Blueprint $table) { $table->boolean('shopify_grandfathered')->default(false); $table->string('shopify_namespace')->nullable(true)->default(null); $table->boolean('shopify_freemium')->default(false); $table->integer('plan_id')->unsigned()->nullable(); - if (! Schema::hasColumn(Util::getShopifyConfig('table_names.shops'), 'deleted_at')) { + if (! Schema::hasColumn(Util::getShopsTable(), 'deleted_at')) { $table->softDeletes(); } @@ -35,8 +35,8 @@ public function up(): void */ public function down(): void { - Schema::table(Util::getShopifyConfig('table_names.shops'), function (Blueprint $table) { - $table->dropForeign(Util::getShopifyConfig('table_names.shops') . '_plan_id_foreign'); + Schema::table(Util::getShopsTable(), function (Blueprint $table) { + $table->dropForeign(Util::getShopsTable() . '_plan_id_foreign'); $table->dropColumn([ 'shopify_grandfathered', 'shopify_namespace', diff --git a/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php b/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php index c386a5ae..9f1b9128 100644 --- a/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php +++ b/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php @@ -5,7 +5,6 @@ use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Schema; use Osiset\ShopifyApp\Util; -use Illuminate\Support\Str; class CreateChargesTable extends Migration { @@ -80,13 +79,13 @@ public function up() $table->softDeletes(); if ($this->getLaravelVersion() < 5.8) { - $table->integer(Str::singular(Util::getShopifyConfig('table_names.shops')) . '_id')->unsigned(); + $table->integer(Util::getShopsTable(true))->unsigned(); } else { - $table->bigInteger(Str::singular(Util::getShopifyConfig('table_names.shops')) . '_id')->unsigned(); + $table->bigInteger(Util::getShopsTable(true))->unsigned(); } // Linking - $table->foreign(Str::singular(Util::getShopifyConfig('table_names.shops')) . '_id')->references('id')->on(Util::getShopifyConfig('table_names.shops'))->onDelete('cascade'); + $table->foreign(Util::getShopsTable(true))->references('id')->on(Util::getShopsTable())->onDelete('cascade'); $table->foreign('plan_id')->references('id')->on(Util::getShopifyConfig('table_names.plans', 'plans')); }); } diff --git a/src/resources/database/migrations/2021_04_21_103633_add_password_updated_at_to_users_table.php b/src/resources/database/migrations/2021_04_21_103633_add_password_updated_at_to_users_table.php index 1b14746b..21751b3c 100644 --- a/src/resources/database/migrations/2021_04_21_103633_add_password_updated_at_to_users_table.php +++ b/src/resources/database/migrations/2021_04_21_103633_add_password_updated_at_to_users_table.php @@ -14,7 +14,7 @@ class AddPasswordUpdatedAtToUsersTable extends Migration */ public function up() { - Schema::table(Util::getShopifyConfig('table_names.shops'), function (Blueprint $table) { + Schema::table(Util::getShopsTable(), function (Blueprint $table) { $table->date('password_updated_at')->nullable(); }); } @@ -26,7 +26,7 @@ public function up() */ public function down() { - Schema::table(Util::getShopifyConfig('table_names.shops'), function (Blueprint $table) { + Schema::table(Util::getShopsTable(), function (Blueprint $table) { $table->dropColumn('password_updated_at'); }); } From 54907b60c9e7b4efcd86575c733f48a86812c460 Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Fri, 9 Sep 2022 00:49:49 +0600 Subject: [PATCH 4/7] refactor getShopsTable() and added new method for getting shops table foreign key --- src/Storage/Commands/Charge.php | 4 ++-- src/Storage/Models/Charge.php | 4 ++-- src/Storage/Queries/Charge.php | 2 +- src/Util.php | 22 ++++++++++--------- ...2020_01_29_231006_create_charges_table.php | 6 ++--- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Storage/Commands/Charge.php b/src/Storage/Commands/Charge.php index ee669903..18c23a3f 100644 --- a/src/Storage/Commands/Charge.php +++ b/src/Storage/Commands/Charge.php @@ -50,7 +50,7 @@ public function make(ChargeTransfer $chargeObj): ChargeId return $obj instanceof Carbon; }; - $shopTableId = Util::getShopsTable(true); + $shopTableId = Util::getShopsTableForeignKey(); $chargeClass = Util::getShopifyConfig('models.charge', ChargeModel::class); $charge = new $chargeClass(); @@ -91,7 +91,7 @@ public function delete(ChargeReference $chargeRef, ShopId $shopId): bool */ public function makeUsage(UsageChargeTransfer $chargeObj): ChargeId { - $shopTableId = Util::getShopsTable(true); + $shopTableId = Util::getShopsTableForeignKey(); // Create the charge $chargeClass = Util::getShopifyConfig('models.charge', ChargeModel::class); $charge = new $chargeClass(); diff --git a/src/Storage/Models/Charge.php b/src/Storage/Models/Charge.php index 440a1777..d48c2e72 100644 --- a/src/Storage/Models/Charge.php +++ b/src/Storage/Models/Charge.php @@ -50,7 +50,7 @@ class Charge extends Model public function __construct(array $attributes = []) { - $this->fillable[] = Util::getShopsTable(true); + $this->fillable[] = Util::getShopsTableForeignKey(); parent::__construct($attributes); @@ -96,7 +96,7 @@ public function shop(): BelongsTo { return $this->belongsTo( Util::getShopifyConfig('user_model'), - Util::getShopsTable(true), + Util::getShopsTableForeignKey(), 'id' ); } diff --git a/src/Storage/Queries/Charge.php b/src/Storage/Queries/Charge.php index 75613f46..75ba4912 100644 --- a/src/Storage/Queries/Charge.php +++ b/src/Storage/Queries/Charge.php @@ -61,7 +61,7 @@ public function getByReferenceAndShopId(ChargeReference $chargeRef, ShopId $shop { return $this->chargeModel->query() ->where('charge_id', $chargeRef->toNative()) - ->where(Util::getShopsTable(true), $shopId->toNative()) + ->where(Util::getShopsTableForeignKey(), $shopId->toNative()) ->get() ->first(); } diff --git a/src/Util.php b/src/Util.php index 240669a7..5a966328 100644 --- a/src/Util.php +++ b/src/Util.php @@ -212,20 +212,22 @@ public static function getGraphQLWebhookTopic(string $topic): string /** - * Get the table name / table foreign_id for shop - * - * @param bool $foreignId + * Get the table name for shop * * @return string */ - public static function getShopsTable(bool $foreignId = false): string + public static function getShopsTable(): string { - $shopTable = Util::getShopifyConfig('table_names.shops') ?? 'users'; - - if ($foreignId) { - return Str::singular($shopTable) . '_id' ; - } + return Util::getShopifyConfig('table_names.shops') ?? 'users'; + } - return $shopTable; + /** + * Get the table foreign key for shop + * + * @return string + */ + public static function getShopsTableForeignKey(): string + { + return Str::singular(self::getShopsTable()) . '_id'; } } diff --git a/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php b/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php index 9f1b9128..74da5107 100644 --- a/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php +++ b/src/resources/database/migrations/2020_01_29_231006_create_charges_table.php @@ -79,13 +79,13 @@ public function up() $table->softDeletes(); if ($this->getLaravelVersion() < 5.8) { - $table->integer(Util::getShopsTable(true))->unsigned(); + $table->integer(Util::getShopsTableForeignKey())->unsigned(); } else { - $table->bigInteger(Util::getShopsTable(true))->unsigned(); + $table->bigInteger(Util::getShopsTableForeignKey())->unsigned(); } // Linking - $table->foreign(Util::getShopsTable(true))->references('id')->on(Util::getShopsTable())->onDelete('cascade'); + $table->foreign(Util::getShopsTableForeignKey())->references('id')->on(Util::getShopsTable())->onDelete('cascade'); $table->foreign('plan_id')->references('id')->on(Util::getShopifyConfig('table_names.plans', 'plans')); }); } From c099191c3155274bff07e3bac9751e0529fa1a80 Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Fri, 9 Sep 2022 18:52:06 +0600 Subject: [PATCH 5/7] Remove unwanted new line feom Charge model contractor --- src/Storage/Models/Charge.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Storage/Models/Charge.php b/src/Storage/Models/Charge.php index d48c2e72..4908608c 100644 --- a/src/Storage/Models/Charge.php +++ b/src/Storage/Models/Charge.php @@ -53,8 +53,6 @@ public function __construct(array $attributes = []) $this->fillable[] = Util::getShopsTableForeignKey(); parent::__construct($attributes); - - } /** From 41c87341caa20ef3d08ffaa8a2850928dd5ca31a Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Fri, 9 Sep 2022 20:17:51 +0600 Subject: [PATCH 6/7] auto fixes code style from php-cs-fixer --- src/Util.php | 4 ++-- .../migrations/2020_01_29_230905_create_shops_table.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Util.php b/src/Util.php index 5a966328..b468e0f4 100644 --- a/src/Util.php +++ b/src/Util.php @@ -218,7 +218,7 @@ public static function getGraphQLWebhookTopic(string $topic): string */ public static function getShopsTable(): string { - return Util::getShopifyConfig('table_names.shops') ?? 'users'; + return self::getShopifyConfig('table_names.shops') ?? 'users'; } /** @@ -228,6 +228,6 @@ public static function getShopsTable(): string */ public static function getShopsTableForeignKey(): string { - return Str::singular(self::getShopsTable()) . '_id'; + return Str::singular(self::getShopsTable()).'_id'; } } diff --git a/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php b/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php index cd7cc26b..c87f0b16 100644 --- a/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php +++ b/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php @@ -36,7 +36,7 @@ public function up(): void public function down(): void { Schema::table(Util::getShopsTable(), function (Blueprint $table) { - $table->dropForeign(Util::getShopsTable() . '_plan_id_foreign'); + $table->dropForeign(Util::getShopsTable().'_plan_id_foreign'); $table->dropColumn([ 'shopify_grandfathered', 'shopify_namespace', From 5ddf28b53031c1ac48979f7489bf18e19e1a810d Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Fri, 9 Sep 2022 21:42:37 +0600 Subject: [PATCH 7/7] added name, email and password in create shops table migration if its missing current shops table --- .../2020_01_29_230905_create_shops_table.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php b/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php index c87f0b16..05631fdc 100644 --- a/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php +++ b/src/resources/database/migrations/2020_01_29_230905_create_shops_table.php @@ -24,6 +24,18 @@ public function up(): void $table->softDeletes(); } + if (! Schema::hasColumn(Util::getShopsTable(), 'name')) { + $table->string('name')->nullable(); + } + + if (! Schema::hasColumn(Util::getShopsTable(), 'email')) { + $table->string('email')->nullable(); + } + + if (! Schema::hasColumn(Util::getShopsTable(), 'password')) { + $table->string('password', 100)->nullable(); + } + $table->foreign('plan_id')->references('id')->on(Util::getShopifyConfig('table_names.plans', 'plans')); }); } @@ -38,6 +50,9 @@ public function down(): void Schema::table(Util::getShopsTable(), function (Blueprint $table) { $table->dropForeign(Util::getShopsTable().'_plan_id_foreign'); $table->dropColumn([ + 'name', + 'email', + 'password', 'shopify_grandfathered', 'shopify_namespace', 'shopify_freemium',