Skip to content

Conversation

@Hafsa-Naeem
Copy link
Contributor

for #11885

Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I left a couple of comments. Can you also do a rebase, this would also require additional modifications because of a recent merge.

$id = (int) $request->route('templateId');

$template = Template::query()
->where('context_id', $contextId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use scope here as we avoid using column names besides the Model itself


$template = Template::query()
->where('context_id', $contextId)
->findOrFail($id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need the explicit response error code (404) and message

if (array_key_exists('stageId', $data)) $updates['stage_id'] = (int) $data['stageId'];
if (array_key_exists('title', $data)) $updates['title'] = $data['title'];
if (array_key_exists('include', $data)) $updates['include'] = (bool) $data['include'];
if (array_key_exists('emailTemplateKey', $data)) $updates['email_template_key'] = $data['emailTemplateKey'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removed the email template key association. The current idea is to hard code the message into the template using description attribute


DB::transaction(function () use ($template, $data) {
$updates = [];
if (array_key_exists('stageId', $data)) $updates['stage_id'] = (int) $data['stageId'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need these checks and go directly to the update

if ($updates) {
$template->update($updates);
}
if (array_key_exists('userGroupIds', $data)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like the following would be better:

$userGroupIds = Arr::pull($data, 'userGroupIds');
$template->update($data);
$template->userGroups()->sync($userGroupIds);

$stages = Application::getApplicationStages();
$stageIds = array_values(array_unique(array_filter(
array_map('intval', array_merge(array_keys((array)$stages), array_values((array)$stages))),
fn ($id) => $id > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably we don't need this check

'title' => ['required', 'string', 'max:255'],
'include' => ['boolean'],
'emailTemplateKey' => ['sometimes', 'nullable', 'string', 'max:255', Rule::in($emailKeys)],
'type' => ['required','integer','in:1,2'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can re-use our EditorialTaskType enum here instead of plain numbers

$stages = Application::getApplicationStages();
$stageIds = array_values(array_unique(array_filter(
array_map('intval', array_merge(array_keys((array)$stages), array_values((array)$stages))),
fn ($id) => $id > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this check isn't needed

)));

// Context-scoped email keys
$emailKeys = \APP\facades\Repo::emailTemplate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as we don't rely on email templates anymore


public $timestamps = true;

public const TYPE_DISCUSSION = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just re-use EdirotialTaskType enum

@Hafsa-Naeem Hafsa-Naeem force-pushed the i11885-main-fix branch 3 times, most recently from 6b7fc8b to 754ce24 Compare October 28, 2025 09:21
Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I left a couple of comments


DB::transaction(function () use ($template, $data) {
$userGroupIds = Arr::pull($data, 'userGroupIds');
$updates = collect($data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anything critical but this should already be done during validation

use PKP\editorialTask\enums\EditorialTaskDueInterval;
use PKP\editorialTask\enums\EditorialTaskType;

class UpdateTaskTemplate extends FormRequest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this class and AddTaskTemplate could have a common parent to avoid code duplication. Or AddTaskTemplate could extend this class. Or have a common trait...


class UpdateTaskTemplate extends FormRequest
{
public function authorize(): bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work as we haven't yet integrated/adopted Laravel auth policies (it uses Laravel gates and policies according to the documentation: https://laravel.com/docs/12.x/validation#authorizing-form-requests)

}

$tokens = preg_split('/\s+/', $phrase) ?: [];
$tokens = array_values(array_filter($tokens, fn ($t) => $t !== ''));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also should do a special treatment for the task or discussion keyword within search phrase. E.g., the search phrase

task ethics

The code should perform the search by the keyword ethics within the tasks only.

return $query;
}

$tokens = preg_split('/\s+/', $phrase) ?: [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but maybe we already got a helper to break the phrase onto tokens somewhere in our codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vitaliy-1 I checked the PKP codebase for existing helpers around tokenizing search phrases, but didn't find a reusable helper for this. Other search-related code appears to split phrases inline in a similar way.
For now I've kept the simple preg_split('/\s+/', ...) implementation here to stay consistent. If we later introduce a shared helper for free-text search tokens, I can switch this scope to use it.

@Vitaliy-1 Vitaliy-1 requested a review from bozana October 29, 2025 12:13
@Vitaliy-1
Copy link
Contributor

@bozana, could you take a look at the search implementation for task templates? I'm not much familiar with our patterns and best practices, e.g., breaking the string into tokens/keywords. Also, should we use vocabulary for this? The idea is to search matches in the title and description/headnote. Ideally grouping and showing matches in the title first.

Copy link
Contributor

@bozana bozana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Hafsa-Naeem and @Vitaliy-1,
I went through the changes and left some comments.
Thanks!

$outer->where(function (Builder $q) use ($like, $settingsTable, $pk, $selfTable) {
$q->whereRaw('LOWER(title) LIKE ?', [$like])
->orWhereRaw('LOWER(description) LIKE ?', [$like])
->orWhereExists(function ($sub) use ($like, $settingsTable, $pk, $selfTable) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builder $sub -- type Builder?

@bozana
Copy link
Contributor

bozana commented Nov 5, 2025

Hi @Vitaliy-1, oh I first now see your message above.
I think we have never used vocabularies, so I think this is not needed.
Regarding "The idea is to search matches in the title and description/headnote. Ideally grouping and showing matches in the title first.": hmmm... I am not sure how to implement ranking, would need to think about it...

@Hafsa-Naeem Hafsa-Naeem force-pushed the i11885-main-fix branch 2 times, most recently from edc8132 to bc76e6f Compare November 10, 2025 16:10
Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment but not a showstopper

protected function getStageIds(): array
{
$stages = Application::getApplicationStages();
return array_map('intval', array_values($stages));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that there already was a comment regarding this, do we need array_values and array_map here. I mean Application::getApplicationStages() already returns non-associative array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vitaliy-1 Yes! I'll update this accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants