-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkp/pkp-lib#10506 Refactor UserGroup to use Eloquent #10519
base: main
Are you sure you want to change the base?
pkp/pkp-lib#10506 Refactor UserGroup to use Eloquent #10519
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've left a couple of comments but overall it looks good!
* Retrieve a keyed Collection (key = user_group_id, value = count) with the amount of active users for each UserGroup. | ||
* | ||
* @param int|null $contextId | ||
* @return Collection | ||
*/ | ||
public function getUserCountByContextId(?int $contextId = null): Collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to the Model as a scope?
classes/userGroup/Repository.php
Outdated
* | ||
* @param array $params | ||
* @return UserGroup | ||
*/ | ||
public function newDataObject(array $params = []): UserGroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that we need this method
classes/userGroup/Repository.php
Outdated
self::forgetEditorialHistoryCache($userGroup->context_id); | ||
} | ||
|
||
$userGroup->delete(); | ||
|
||
Hook::call('UserGroup::delete', [$userGroup]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rely on the Model's events here. But this needs to be added to the list of the removed hooks, the same as for Announcements
classes/core/SettingsBuilder.php
Outdated
@@ -110,6 +111,10 @@ public function insertGetId(array $values, $sequence = null) | |||
$settingValues->each(function (mixed $settingValue, string $settingName) use ($id, &$rows) { | |||
$settingName = Str::camel($settingName); | |||
if ($this->isMultilingual($settingName)) { | |||
// if non-localized data passed, set the locale to default one | |||
if (is_string($settingValue)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it makes the code better. @jonasraoni, do you have an opinion whether we should allow to set multilingual value by the default locale?
* @param int $id | ||
* @param int|null $contextId | ||
* @return UserGroup|null | ||
*/ | ||
public function get(int $id, ?int $contextId = null): ?UserGroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move some of the logic from Repository to the Model. In particular, methods that are associated with basic operations with the entity, like this one
classes/userGroup/UserGroup.php
Outdated
*/ | ||
public function getContextId(): ?int | ||
public function setAttribute($key, $value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to override setAttribute() here in order to allow to set multilingual values as usual strings. It's better to think about general solution
*/ | ||
public function setDefault($isDefault) | ||
public function stageAssignments(): HasMany |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add the relationship to the StageAssignment? And the same for the UserUserGroup
classes/userGroup/Repository.php
Outdated
return collect($item)->unique(); | ||
}); | ||
return $userIdsByUserGroupId->toArray(); | ||
$users = UserUserGroup::query() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it work without query()
method applied?
$cacheKeyPrefix = 'PKP\userGroup\Repository::getMastheadUserIdsByRoleIds'; | ||
$cacheKeys = [ | ||
"{$cacheKeyPrefix}EditorialMasthead{$contextId}" . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME, | ||
"{$cacheKeyPrefix}EditorialHistory{$contextId}" . self::MAX_EDITORIAL_MASTHEAD_CACHE_LIFETIME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this method also clear cache for the Editorial History?
classes/userGroup/Repository.php
Outdated
@@ -34,6 +34,7 @@ | |||
use PKP\userGroup\relationships\UserUserGroup; | |||
use PKP\validation\ValidatorFactory; | |||
use PKP\xml\PKPXMLParser; | |||
use Illuminate\Database\Query\Builder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several use
statements aren't used anymore.
No description provided.