Skip to content

Commit

Permalink
Fixed EZP-19673: search results contain link to hidden nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dpobel committed Oct 24, 2012
1 parent a505cf6 commit 3fc1347
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
4 changes: 3 additions & 1 deletion classes/ezfezpsolrquerybuilder.php
Expand Up @@ -158,6 +158,7 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
$visibilityDefaultSetting = self::$SiteINI->variable( 'SiteAccessSettings', 'ShowHiddenNodes' );
$visibilityDefault = ( $visibilityDefaultSetting === 'true' ) ? true : false;
$ignoreVisibility = isset( $params['IgnoreVisibility'] ) ? $params['IgnoreVisibility'] : $visibilityDefault;
$this->searchPluginInstance->postSearchProcessingData['ignore_visibility'] = $ignoreVisibility;
$limitation = isset( $params['Limitation'] ) ? $params['Limitation'] : null;
$boostFunctions = isset( $params['BoostFunctions'] ) ? $params['BoostFunctions'] : null;
$forceElevation = isset( $params['ForceElevation'] ) ? $params['ForceElevation'] : false;
Expand Down Expand Up @@ -451,7 +452,8 @@ public function buildSearch( $searchText, $params = array(), $searchTypes = arra
eZSolr::getMetaFieldName( 'main_url_alias' ) . ' ' . eZSolr::getMetaFieldName( 'installation_url' ) . ' ' .
eZSolr::getMetaFieldName( 'id' ) . ' ' . eZSolr::getMetaFieldName( 'main_node_id' ) . ' ' .
eZSolr::getMetaFieldName( 'language_code' ) . ' ' . eZSolr::getMetaFieldName( 'name' ) .
' score ' . eZSolr::getMetaFieldName( 'published' ) . ' ' . eZSolr::getMetaFieldName( 'path_string' ) . ' ' . implode( ' ', $extraFieldsToReturn );
' score ' . eZSolr::getMetaFieldName( 'published' ) . ' ' . eZSolr::getMetaFieldName( 'path_string' ) . ' ' .
eZSolr::getMetaFieldName( 'is_invisible' ) . ' ' . implode( ' ', $extraFieldsToReturn );

if ( ! $asObjects )
{
Expand Down
47 changes: 42 additions & 5 deletions search/plugins/ezsolr/ezsolr.php
Expand Up @@ -345,16 +345,42 @@ protected function getNodeID( $doc )
$docPathStrings,
$subtreeLimitations
);
$ignoreVisibility = eZContentObjectTreeNode::showInvisibleNodes();
if ( isset( $this->postSearchProcessingData['ignore_visibility'] ) )
{
$ignoreVisibility = $this->postSearchProcessingData['ignore_visibility'];
}


// Intersect between $validSubtreeArray (search location filter) and $validSubtreeLimitations (user policy limitations)
// indicates valid locations for $doc in current search query
// If this intersect is not empty, we take the first element to get the corresponding node ID
$validSubtrees = array_intersect( $validSubtreeArray, $validSubtreeLimitations );
// If this intersect is not empty, we take the first node id that
// matches the visibility requirement
$validSubtrees = array_flip(
array_intersect( $validSubtreeArray, $validSubtreeLimitations )
);
if ( !empty( $validSubtrees ) )
{
$validSubtree = array_shift( $validSubtrees );
$nodeArray = explode( '/', rtrim( $validSubtree, '/' ) );
return (int)array_pop( $nodeArray );
foreach ( $docPathStrings as $k => $path )
{
if ( isset( $validSubtrees[$path] ) )
{
if (
$ignoreVisibility ||
!$doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'is_invisible' )][$k]
)
{
$nodeArray = explode( '/', rtrim( $path, '/' ) );
return (int)array_pop( $nodeArray );
}
}
}
eZDebug::writeError(
"Could not find a visible location for content " .
"#{$doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'id' )]} " .
"that current user has read access on. The Solr index is probably outdated",
__METHOD__
);
}
else
{
Expand All @@ -369,6 +395,17 @@ protected function getNodeID( $doc )
__METHOD__
);
}
foreach ( $docPathStrings as $k => $path )
{
if (
$ignoreVisibility ||
!$doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'is_invisible' )][$k]
)
{
$nodeArray = explode( '/', rtrim( $path, '/' ) );
return (int)array_pop( $nodeArray );
}
}
}

return (int)$doc[ezfSolrDocumentFieldBase::generateMetaFieldName( 'main_node_id' )];
Expand Down

1 comment on commit 3fc1347

@paulborgermans
Copy link
Contributor

Choose a reason for hiding this comment

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

Patch looks good, +1

Please sign in to comment.