Skip to content

Commit

Permalink
Do not overdelete if all node paths changed
Browse files Browse the repository at this point in the history
  • Loading branch information
André L F S Bacci committed Nov 27, 2024
1 parent 79a06be commit 2fec2ba
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,21 +790,21 @@ function getFileModificationHistory(): array {
$fatal = $ac['LANG'] == 'en';
$xpath = new DOMXPath( $dom );

// pre run id capture
// pre xinclude() run id capture

$prevIdPath = [];
$listIdPath = [];

$nodes = $xpath->query( "//*[@xml:id]" );
foreach( $nodes as $node )
{
$id = $node->getAttribute( "xml:id" );
$path = $node->getNodePath();
if ( isset( $prevIdPath[ $id ] ) )
if ( isset( $listIdPath[ $id ] ) )
{
echo "failed.\nDuplicated xml:id '$id' before XInclude!\n";
errors_are_bad( 1 );
}
$prevIdPath[ $id ] = $path;
$listIdPath[ $id ] = $path;
}

// automatic xi:fallback
Expand Down Expand Up @@ -870,13 +870,10 @@ function getFileModificationHistory(): array {
{
$count++;
$path = getNodePathWithIds( $node->parentNode );
fprintf( $print , "\nFailed xi:include at: $path\n");
fprintf( $print , "\nFailed xi:include location: $path\n");

if ( trim( $payload) != "xi:fallback" )
{
$payload = trim( substr( $payload , 12 ) );
fprintf( $print , "Failed xi:include target is: $payload\n");
}
$payload = trim( substr( $payload , 12 ) );
fprintf( $print , "Failed xi:include target is: $payload\n");
}
}

Expand All @@ -891,12 +888,27 @@ function getFileModificationHistory(): array {
// post run id fixup

$nodes = $xpath->query( "//*[@xml:id]" );

$count = [];
foreach( $nodes as $node )
{
$id = $node->getAttribute( "xml:id" );
isset( $count[$id] ) ? $count[$id]++ : $count[$id] = 1;
}

foreach( $nodes as $node )
{
$id = $node->getAttribute( "xml:id" );
$path = $node->getNodePath();
if ( $prevIdPath[ $id ] != $path )

// Delete ids with unknown (newer?) paths,
// but do not overdelete if all paths changed.

if ( $listIdPath[ $id ] != $path && $count[ $id ] > 1 )
{
$node->removeAttribute( "xml:id" );
$count[ $id ]--;
}
}

flush();
Expand Down

0 comments on commit 2fec2ba

Please sign in to comment.