From d022b99727048d30f30497ab825a557335bc8bb4 Mon Sep 17 00:00:00 2001 From: Syed Ali Murtaza Date: Tue, 12 Oct 2021 11:09:30 +0500 Subject: [PATCH 1/8] Reformat code --- ...te_oauth_tables_primary_key_type_to_uuid.php | 6 +++--- ...ship_job_tables_primary_key_type_to_uuid.php | 2 +- Models/Client.php | 2 +- Models/PersonalAccessClient.php | 2 +- Providers/MainServiceProvider.php | 4 ++-- README.md | 17 ++++++++++++----- WARNING.md | 6 ++++-- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Data/Migrations/2020_04_11_065917_update_oauth_tables_primary_key_type_to_uuid.php b/Data/Migrations/2020_04_11_065917_update_oauth_tables_primary_key_type_to_uuid.php index 313b74e..4f13705 100644 --- a/Data/Migrations/2020_04_11_065917_update_oauth_tables_primary_key_type_to_uuid.php +++ b/Data/Migrations/2020_04_11_065917_update_oauth_tables_primary_key_type_to_uuid.php @@ -40,9 +40,9 @@ public function up() }); Schema::table('oauth_personal_access_clients', function (Blueprint $table) { - $table->uuid('id')->primary()->first(); - $table->uuid('client_id')->change(); - }); + $table->uuid('id')->primary()->first(); + $table->uuid('client_id')->change(); + }); } /** diff --git a/Data/Migrations/2020_07_05_095636_update_ship_job_tables_primary_key_type_to_uuid.php b/Data/Migrations/2020_07_05_095636_update_ship_job_tables_primary_key_type_to_uuid.php index 73cefe0..874fa96 100644 --- a/Data/Migrations/2020_07_05_095636_update_ship_job_tables_primary_key_type_to_uuid.php +++ b/Data/Migrations/2020_07_05_095636_update_ship_job_tables_primary_key_type_to_uuid.php @@ -11,7 +11,7 @@ class UpdateShipJobTablesPrimaryKeyTypeToUuid extends Migration */ public function up() { - if(Config::get('queue.default') == 'database'){ + if (Config::get('queue.default') == 'database') { // First drop `id` column, so they can be re-added with new type. Schema::table('jobs', function (Blueprint $table) { diff --git a/Models/Client.php b/Models/Client.php index bd6c37b..80581e5 100644 --- a/Models/Client.php +++ b/Models/Client.php @@ -1,4 +1,5 @@ [Larabeans](README.md) > Uuider +> [Larabeans](README.md) > Uuider --- @@ -18,29 +18,36 @@ --- ## Migrations + Contains new migrations to update core tables primary key type to uuid, which is incremental by default. --- ## Models + Adds new models. - Client - PersonalAccessClient -- User, Role and Permission models are used that are provided in core (beaner container). If you want to use your own models, write your own model and use HasUuid trait in your custom models. Or just extend existing models and add your custom functionality in those models. You also have to update core (beaner) config file models values to make this work for your custom models +- User, Role and Permission models are used that are provided in core (beaner container). If you want to use your own + models, write your own model and use HasUuid trait in your custom models. Or just extend existing models and add your + custom functionality in those models. You also have to update core (beaner) config file models values to make this + work for your custom models + --- ## Environment File + - Update env file user namespace as USER_NAMESPACE=App\Containers\Vendor\Beaner\Models\ -OR +OR -Create you own user model and use trait from core (beaner) container as +Create you own user model and use trait from core (beaner) container as ```phpt use HasUuid; ``` --- ->[Larabeans](README.md) > Uuider [⬆](#uuider) +> [Larabeans](README.md) > Uuider [⬆](#uuider) diff --git a/WARNING.md b/WARNING.md index b78d55c..8a923d6 100644 --- a/WARNING.md +++ b/WARNING.md @@ -1,5 +1,7 @@ THIS CONTAINER CAN ONLY BE USED WITH FRESH PROJECTS. DON'T USE WITH EXISTING PROJECTS OTHERWISE YOU CAN LOOSE YOUR DATA. -This container can only be installed at start of your project. +This container can only be installed at start of your project. -If you already started project with primary key type as auto increment (which is default) don't install this container. As this modifies database table columns typs by dropping existing primary column and adding new ones, which may result in loose of existing data. +If you already started project with primary key type as auto increment (which is default) don't install this container. +As this modifies database table columns typs by dropping existing primary column and adding new ones, which may result +in loose of existing data. From 70e203f111aef0d8aa1a7604cf9801aa8680f948 Mon Sep 17 00:00:00 2001 From: Syed Ali Murtaza Date: Tue, 14 Dec 2021 17:12:12 +0500 Subject: [PATCH 2/8] Moves HasUuid trait from core/beaner to Uuider container --- traits/HasUuid.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 traits/HasUuid.php diff --git a/traits/HasUuid.php b/traits/HasUuid.php new file mode 100644 index 0000000..949bc3b --- /dev/null +++ b/traits/HasUuid.php @@ -0,0 +1,39 @@ + + */ +trait HasUuid +{ + /** + * Boot function from laravel. + */ + protected static function bootHasUuid() + { + if (config('uuider.installed', false)) { + static::creating(function ($model) { + if (!$model->getIncrementing()) { + $model->keyType = 'string'; + $model->incrementing = false; + $model->{$model->getKeyName()} = $model->{$model->getKeyName()} ?: (string)Str::orderedUuid(); + } + }); + } + } + + public function getIncrementing() + { + return !config('uuider.installed', false); + } + + public function getKeyType() + { + return config('uuider.installed', false) ? 'string' : 'integer'; + } +} From aa7ac07bcf749ed6dfadd3ffa36f02c533a483bf Mon Sep 17 00:00:00 2001 From: Syed Ali Murtaza Date: Tue, 14 Dec 2021 17:19:47 +0500 Subject: [PATCH 3/8] Fixes error due to code refactoring --- Models/Client.php | 2 +- Models/PersonalAccessClient.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Models/Client.php b/Models/Client.php index 80581e5..79bc655 100644 --- a/Models/Client.php +++ b/Models/Client.php @@ -3,7 +3,7 @@ namespace App\Containers\Vendor\Uuider\Models; use Laravel\Passport\Client as OAuthClient; -use App\Containers\Vendor\Beaner\Traits\HasUuid; +use App\Containers\Vendor\Uuider\Traits\HasUuid; class Client extends OAuthClient { diff --git a/Models/PersonalAccessClient.php b/Models/PersonalAccessClient.php index eb69f44..dc3f5e1 100644 --- a/Models/PersonalAccessClient.php +++ b/Models/PersonalAccessClient.php @@ -3,7 +3,7 @@ namespace App\Containers\Vendor\Uuider\Models; use Laravel\Passport\PersonalAccessClient as OAuthPersonalAccessClient; -use App\Containers\Vendor\Beaner\Traits\HasUuid; +use App\Containers\Vendor\Uuider\Traits\HasUuid; class PersonalAccessClient extends OAuthPersonalAccessClient { From 08e0150a5ce8e841a577c7de7489e1077ce29493 Mon Sep 17 00:00:00 2001 From: Syed Ali Murtaza Date: Tue, 8 Feb 2022 13:40:06 +0500 Subject: [PATCH 4/8] Adds License --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..64e0b13 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Larabeans + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From d2e0b8953d635c963223637fc0f596d5c4e9237e Mon Sep 17 00:00:00 2001 From: Sajjad Naqvi Date: Thu, 2 Jun 2022 12:16:31 +0500 Subject: [PATCH 5/8] Updates container according to apiato11 --- Providers/MainServiceProvider.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Providers/MainServiceProvider.php b/Providers/MainServiceProvider.php index 09887f3..49cfa1d 100644 --- a/Providers/MainServiceProvider.php +++ b/Providers/MainServiceProvider.php @@ -2,16 +2,16 @@ namespace App\Containers\Vendor\Uuider\Providers; -use App\Ship\Parents\Providers\MainProvider; +use App\Ship\Parents\Providers\MainServiceProvider as ParentMainServiceProvider; use Laravel\Passport\Passport; -class MainServiceProvider extends MainProvider +class MainServiceProvider extends ParentMainServiceProvider { public function boot(): void { // To use customize passport models to replace primary key type from auto-increment to uuid. - Passport::useClientModel(config('uuider.models.client',\App\Containers\Vendor\Uuider\Models\Client::class)); - Passport::usePersonalAccessClientModel(config('uuider.models.personal_access_client',\App\Containers\Vendor\Uuider\Models\PersonalAccessClient::class)); + Passport::useClientModel(config('uuider.models.client', \App\Containers\Vendor\Uuider\Models\Client::class)); + Passport::usePersonalAccessClientModel(config('uuider.models.personal_access_client', \App\Containers\Vendor\Uuider\Models\PersonalAccessClient::class)); } public function register(): void From d81eabb2eb52ad2bd19cfc8aeab69e5e1f461094 Mon Sep 17 00:00:00 2001 From: Syed Ali Murtaza Date: Sat, 16 Jul 2022 18:11:47 +0500 Subject: [PATCH 6/8] Refactors container to larabeans section --- Configs/uuider.php | 4 ++-- Models/Client.php | 4 ++-- Models/PersonalAccessClient.php | 4 ++-- Providers/MainServiceProvider.php | 10 +++++----- README.md | 2 +- composer.json | 3 ++- traits/HasUuid.php | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Configs/uuider.php b/Configs/uuider.php index f528337..da4dcfc 100644 --- a/Configs/uuider.php +++ b/Configs/uuider.php @@ -6,9 +6,9 @@ 'models' => [ - 'client' => \App\Containers\Vendor\Uuider\Models\Client::class, + 'client' => \App\Containers\Larabeans\Uuider\Models\Client::class, - 'personal_access_client' => \App\Containers\Vendor\Uuider\Models\PersonalAccessClient::class, + 'personal_access_client' => \App\Containers\Larabeans\Uuider\Models\PersonalAccessClient::class, ], // Containers to skip primary key type conversion from auto-increment to uuid diff --git a/Models/Client.php b/Models/Client.php index 79bc655..e15b921 100644 --- a/Models/Client.php +++ b/Models/Client.php @@ -1,9 +1,9 @@ config('beaner.models.permission', \App\Containers\Vendor\Beaner\Models\Permission::class)]); - config(['permission.models.role' => config('beaner.models.role', \App\Containers\Vendor\Beaner\Models\Role::class)]); + config(['permission.models.permission' => config('beaner.models.permission', \App\Containers\Larabeans\Beaner\Models\Permission::class)]); + config(['permission.models.role' => config('beaner.models.role', \App\Containers\Larabeans\Beaner\Models\Role::class)]); } } diff --git a/README.md b/README.md index b439b39..f95ec3b 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Adds new models. ## Environment File -- Update env file user namespace as USER_NAMESPACE=App\Containers\Vendor\Beaner\Models\ +- Update env file user namespace as USER_NAMESPACE=App\Containers\Larabeans\Beaner\Models\ OR diff --git a/composer.json b/composer.json index faa1ba4..1b692d3 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "larabeans/uuider", "description": "Apiato container to replace primary key type from auto-increment to uuid.", - "type": "apiato-container", + "type": "larabeans-container", "homepage": "https://larabeans.com/", "version": "0.1.0", "support": { @@ -29,6 +29,7 @@ "extra": { "apiato": { "container": { + "section": "Larabeans", "name": "Uuider" } } diff --git a/traits/HasUuid.php b/traits/HasUuid.php index 949bc3b..e57e3ec 100644 --- a/traits/HasUuid.php +++ b/traits/HasUuid.php @@ -1,6 +1,6 @@ Date: Sat, 16 Jul 2022 18:17:09 +0500 Subject: [PATCH 7/8] Fixes as per psr-4 standard --- {traits => Traits}/HasUuid.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {traits => Traits}/HasUuid.php (100%) diff --git a/traits/HasUuid.php b/Traits/HasUuid.php similarity index 100% rename from traits/HasUuid.php rename to Traits/HasUuid.php From 5a65074394e4339d1d09e5f2f9f0837222371f82 Mon Sep 17 00:00:00 2001 From: Syed Ali Murtaza Date: Sat, 16 Jul 2022 18:21:07 +0500 Subject: [PATCH 8/8] Refactors Beaner to Core --- Providers/MainServiceProvider.php | 4 ++-- README.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Providers/MainServiceProvider.php b/Providers/MainServiceProvider.php index 3370b68..8e16e27 100644 --- a/Providers/MainServiceProvider.php +++ b/Providers/MainServiceProvider.php @@ -18,8 +18,8 @@ public function register(): void { // Over-write permission configuration on run time to // update role and permissions models - config(['permission.models.permission' => config('beaner.models.permission', \App\Containers\Larabeans\Beaner\Models\Permission::class)]); - config(['permission.models.role' => config('beaner.models.role', \App\Containers\Larabeans\Beaner\Models\Role::class)]); + config(['permission.models.permission' => config('core.models.permission', \App\Containers\Larabeans\Core\Models\Permission::class)]); + config(['permission.models.role' => config('core.models.role', \App\Containers\Larabeans\Core\Models\Role::class)]); } } diff --git a/README.md b/README.md index f95ec3b..ce649cc 100644 --- a/README.md +++ b/README.md @@ -30,20 +30,20 @@ Adds new models. - Client - PersonalAccessClient -- User, Role and Permission models are used that are provided in core (beaner container). If you want to use your own +- User, Role and Permission models are used that are provided in core container. If you want to use your own models, write your own model and use HasUuid trait in your custom models. Or just extend existing models and add your - custom functionality in those models. You also have to update core (beaner) config file models values to make this + custom functionality in those models. You also have to update core config file models values to make this work for your custom models --- ## Environment File -- Update env file user namespace as USER_NAMESPACE=App\Containers\Larabeans\Beaner\Models\ +- Update env file user namespace as USER_NAMESPACE=App\Containers\Larabeans\Core\Models\ OR -Create you own user model and use trait from core (beaner) container as +Create you own user model and use trait from core container as ```phpt use HasUuid;