-
Notifications
You must be signed in to change notification settings - Fork 447
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#10292 Controlled Vocab DAO to Eloquent Model #10324
base: main
Are you sure you want to change the base?
Conversation
5cefa04
to
4845517
Compare
public function scopeGetLocaleFieldNames(Builder $query): array | ||
{ | ||
return ['submissionAgency']; | ||
} |
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 these methods have any use (here is other similar class to get the locale field name)
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 added some early review comments!
35ed0cb
to
4c2b857
Compare
d68630a
to
3e91b7a
Compare
fn ($query) => $query->withSymbolic($symbolic)->withAssoc($assocType, $assocId) | ||
) | ||
->withLocale($locale) | ||
->withSetting($symbolic, $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.
here previously setting name passed as name
but is that correct as for controlled vocabs we have specific settings ?
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.
Per my comment above -- setting names and controlled vocab symbolic names are different things, and I think this PR mixes them accidentally.
classes/migration/upgrade/v3_5_0/I10292_RemoveControlledVocabEntrySettingType.php
Show resolved
Hide resolved
return $controlledVocabDao->enumerate($this->getId(), $settingName); | ||
} | ||
} | ||
public function enumerate(?string $settingName = null): array |
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.
Here $settingName
previously have default value to name
but that seems not right as for controlled vocab, we have a specific sets to settings only . Or I am missing something ?
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.
The setting name (the setting_name
column in a _settings
table) is not the same as the controlled vocab symbolic name, which is the symbolic
column in controlled_vocabs
. Be careful to keep the two distinct.
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.
@touhidurabir, I think this comment still applies; you're mixing the symbolic name of the controlled vocabulary with the setting name, and they're different things.
classes/user/interest/Repository.php
Outdated
'controlledVocabEntryId' => $interestId, | ||
])); | ||
|
||
Repo::controlledVocab()->resequence($controlledVocab->id); |
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.
do we need to resequence the vocabs for user interest, don't see any benefit or usage of it ?
$assocId = (DB::table("publications") | ||
->select("publication_id as id") | ||
->orderBy("publication_id", "desc") | ||
->first() | ||
->id ?? 0) + 100; |
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.
rather than setting a fixed value like 333
, it's better to build one based on what we have in DB and add a const value (like here 100
) to just to be safe .
$testControlledVocab = Repo::controlledVocab()->build( | ||
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, | ||
Application::ASSOC_TYPE_CITATION, | ||
$assocId | ||
); | ||
|
||
// Mock the ControlledVocabDAO | ||
$mockControlledVocabDao = $this->getMockBuilder(ControlledVocabDAO::class) | ||
->onlyMethods(['getBySymbolic']) | ||
->getMock(); | ||
$controlledVocabEntryId1 = ControlledVocabEntry::create([ | ||
'controlledVocabId' => $testControlledVocab->id, | ||
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD => [ | ||
'en' => 'testEntry', | ||
], | ||
])->id; | ||
|
||
// Set up the mock getBySymbolic() method | ||
$mockControlledVocabDao->expects($this->any()) | ||
->method('getBySymbolic') | ||
->with('testVocab', Application::ASSOC_TYPE_CITATION, 333) | ||
->willReturn($mockControlledVocab); | ||
|
||
DAORegistry::registerDAO('ControlledVocabDAO', $mockControlledVocabDao); | ||
$controlledVocabEntryId2 = ControlledVocabEntry::create([ | ||
'controlledVocabId' => $testControlledVocab->id, | ||
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD => [ | ||
'en' => 'testEntry', | ||
], | ||
])->id; | ||
|
||
// Instantiate validator | ||
$validator = new \PKP\form\validation\FormValidatorControlledVocab($form, 'testData', FormValidator::FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key', 'testVocab', Application::ASSOC_TYPE_CITATION, 333); | ||
$validator = new FormValidatorControlledVocab( | ||
$form, | ||
'testData', | ||
FormValidator::FORM_VALIDATOR_REQUIRED_VALUE, | ||
'some.message.key', | ||
ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, | ||
Application::ASSOC_TYPE_CITATION, | ||
$assocId | ||
); | ||
|
||
$form->setData('testData', '1'); | ||
$form->setData('testData', $controlledVocabEntryId1); | ||
self::assertTrue($validator->isValid()); | ||
|
||
$form->setData('testData', '2'); | ||
$form->setData('testData', $controlledVocabEntryId2); | ||
self::assertTrue($validator->isValid()); | ||
|
||
$form->setData('testData', '3'); | ||
$form->setData('testData', 3); | ||
self::assertFalse($validator->isValid()); | ||
|
||
// Delete the test vocab along with entries | ||
ControlledVocab::find($testControlledVocab->id)->delete(); |
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.
With implementation of setting table based eloquent, we can not add any arbitrary setting data so only options seems to create data and delete at the end of test . Another option can be is to backup/restore specific tables or full DB but that make the test time high. For this and other similar tests t below .
da83366
to
e1964a3
Compare
160d196
to
bed3f45
Compare
02334cd
to
9414859
Compare
for #10292