From f9a096a6e6b579798f09e2773b33a06a95189a00 Mon Sep 17 00:00:00 2001 From: Keania Eric Date: Thu, 19 Oct 2023 18:04:17 +0100 Subject: [PATCH 1/6] configure permissions and roles table names --- config/twill.php | 2 ++ .../2020_04_20_000001_support_permission.php | 33 +++++++++++-------- src/Models/Permission.php | 6 ++++ src/Models/Role.php | 6 ++++ 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/config/twill.php b/config/twill.php index 26644077e..d66899fc7 100644 --- a/config/twill.php +++ b/config/twill.php @@ -143,6 +143,8 @@ 'tags_table' => 'twill_tags', 'users_oauth_table' => 'twill_users_oauth', 'users_table' => 'twill_users', + 'permissions_table' => 'permissions', + 'roles_table' => 'roles', /* |-------------------------------------------------------------------------- diff --git a/migrations/optional/permissions-management/2020_04_20_000001_support_permission.php b/migrations/optional/permissions-management/2020_04_20_000001_support_permission.php index 8faf8e869..bc4048a8e 100644 --- a/migrations/optional/permissions-management/2020_04_20_000001_support_permission.php +++ b/migrations/optional/permissions-management/2020_04_20_000001_support_permission.php @@ -16,15 +16,18 @@ class SupportPermission extends Migration */ public function up() { - if (!Schema::hasTable('permissions') + $permissionsTableName = config('twill.permissions_table', 'permissions'); + $rolesTableName = config('twill.roles_table', 'roles'); + + if (!Schema::hasTable($permissionsTableName) && !Schema::hasTable('groups') - && !Schema::hasTable('roles') + && !Schema::hasTable($rolesTableName) && !Schema::hasTable('permission_twill_user') && !Schema::hasTable('group_twill_user') && !Schema::hasTable('group_permission') && !Schema::hasTable('permission_role') ) { - Schema::create('permissions', function (Blueprint $table) { + Schema::create($permissionsTableName, function (Blueprint $table) { createDefaultTableFields($table); $table->string('name'); $table->string('display_name')->nullable(); @@ -40,14 +43,14 @@ public function up() $table->boolean('is_everyone_group')->default(false); }); - Schema::create('roles', function (Blueprint $table) { + Schema::create($rolesTableName, function (Blueprint $table) { createDefaultTableFields($table); $table->string('name', 255)->nullable(); $table->boolean('in_everyone_group')->default(true); $table->integer('position')->unsigned()->nullable(); }); - Schema::create('permission_twill_user', function (Blueprint $table) { + Schema::create('permission_twill_user', function (Blueprint $table) use($permissionsTableName) { $table->bigInteger('twill_user_id')->unsigned()->nullable(); $table->foreign('twill_user_id') ->references('id') @@ -57,7 +60,7 @@ public function up() $table->bigInteger('permission_id')->unsigned()->nullable(); $table->foreign('permission_id') ->references('id') - ->on('permissions') + ->on($permissionsTableName) ->onDelete('cascade'); }); @@ -77,11 +80,11 @@ public function up() $table->integer('position')->unsigned()->nullable(); }); - Schema::create('group_permission', function (Blueprint $table) { + Schema::create('group_permission', function (Blueprint $table) use($permissionsTableName) { $table->bigInteger('permission_id')->unsigned()->nullable(); $table->foreign('permission_id') ->references('id') - ->on('permissions') + ->on($permissionsTableName) ->onDelete('cascade'); $table->bigInteger('group_id')->unsigned()->nullable(); @@ -91,17 +94,17 @@ public function up() ->onDelete('cascade'); }); - Schema::create('permission_role', function (Blueprint $table) { + Schema::create('permission_role', function (Blueprint $table) use($permissionsTableName, $rolesTableName) { $table->bigInteger('permission_id')->unsigned()->nullable(); $table->foreign('permission_id') ->references('id') - ->on('permissions') + ->on($permissionsTableName) ->onDelete('cascade'); $table->bigInteger('role_id')->unsigned()->nullable(); $table->foreign('role_id') ->references('id') - ->on('roles') + ->on($rolesTableName) ->onDelete('cascade'); }); @@ -118,13 +121,17 @@ public function up() */ public function down() { + $permissionsTableName = config('twill.permissions_table', 'permissions'); + $rolesTableName = config('twill.roles_table', 'roles'); + + Schema::dropIfExists('permission_twill_user'); Schema::dropIfExists('group_twill_user'); Schema::dropIfExists('group_permission'); Schema::dropIfExists('permission_role'); - Schema::dropIfExists('permissions'); + Schema::dropIfExists($permissionsTableName); Schema::dropIfExists('groups'); - Schema::dropIfExists('roles'); + Schema::dropIfExists($rolesTableName); } private function seedBasicPermissions() diff --git a/src/Models/Permission.php b/src/Models/Permission.php index 9c34b6ea5..743a39142 100644 --- a/src/Models/Permission.php +++ b/src/Models/Permission.php @@ -42,6 +42,12 @@ class Permission extends BaseModel 'is_default', ]; + public function __construct(array $attributes = []) + { + $this->table = config('twill.permissions_table', 'permissions'); + parent::__construct($attributes); + } + protected $appends = ['permissionable_module']; /** diff --git a/src/Models/Role.php b/src/Models/Role.php index 343256eb4..a3fa1c715 100644 --- a/src/Models/Role.php +++ b/src/Models/Role.php @@ -38,6 +38,12 @@ class Role extends BaseModel implements Sortable, TwillModelContract 'deleted_at' => 'datetime' ]; + public function __construct(array $attributes = []) + { + $this->table = config('twill.roles_table', 'roles'); + parent::__construct($attributes); + } + public function scopeAccessible($query): Builder { $currentUser = auth('twill_users')->user(); From c97ef8da2db4675e4ed5e6b38d0e3cfe506c500f Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Thu, 2 Nov 2023 21:25:21 +0300 Subject: [PATCH 2/6] Fix artisan command --- docs/content/1_docs/4_form-fields/06_multi-select.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/1_docs/4_form-fields/06_multi-select.md b/docs/content/1_docs/4_form-fields/06_multi-select.md index ed61942f7..e71efe692 100644 --- a/docs/content/1_docs/4_form-fields/06_multi-select.md +++ b/docs/content/1_docs/4_form-fields/06_multi-select.md @@ -168,7 +168,7 @@ In this case that it can be implemented as follows: - Create a Sectors [module](../3_modules/2_cli-generator.md) ``` -php artisan twill:module sectors +php artisan twill:make:module sectors ``` - Create a migration for a pivot table. From 7bdba63093646e82cff2becb6750d88f158ef782 Mon Sep 17 00:00:00 2001 From: Roy de Vos Burchart Date: Fri, 3 Nov 2023 14:37:34 +0100 Subject: [PATCH 3/6] Always include `locale` in the mediables pivot --- src/Models/Behaviors/HasMedias.php | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Models/Behaviors/HasMedias.php b/src/Models/Behaviors/HasMedias.php index a3814e9df..685d14305 100644 --- a/src/Models/Behaviors/HasMedias.php +++ b/src/Models/Behaviors/HasMedias.php @@ -44,20 +44,18 @@ public function medias() Media::class, 'mediable', config('twill.mediables_table', 'twill_mediables') - )->withPivot( - array_merge([ - 'crop', - 'role', - 'crop_w', - 'crop_h', - 'crop_x', - 'crop_y', - 'lqip_data', - 'ratio', - 'metadatas', - ], config('twill.media_library.translated_form_fields', false) ? ['locale'] : []) - ) - ->withTimestamps()->orderBy(config('twill.mediables_table', 'twill_mediables') . '.id', 'asc'); + )->withPivot([ + 'crop', + 'role', + 'crop_w', + 'crop_h', + 'crop_x', + 'crop_y', + 'lqip_data', + 'ratio', + 'metadatas', + 'locale', + ])->withTimestamps()->orderBy(config('twill.mediables_table', 'twill_mediables') . '.id', 'asc'); } private function findMedia($role, $crop = 'default') From fa64cac62958ae6a16e2a076c8a0c360f091451c Mon Sep 17 00:00:00 2001 From: Cole Geissinger Date: Thu, 2 Nov 2023 19:12:11 -0700 Subject: [PATCH 4/6] [Docs] Fix typo in create page module --- .../1_page-builder-with-blade/4_creating-the-page-module.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/2_guides/1_page-builder-with-blade/4_creating-the-page-module.md b/docs/content/2_guides/1_page-builder-with-blade/4_creating-the-page-module.md index 22f5b8cde..e8616efde 100644 --- a/docs/content/2_guides/1_page-builder-with-blade/4_creating-the-page-module.md +++ b/docs/content/2_guides/1_page-builder-with-blade/4_creating-the-page-module.md @@ -1,6 +1,6 @@ # Creating the page module -Now that we area ready with the initial setup of Laravel and Twill we can start building our CMS. +Now that we are ready with the initial setup of Laravel and Twill we can start building our CMS. In Twill we use Modules. A module is a single "content type" and exists out of a few files: From 7bdccac1bdcb954fb79e4caa8ec24a5a9e2975df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:56:50 +0000 Subject: [PATCH 5/6] Bump @babel/traverse from 7.20.12 to 7.23.2 Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.20.12 to 7.23.2. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse) --- updated-dependencies: - dependency-name: "@babel/traverse" dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 252 +++++++++++++++++++++++----------------------- 1 file changed, 128 insertions(+), 124 deletions(-) diff --git a/package-lock.json b/package-lock.json index 81d0fbe97..e363dc73d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -113,12 +113,13 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz", - "integrity": "sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==", + "version": "7.22.13", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", + "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", "dev": true, "dependencies": { - "@babel/highlight": "^7.18.6" + "@babel/highlight": "^7.22.13", + "chalk": "^2.4.2" }, "engines": { "node": ">=6.9.0" @@ -182,13 +183,14 @@ } }, "node_modules/@babel/generator": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.20.7.tgz", - "integrity": "sha512-7wqMOJq8doJMZmP4ApXTzLxSr7+oO2jroJURrVEp6XShrQUObV8Tq/D0NCcoYg2uHqUrjzO0zwBjoYzelxK+sw==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", + "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", "dev": true, "dependencies": { - "@babel/types": "^7.20.7", + "@babel/types": "^7.23.0", "@jridgewell/gen-mapping": "^0.3.2", + "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" }, "engines": { @@ -309,9 +311,9 @@ } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.18.9", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.18.9.tgz", - "integrity": "sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", + "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", "dev": true, "engines": { "node": ">=6.9.0" @@ -330,25 +332,25 @@ } }, "node_modules/@babel/helper-function-name": { - "version": "7.19.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.19.0.tgz", - "integrity": "sha512-WAwHBINyrpqywkUH0nTnNgI5ina5TFn85HKS0pbPDfxFfhyR/aNQEn4hGi1P1JyT//I0t4OgXUlofzWILRvS5w==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", + "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", "dev": true, "dependencies": { - "@babel/template": "^7.18.10", - "@babel/types": "^7.19.0" + "@babel/template": "^7.22.15", + "@babel/types": "^7.23.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-hoist-variables": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz", - "integrity": "sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", + "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", "dev": true, "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" @@ -478,30 +480,30 @@ } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.18.6.tgz", - "integrity": "sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==", + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", "dev": true, "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.19.4", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz", - "integrity": "sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", + "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", "dev": true, "engines": { "node": ">=6.9.0" @@ -546,13 +548,13 @@ } }, "node_modules/@babel/highlight": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", - "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", + "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.18.6", - "chalk": "^2.0.0", + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", "js-tokens": "^4.0.0" }, "engines": { @@ -560,9 +562,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.7.tgz", - "integrity": "sha512-T3Z9oHybU+0vZlY9CiDSJQTD5ZapcW18ZctFMi0MOAl/4BjFF4ul7NVSARLdbGO5vDqy9eQiGTV0LtKfvCYvcg==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", + "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", "bin": { "parser": "bin/babel-parser.js" }, @@ -1737,33 +1739,33 @@ } }, "node_modules/@babel/template": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", - "integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", + "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7" + "@babel/code-frame": "^7.22.13", + "@babel/parser": "^7.22.15", + "@babel/types": "^7.22.15" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.20.12", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.20.12.tgz", - "integrity": "sha512-MsIbFN0u+raeja38qboyF8TIT7K0BFzz/Yd/77ta4MsUsmP2RAnidIlwq7d5HFQrH/OZJecGV6B71C4zAgpoSQ==", - "dev": true, - "dependencies": { - "@babel/code-frame": "^7.18.6", - "@babel/generator": "^7.20.7", - "@babel/helper-environment-visitor": "^7.18.9", - "@babel/helper-function-name": "^7.19.0", - "@babel/helper-hoist-variables": "^7.18.6", - "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", + "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", + "dev": true, + "dependencies": { + "@babel/code-frame": "^7.22.13", + "@babel/generator": "^7.23.0", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-hoist-variables": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/parser": "^7.23.0", + "@babel/types": "^7.23.0", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -1772,13 +1774,13 @@ } }, "node_modules/@babel/types": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.20.7.tgz", - "integrity": "sha512-69OnhBxSSgK0OzTJai4kyPDiKTIe3j+ctaHdIGVbRahTLAT7L3R9oeXHC2aVSuGYt3cVnoAMDmOCgJ2yaiLMvg==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", + "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.19.4", - "@babel/helper-validator-identifier": "^7.19.1", + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" }, "engines": { @@ -14151,12 +14153,13 @@ } }, "@babel/code-frame": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz", - "integrity": "sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==", + "version": "7.22.13", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", + "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", "dev": true, "requires": { - "@babel/highlight": "^7.18.6" + "@babel/highlight": "^7.22.13", + "chalk": "^2.4.2" } }, "@babel/compat-data": { @@ -14200,13 +14203,14 @@ } }, "@babel/generator": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.20.7.tgz", - "integrity": "sha512-7wqMOJq8doJMZmP4ApXTzLxSr7+oO2jroJURrVEp6XShrQUObV8Tq/D0NCcoYg2uHqUrjzO0zwBjoYzelxK+sw==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", + "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", "dev": true, "requires": { - "@babel/types": "^7.20.7", + "@babel/types": "^7.23.0", "@jridgewell/gen-mapping": "^0.3.2", + "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" }, "dependencies": { @@ -14296,9 +14300,9 @@ } }, "@babel/helper-environment-visitor": { - "version": "7.18.9", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.18.9.tgz", - "integrity": "sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", + "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", "dev": true }, "@babel/helper-explode-assignable-expression": { @@ -14311,22 +14315,22 @@ } }, "@babel/helper-function-name": { - "version": "7.19.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.19.0.tgz", - "integrity": "sha512-WAwHBINyrpqywkUH0nTnNgI5ina5TFn85HKS0pbPDfxFfhyR/aNQEn4hGi1P1JyT//I0t4OgXUlofzWILRvS5w==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", + "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", "dev": true, "requires": { - "@babel/template": "^7.18.10", - "@babel/types": "^7.19.0" + "@babel/template": "^7.22.15", + "@babel/types": "^7.23.0" } }, "@babel/helper-hoist-variables": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz", - "integrity": "sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", + "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", "dev": true, "requires": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" } }, "@babel/helper-member-expression-to-functions": { @@ -14423,24 +14427,24 @@ } }, "@babel/helper-split-export-declaration": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.18.6.tgz", - "integrity": "sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==", + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", "dev": true, "requires": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" } }, "@babel/helper-string-parser": { - "version": "7.19.4", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz", - "integrity": "sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", + "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", "dev": true }, "@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", "dev": true }, "@babel/helper-validator-option": { @@ -14473,20 +14477,20 @@ } }, "@babel/highlight": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", - "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", + "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", "dev": true, "requires": { - "@babel/helper-validator-identifier": "^7.18.6", - "chalk": "^2.0.0", + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", "js-tokens": "^4.0.0" } }, "@babel/parser": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.7.tgz", - "integrity": "sha512-T3Z9oHybU+0vZlY9CiDSJQTD5ZapcW18ZctFMi0MOAl/4BjFF4ul7NVSARLdbGO5vDqy9eQiGTV0LtKfvCYvcg==" + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", + "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==" }, "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": { "version": "7.18.6", @@ -15268,42 +15272,42 @@ } }, "@babel/template": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", - "integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", + "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", "dev": true, "requires": { - "@babel/code-frame": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7" + "@babel/code-frame": "^7.22.13", + "@babel/parser": "^7.22.15", + "@babel/types": "^7.22.15" } }, "@babel/traverse": { - "version": "7.20.12", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.20.12.tgz", - "integrity": "sha512-MsIbFN0u+raeja38qboyF8TIT7K0BFzz/Yd/77ta4MsUsmP2RAnidIlwq7d5HFQrH/OZJecGV6B71C4zAgpoSQ==", - "dev": true, - "requires": { - "@babel/code-frame": "^7.18.6", - "@babel/generator": "^7.20.7", - "@babel/helper-environment-visitor": "^7.18.9", - "@babel/helper-function-name": "^7.19.0", - "@babel/helper-hoist-variables": "^7.18.6", - "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", + "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.22.13", + "@babel/generator": "^7.23.0", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-hoist-variables": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/parser": "^7.23.0", + "@babel/types": "^7.23.0", "debug": "^4.1.0", "globals": "^11.1.0" } }, "@babel/types": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.20.7.tgz", - "integrity": "sha512-69OnhBxSSgK0OzTJai4kyPDiKTIe3j+ctaHdIGVbRahTLAT7L3R9oeXHC2aVSuGYt3cVnoAMDmOCgJ2yaiLMvg==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", + "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", "dev": true, "requires": { - "@babel/helper-string-parser": "^7.19.4", - "@babel/helper-validator-identifier": "^7.19.1", + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" } }, From f10733d4b05b51ee5774d93980173f3dff5f85f1 Mon Sep 17 00:00:00 2001 From: Roy de Vos Burchart Date: Fri, 3 Nov 2023 14:20:10 +0100 Subject: [PATCH 6/6] Fixes to reduce excessive number of queries --- src/Models/AppSetting.php | 13 +++++++++++++ src/Services/Settings/SettingsGroup.php | 11 +++++------ src/TwillAppSettings.php | 2 +- tests/integration/Settings/SettingsFacadeTest.php | 4 ++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Models/AppSetting.php b/src/Models/AppSetting.php index 91e8f324d..bb8a4c6d7 100644 --- a/src/Models/AppSetting.php +++ b/src/Models/AppSetting.php @@ -26,6 +26,19 @@ class AppSetting extends Model private bool $didRegisterSettingsBlocks = false; + public static function booted() + { + self::saving(function (self $model) { + /* + * Here we remove the 'blocks' relation so that any developer hooking + * into the saved event on the AppSetting can still fetch the settings + * with the new values. The next time the setting facade is called to + * retrieve a setting, the blocks relation is hydrated again. + */ + $model->unsetRelation('blocks'); + }); + } + /** * @return array|array */ diff --git a/src/Services/Settings/SettingsGroup.php b/src/Services/Settings/SettingsGroup.php index 63701a016..2707995b4 100644 --- a/src/Services/Settings/SettingsGroup.php +++ b/src/Services/Settings/SettingsGroup.php @@ -18,6 +18,8 @@ class SettingsGroup private ?Closure $availableWhen = null; + private AppSetting $appSetting; + public static function make(): self { return new self(); @@ -70,12 +72,9 @@ public function hasSection(string $sectionName): bool public function getSettingsModel(): AppSetting { - $settingsModel = AppSetting::where(['name' => $this->getName()])->first(); - if (!$settingsModel) { - $settingsModel = AppSetting::create(['name' => $this->getName()]); - } - - return $settingsModel; + return $this->appSetting ??= AppSetting::firstOrCreate([ + 'name' => $this->getName(), + ]); } /** diff --git a/src/TwillAppSettings.php b/src/TwillAppSettings.php index 32de3b73f..17efa6bef 100644 --- a/src/TwillAppSettings.php +++ b/src/TwillAppSettings.php @@ -105,7 +105,7 @@ public function getGroupDataForSectionAndName(string $group, string $section): B { $groupObject = $this->getGroupForGroupAndSectionName($group, $section); - return $groupObject->getSettingsModel()->blocks() + return $groupObject->getSettingsModel()->blocks ->where('editor_name', $section) ->where('parent_id', null) ->firstOrFail(); diff --git a/tests/integration/Settings/SettingsFacadeTest.php b/tests/integration/Settings/SettingsFacadeTest.php index 2e4ffb640..d677d1e7d 100644 --- a/tests/integration/Settings/SettingsFacadeTest.php +++ b/tests/integration/Settings/SettingsFacadeTest.php @@ -5,6 +5,7 @@ use A17\Twill\Exceptions\Settings\SettingsGroupDoesNotExistException; use A17\Twill\Exceptions\Settings\SettingsSectionDoesNotExistException; use A17\Twill\Facades\TwillAppSettings; +use A17\Twill\Models\AppSetting; use A17\Twill\Services\Settings\SettingsGroup; use A17\Twill\Tests\Integration\TestCase; @@ -66,6 +67,9 @@ public function setUp(): void ] ) ->assertStatus(200); + + /** @see AppSetting::booted() */ + $model->unsetRelation('blocks'); } public function testTranslatedSettingsGetter(): void