Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions php/libraries/NDB_BVL_Instrument.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2214,16 +2214,17 @@ abstract class NDB_BVL_Instrument extends NDB_Page
*
* @param $commentIDs string[] A list of commentIDs to load in bulk.
*
* @return \NDB_BVL_Instrument[]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This type shouldn't have to change but phan isn't great at understanding generators and doesn't recognize them as sometype[] compatible.

* @return Generator<\NDB_BVL_Instrument>
*/
function bulkLoadInstanceData(iterable $commentIDs): array
function bulkLoadInstanceData(iterable $commentIDs): iterable
{
if ($this->commentID !== null && $this->commentID !== '') {
throw new \LogicException(
"Must bulk load from instrument loaded without commentID"
);
}
$db = $this->loris->getDatabaseConnection();
$db = $this->loris->getNewDatabaseConnection();
$db->setBuffering(false);

$prepBindings = [];
$prepValues = [];
Expand Down Expand Up @@ -2252,8 +2253,7 @@ abstract class NDB_BVL_Instrument extends NDB_Page
. join(',', $prepBindings) . ')',
$prepValues,
);
return array_map(
function ($row) {
foreach ($jsondata as $row) {
$newinst = clone $this;

$newinst->commentID = $row['CommentID'];
Expand All @@ -2263,11 +2263,9 @@ abstract class NDB_BVL_Instrument extends NDB_Page
$row['Data'] ?? '{}',
true,
) ?? $this->defaultInstanceData();

return $newinst;
},
iterator_to_array($jsondata)
);
yield $newinst;
}
return;
} else {
$defaults = $db->pselect(
"SELECT flag.CommentID as CommentID,
Expand All @@ -2280,8 +2278,7 @@ abstract class NDB_BVL_Instrument extends NDB_Page
. join(',', $prepBindings) . ')',
$prepValues,
);
return array_map(
function ($row) {
foreach ($defaults as $row) {
$newinst = clone $this;

$newinst->commentID = $row['CommentID'];
Expand All @@ -2291,10 +2288,9 @@ abstract class NDB_BVL_Instrument extends NDB_Page

$newinst->instanceData = $row;

return $newinst;
},
iterator_to_array($defaults)
);
yield $newinst;
}
return;
}
}

Expand Down