Skip to content
Snippets Groups Projects
Commit 622ad4c3 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3398076: NewMessage sent to VGWort needs at least one author

parent 922a506d
No related branches found
No related tags found
1 merge request!33Check only for authors, not publishers and translators
Pipeline #42271 canceled
......@@ -28,6 +28,10 @@ Unless additional actions are taken no information will be sent to VG Wort. Once
all the author information has been entered the queue can be set to be processed
by cron, or you can configure a daemon or drush job to process the queue.
**Note:** If an entity does not have any author information it will not be sent
to VG Wort. It will be requeued (defaults to 14 days). If the entity is saved
again in the meantime it will be reset and processed within the next day.
## Excluding an entity from VG Wort
If you've configured entities to have the VG Wort counter ID you can implement
`hook_vgwort_enable_for_entity()` to exclude specific entities from VG Wort.
......
......@@ -61,4 +61,14 @@ abstract class Participant implements \JsonSerializable {
return $b instanceof PersonParticipant ? 1 : -1;
}
/**
* Gets the participant's involvement.
*
* @return string
* The participant's involvement; either author, publisher, or translator.
*/
public function getInvolvment(): string {
return $this->involvement;
}
}
......@@ -10,6 +10,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\vgwort\Api\MessageText;
use Drupal\vgwort\Api\NewMessage;
use Drupal\vgwort\Api\Participant;
use Drupal\vgwort\Api\Webrange;
use Drupal\vgwort\Exception\NoCounterIdException;
use Drupal\vgwort\Exception\NoParticipantsException;
......@@ -93,8 +94,8 @@ class MessageGenerator {
(string) $this->renderer->renderPlain($build)
);
$participants = $this->participantListManager->getParticipants($entity);
if (empty($participants)) {
throw new NoParticipantsException('Entities must have at least one participant in order to generate a VG Wort new massage notification');
if (!$this->hasAuthor($participants)) {
throw new NoParticipantsException('Entities must have at least one author in order to generate a VG Wort new massage notification');
}
$webranges = [new Webrange([$entity->toUrl()->setAbsolute()->toString()])];
$legal_rights = $this->config->get('legal_rights');
......@@ -122,4 +123,22 @@ class MessageGenerator {
);
}
/**
* Determines if the entity has at least one author participant.
*
* @param \Drupal\vgwort\Api\Participant[] $participants
* The list of participants.
*
* @return bool
* TRUE if the entity has at least one author participant, FALSE if not.
*/
private function hasAuthor(array $participants): bool {
foreach ($participants as $participant) {
if ($participant->getInvolvment() === Participant::AUTHOR) {
return TRUE;
}
}
return FALSE;
}
}
......@@ -455,7 +455,7 @@ class EntityQueueTest extends VgWortKernelTestBase {
$this->container->get('advancedqueue.processor')->processQueue($queue);
$this->assertSame($jobs, $queue_backend->countJobs());
$job = $this->container->get('vgwort.entity_job_mapper')->getJob($entity);
$this->assertSame('The entity entity_test_revpub:1 failed: Entities must have at least one participant in order to generate a VG Wort new massage notification', $job->getMessage());
$this->assertSame('The entity entity_test_revpub:1 failed: Entities must have at least one author in order to generate a VG Wort new massage notification', $job->getMessage());
$this->assertSame('1', $job->getNumRetries());
// Go 30 days into the future.
......@@ -463,7 +463,7 @@ class EntityQueueTest extends VgWortKernelTestBase {
$this->container->get('advancedqueue.processor')->processQueue($queue);
$this->assertSame($jobs, $queue_backend->countJobs());
$job = $this->container->get('vgwort.entity_job_mapper')->getJob($entity);
$this->assertSame('The entity entity_test_revpub:1 failed: Entities must have at least one participant in order to generate a VG Wort new massage notification', $job->getMessage());
$this->assertSame('The entity entity_test_revpub:1 failed: Entities must have at least one author in order to generate a VG Wort new massage notification', $job->getMessage());
$this->assertSame('2', $job->getNumRetries());
// Add VG Wort info to user.
......
......@@ -47,7 +47,36 @@ class MessageGeneratorTest extends VgWortKernelTestBase {
'name' => 'A title',
]);
$entity->save();
$this->expectExceptionMessage('Entities must have at least one participant in order to generate a VG Wort new massage notification');
/** @var \Drupal\vgwort\ParticipantListManager $participant_manager */
$participant_manager = $this->container->get('vgwort.participant_list_manager');
$this->assertCount(0, $participant_manager->getParticipants($entity));
$this->expectExceptionMessage('Entities must have at least one author in order to generate a VG Wort new massage notification');
$this->expectException(NoParticipantsException::class);
$this->container->get('vgwort.message_generator')->entityToNewMessage($entity);
}
public function testNoAuthorsNoParticipantException() {
$entity_type = 'entity_test';
$entity = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create([
// Add a translator.
'vgwort_test2' => [
'card_number' => '123123123',
'firstname' => 'Bob',
'surname' => 'Jones',
'agency_abbr' => '',
],
'text' => 'Some text',
'name' => 'A title',
]);
$entity->save();
/** @var \Drupal\vgwort\ParticipantListManager $participant_manager */
$participant_manager = $this->container->get('vgwort.participant_list_manager');
$this->assertCount(1, $participant_manager->getParticipants($entity));
$this->expectExceptionMessage('Entities must have at least one author in order to generate a VG Wort new massage notification');
$this->expectException(NoParticipantsException::class);
$this->container->get('vgwort.message_generator')->entityToNewMessage($entity);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment