From 345b2018b94d257c22a056fc8b2170837d95c0ce Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 17 Oct 2017 12:32:53 +0200 Subject: [PATCH] Update RoleExcludedCategories and related models --- Changelog | 1 + app/Models/Category.php | 5 +++++ app/Models/RoleExcludedCategory.php | 10 ++++++++++ app/Models/UserRole.php | 5 +++++ build/nntmux.xml | 4 ++-- nntmux/Users.php | 4 ++-- .../db/patches/mysql/0325~role_excluded_categories.sql | 3 +++ resources/db/schema/mysql-ddl.sql | 2 +- 8 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 resources/db/patches/mysql/0325~role_excluded_categories.sql diff --git a/Changelog b/Changelog index e9f4c250d..443aecb3f 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2017-10-17 DariusIII + * Chg: Update RoleExcludedCategories and related models * Fix: Fix sending of contact form when not logged in * Chg: Update composer.lock * Fix: Fix wrong template used for password reset diff --git a/app/Models/Category.php b/app/Models/Category.php index ac8934ea1..fc20df43b 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -40,4 +40,9 @@ class Category extends Model { return $this->belongsTo('App\Models\UserExcludedCategory', 'categories_id'); } + + public function roleExcludedCategory() + { + return $this->belongsTo('App\Models\RoleExcludedCategory', 'categories_id'); + } } diff --git a/app/Models/RoleExcludedCategory.php b/app/Models/RoleExcludedCategory.php index bc66b03d1..e7caeed62 100644 --- a/app/Models/RoleExcludedCategory.php +++ b/app/Models/RoleExcludedCategory.php @@ -9,4 +9,14 @@ class RoleExcludedCategory extends Model protected $dateFormat = false; protected $guarded = []; + + public function role() + { + return $this->belongsTo('App\Models\UserRole', 'user_roles_id'); + } + + public function category() + { + return $this->hasMany('App\Models\Category', 'categories_id'); + } } diff --git a/app/Models/UserRole.php b/app/Models/UserRole.php index 5175dc510..a65485d13 100644 --- a/app/Models/UserRole.php +++ b/app/Models/UserRole.php @@ -28,4 +28,9 @@ class UserRole extends Model { return $this->hasMany('App\Models\User', 'user_roles_id'); } + + public function roleExcludedCategory() + { + return $this->hasMany('App\Models\RoleExcludedCategory', 'user_roles_id'); + } } diff --git a/build/nntmux.xml b/build/nntmux.xml index 68e3c6d3f..2b96bb502 100755 --- a/build/nntmux.xml +++ b/build/nntmux.xml @@ -16,8 +16,8 @@ - 324 - 324 + 325 + 325 diff --git a/nntmux/Users.php b/nntmux/Users.php index 1227b5a96..609e8b02f 100755 --- a/nntmux/Users.php +++ b/nntmux/Users.php @@ -1019,7 +1019,7 @@ class Users $this->delRoleCategoryExclusions($role); if (count($catids) > 0) { foreach ($catids as $catid) { - $this->pdo->queryInsert(sprintf('INSERT INTO role_excluded_categories (role, categories_id, created_at) VALUES (%d, %d, now())', $role, $catid)); + RoleExcludedCategory::query()->insertGetId(['user_roles_id' => $role, 'categories_id' => $catid, 'created_at' => Carbon::now()]); } } } @@ -1029,7 +1029,7 @@ class Users */ public function delRoleCategoryExclusions($role): void { - $this->pdo->queryExec(sprintf('DELETE FROM role_excluded_categories WHERE role = %d', $role)); + RoleExcludedCategory::query()->where('user_roles_id', $role)->delete(); } /** diff --git a/resources/db/patches/mysql/0325~role_excluded_categories.sql b/resources/db/patches/mysql/0325~role_excluded_categories.sql new file mode 100644 index 000000000..e6127a1f9 --- /dev/null +++ b/resources/db/patches/mysql/0325~role_excluded_categories.sql @@ -0,0 +1,3 @@ +# Alter the role column, rename it to user_roles_id + +ALTER TABLE role_excluded_categories CHANGE role user_roles_id INT(11) NOT NULL; \ No newline at end of file diff --git a/resources/db/schema/mysql-ddl.sql b/resources/db/schema/mysql-ddl.sql index fdf841d2d..fe565deb9 100755 --- a/resources/db/schema/mysql-ddl.sql +++ b/resources/db/schema/mysql-ddl.sql @@ -1271,7 +1271,7 @@ DROP TABLE IF EXISTS role_excluded_categories; CREATE TABLE role_excluded_categories ( id INT(16) UNSIGNED NOT NULL AUTO_INCREMENT, - role INT(11) NOT NULL, + user_roles_id INT(11) NOT NULL, categories_id INT(11), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL,