This repository was archived by the owner on Jun 1, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-15
lines changed Expand file tree Collapse file tree 1 file changed +19
-15
lines changed Original file line number Diff line number Diff 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 ()])) {
You can’t perform that action at this time.
0 commit comments