Skip to content

Commit

Permalink
move out invariant instructions out of the loop (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rija Menage committed Apr 10, 2018
1 parent a842137 commit d8ecd69
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions protected/models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,20 @@ function mergeAsIdenticalWithAuthor($author) {
$origin_graph[] = $this->id;
$success = true;

//proc to construct a valid db record for author_rel to pass on to createMultipleInsertCommand
$id_to_record = function ($origin_id, $target_id, $relationship_id) {
return ["author_id"=> $origin_id, "related_author_id"=>$target_id, "relationship_id"=>$relationship_id];
};

$connection = Yii::app()->db->getSchema()->getCommandBuilder();

foreach ($origin_graph as $origin_node) {

$id_to_record = function ($origin_id, $target_id, $relationship_id) {
return ["author_id"=> $origin_id, "related_author_id"=>$target_id, "relationship_id"=>$relationship_id];
};
$connection = Yii::app()->db->getSchema()->getCommandBuilder();
$command = $connection->createMultipleInsertCommand('author_rel', array_map( $id_to_record,
array_fill(0, $target_count, $origin_node),
$target_graph,
array_fill(0, $target_count, $identicalToObj->id) )
array_fill(0, $target_count, $identicalToObj->id)
)
);
$inserted_count = $command->execute();
$success = $success && ( $target_count == $inserted_count ? true : false );
Expand Down

0 comments on commit d8ecd69

Please sign in to comment.