Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Conversation

@andriyun
Copy link
Contributor

@andriyun andriyun commented Mar 29, 2022

Custom path: /execute-foloeb-task

The ability to refer to the specific task in email is possible via token, for example
/execute-foloeb-task?token=XebF7BbNosDZNM-GNDP7ADH0vaPbR74pLSf8pnXCalE

The code is available for testing as a composer package https://packagist.org/packages/os2forms/os2forms_forloeb#dev-AARHUS-ITK-A

@andriyun andriyun requested review from rimi-itk and skifter and removed request for skifter March 30, 2022 07:39
Copy link
Collaborator

@rimi-itk rimi-itk left a comment

Choose a reason for hiding this comment

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

Looks very good! Nice and clean solution.

Some comments and suggestions added.

@@ -0,0 +1,9 @@
os2forms_forloeb.forloeb_task_console_controller_execute:
path: 'execute-foloeb-task'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo: “foloeb” should be “forloeb”.

Maybe we should use the module name in the path to get some namespacing, e.g. os2forms_forloeb/execute-forloeb-task, say.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines 129 to 131
else {
$this->messenger()->addWarning($this->t('No tasks found to execute.'));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider an early return if no queue record is found to make the code a little easier to read, i.e.

if (!$queueRecord) {
  $this->messenger()->addWarning($this->t('No tasks found to execute.'));
  return new RedirectResponse($redirect_to->toString());
}

$handler = $queueRecord->handler->getString();
…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added early return

Comment on lines 38 to 64
public function getQueueIdByWebformSubmissionToken($token = '') {
$engine = new MaestroEngine();
// Fetch the user's queue items.
$queueIDs = $engine->getAssignedTaskQueueIds(\Drupal::currentUser()->id());

foreach ($queueIDs as $queueID) {
$this->entityTypeManager->getStorage('maestro_queue')->resetCache([$queueID]);
/** @var \Drupal\maestro\Entity\MaestroQueue $queueRecord */
$queueRecord = $this->entityTypeManager->getStorage('maestro_queue')->load($queueID);
$processID = $engine->getProcessIdFromQueueId($queueID);
$templateMachineName = $engine->getTemplateIdFromProcessId($processID);

// Get user input from 'inherit_webform_unique_id'
$taskMachineName = $engine->getTaskIdFromQueueId($queueID);
$task = $engine->getTemplateTaskByID($templateMachineName, $taskMachineName);

// Load its corresponding webform submission.
$sid = $engine->getEntityIdentiferByUniqueID($processID, $task['data']['inherit_webform_unique_id'] ?? '');
$webform_submission = $sid ? WebformSubmission::load($sid) : NULL;

if ($webform_submission && $webform_submission->getToken() != $token) {
return $queueRecord;
}
}

return NULL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to get the queue record directly from the token without having to load and iterate over all queues and submissions, i.e. something like

// Warning: Pseudocode ahead!
$submission = $this->entityTypeManager->getStorage('webform_submission')->findByToken($token);
return NULL !== $submission
  ? $this->entityTypeManager->getStorage('maestro_queue')->findBySubmission($submission)
  : NULL;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's possible in an easy way. I can not find a direct connection between maestro_queue and webform_submission to implement this kind of lookup.

By idea, maestro_queue can have different handlers and reference to webform submission is on of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I finally found a way to get it f92e668

Copy link
Collaborator

@rimi-itk rimi-itk left a comment

Choose a reason for hiding this comment

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

Very good work!

@andriyun
Copy link
Contributor Author

andriyun commented Apr 4, 2022

Hi @rimi-itk
Unfortunately, I can not merge this PR to develop branch.
Maybe you have access, and can do this for me?

@rimi-itk
Copy link
Collaborator

rimi-itk commented Apr 4, 2022

Sorry, @andriyun, I don't have permissions to merge, but maybe @madsnorgaard or @agger-magenta can help us?

@agger-magenta
Copy link
Contributor

It's strange, but I can't seem to merge this either. @madsnorgaard, can you do it?

@madsnorgaard madsnorgaard merged commit ff334c6 into develop Apr 4, 2022
@madsnorgaard
Copy link
Collaborator

Squashed and merged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants