Remove dependent dangling embeds.

This commit is contained in:
Dave Longley 2011-11-28 22:51:30 -05:00
parent ac210d60e3
commit fb11cb945f

View file

@ -2622,6 +2622,26 @@ function _isDuckType($input, $frame)
return $rval; return $rval;
} }
/**
* Recursively removes dependent dangling embeds.
*
* @param iri the iri of the parent to remove embeds for.
* @param embeds the embeds map.
*/
function removeDependentEmbeds($iri, $embeds)
{
$iris = get_object_vars($embeds);
foreach($iris as $i => $embed)
{
if($embed->parent !== null and
$embed->parent->{'@subject'}->{'@iri'} === $iri)
{
unset($embeds->$i);
removeDependentEmbeds($i, $embeds);
}
}
}
/** /**
* Subframes a value. * Subframes a value.
* *
@ -2672,12 +2692,13 @@ function _subframe(
{ {
if(is_array($embed->parent->{$embed->key})) if(is_array($embed->parent->{$embed->key}))
{ {
// find and replace embed in array
$arrLen = count($embed->parent->{$embed->key}); $arrLen = count($embed->parent->{$embed->key});
for($i = 0; $i < $arrLen; ++$i) for($i = 0; $i < $arrLen; ++$i)
{ {
$obj = $embed->parent->{$embed->key}[$i]; $obj = $embed->parent->{$embed->key}[$i];
if(is_object($obj) and property_exists($obj, '@subject') and if(is_object($obj) and property_exists($obj, '@subject') and
$obj['@iri'] === $iri) $obj->{'@subject'}->{'@iri'} === $iri)
{ {
$embed->parent->{$embed->key}[$i] = $value->{'@subject'}; $embed->parent->{$embed->key}[$i] = $value->{'@subject'};
break; break;
@ -2688,6 +2709,9 @@ function _subframe(
{ {
$embed->parent->{$embed->key} = $value->{'@subject'}; $embed->parent->{$embed->key} = $value->{'@subject'};
} }
// recursively remove any dependent dangling embeds
removeDependentEmbeds($iri, $embeds);
} }
// update embed entry // update embed entry