Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Add batch processing for persisting#23

Open
Tristaan wants to merge 2 commits intomjordan:masterfrom
Abak-net-d-o-o:abak/batch_process
Open

Add batch processing for persisting#23
Tristaan wants to merge 2 commits intomjordan:masterfrom
Abak-net-d-o-o:abak/batch_process

Conversation

@Tristaan
Copy link

Hello,
As said in the issue #22, here is the batch processing. I solved it using an controller and a link in the form. It is working, but it needs some work done in the generic persister, because it does not overwrite existing values, it just adds new values. This is really impractical if doing batch processes multiple times. I did not know how to solve this.

Hope to hear from someone soon.

@mjordan
Copy link
Owner

mjordan commented Sep 15, 2021

@Tristaan thanks for this, I will take a look.

@mjordan
Copy link
Owner

mjordan commented Sep 17, 2021

When you say "it does not overwrite existing values, it just adds new values", are you wanting to overwrite all existing values in for example the "Identifier" field even if they are not persistent identifiers? For example, if I have in my Identifier field some local identifiers (e.g. "etdid3876"), if this node was part of a batch, that value would be wiped out and replaced with "ark:/4653/fooo499q"? If that's the case, we can do that in the persister, but we'll need to provide an option to either overwrite or append values, since not all sites will want to do that. Let me know if I have misunderstood what you're looking for.

@Tristaan
Copy link
Author

Tristaan commented Sep 17, 2021 via email

@mjordan
Copy link
Owner

mjordan commented Sep 17, 2021

Gotcha. I'll comment on one way of doing that over in the code review.

public function persist(&$entity, $pid, $save = TRUE) {
$target_field = trim($this->config->get('persistent_identifiers_target_field'));
if (method_exists($entity, 'hasField') && $entity->hasField($target_field)) {
// TODO: Don't add same values
Copy link
Owner

Choose a reason for hiding this comment

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

Something like this maybe?

$existing_values = $entity->get($target_field)->getValue()
foreach ($existing_values as $value) {
    if ($pid != $value) {
        $entity->{$target_field}[] = $pid;
    }
}

Copy link
Owner

Choose a reason for hiding this comment

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

Or maybe better to use a !in_array($pid, $existing_values)?

Copy link
Author

Choose a reason for hiding this comment

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

an !in_array is better, because looping through the field, if they have multiple values causes additional appends to the array.

@Tristaan Tristaan requested a review from mjordan September 20, 2021 08:05
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.

2 participants