Skip to content
This repository was archived by the owner on Jun 1, 2021. It is now read-only.

Commit 83086e5

Browse files
author
Leonardo Pedretti
committed
Fixed errors when importing people due to a generator being closed when used with a foreach
1 parent d5bad71 commit 83086e5

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/Endpoints/Endpoint.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,29 @@ public function createMany($entries)
5353
{
5454
// first extract the relations wich should be managed through a side request
5555
$relations = [];
56-
foreach ($entries as $entry) {
57-
$tm2id = null;
58-
59-
foreach ($entry['custom_fields'] as $customfield) {
60-
if (is_object($customfield)) {
61-
if ($customfield->name == "TM2 ID") {
62-
$tm2id = $customfield->getValue();
63-
break;
56+
$entriesGenerator = function($entries) use (&$relations) {
57+
foreach ($entries as $entry) {
58+
$tm2id = null;
59+
60+
foreach ($entry['custom_fields'] as $customfield) {
61+
if (is_object($customfield)) {
62+
if ($customfield->name == "TM2 ID") {
63+
$tm2id = $customfield->getValue();
64+
break;
65+
}
6466
}
6567
}
68+
69+
if (isset($entry['relations'])) {
70+
$relations[$tm2id] = $entry['relations'];
71+
unset($entry['relations']);
72+
}
73+
74+
yield $entry;
6675
}
67-
68-
if (isset($entry['relations'])) {
69-
$relations[$tm2id] = $entry['relations'];
70-
unset($entry['relations']);
71-
}
72-
}
76+
};
7377

74-
$results = $this->request('post', $this->entriesJsonifier($entries));
78+
$results = $this->request('post', $this->entriesJsonifier($entriesGenerator($entries)));
7579

7680
foreach ($results as $result) {
7781
if (!empty($relations[$result->custom_fields['TM2 ID']->getValue()])) {

0 commit comments

Comments
 (0)