Skip to content

Commit

Permalink
Merge branch '2017.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Aug 2, 2018
2 parents 0934b6d + 0afc0ae commit 49521c1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
59 changes: 37 additions & 22 deletions kernel/classes/ezcontentobjecttreenode.php
Expand Up @@ -2799,26 +2799,14 @@ static function sortArrayBySortFieldAndSortOrder( $sortField, $sortOrder )
static function assignSectionToSubTree( $nodeID, $sectionID, $oldSectionID = false )
{
$db = eZDB::instance();

$node = eZContentObjectTreeNode::fetch( $nodeID );
$nodePath = $node->attribute( 'path_string' );

$sectionID =(int) $sectionID;

$pathString = " path_string like '$nodePath%' AND ";

// fetch the object id's which needs to be updated
$objectIDArray = $db->arrayQuery( "SELECT
ezcontentobject.id
FROM
ezcontentobject_tree, ezcontentobject
WHERE
$pathString
ezcontentobject_tree.contentobject_id=ezcontentobject.id AND
ezcontentobject_tree.main_node_id=ezcontentobject_tree.node_id" );
if ( count( $objectIDArray ) == 0 )
$objectSimpleIDArray = eZContentObjectTreeNode::getObjectIdsInNodeSubTree($node);
if ( !$objectSimpleIDArray )
return;

$sectionID =(int) $sectionID;

// Who assigns which section at which node should be logged.
$section = eZSection::fetch( $sectionID );
$object = $node->object();
Expand All @@ -2828,12 +2816,6 @@ static function assignSectionToSubTree( $nodeID, $sectionID, $oldSectionID = fal
'Content object name' => $object->attribute( 'name' ),
'Comment' => 'Assigned a section to the current node and all child objects: eZContentObjectTreeNode::assignSectionToSubTree()' ) );

$objectSimpleIDArray = array();
foreach ( $objectIDArray as $objectID )
{
$objectSimpleIDArray[] = $objectID['id'];
}

$filterPart = '';
if ( $oldSectionID !== false )
{
Expand Down Expand Up @@ -6423,6 +6405,39 @@ public function isNodeTrashAllowed()
) == 0 ;
}

/**
* Returns an array of Object IDs inside node subtree or null when empty.
* @param $node
* @return array|null
*/
static function getObjectIdsInNodeSubTree($node)
{
$db = eZDB::instance();
$nodePath = $node->attribute( 'path_string' );
$pathString = " path_string like '$nodePath%' AND ";

$objectIDArray = $db->arrayQuery( "SELECT
ezcontentobject.id
FROM
ezcontentobject_tree, ezcontentobject
WHERE
$pathString
ezcontentobject_tree.contentobject_id=ezcontentobject.id AND
ezcontentobject_tree.main_node_id=ezcontentobject_tree.node_id" );

if ( count( $objectIDArray ) == 0 )
return null;

$objectSimpleIDArray = array();

foreach ( $objectIDArray as $objectID )
{
$objectSimpleIDArray[] = $objectID['id'];
}

return $objectSimpleIDArray;
}

/**
* @var string|bool The current language for the node
*/
Expand Down
19 changes: 18 additions & 1 deletion kernel/classes/ezsection.php
Expand Up @@ -253,7 +253,24 @@ public function applyTo( eZContentObject $object )
}
eZContentCacheManager::clearContentCacheIfNeeded( $object->attribute( "id" ) );
$object->expireAllViewCache();
$db->commit();
$commitResult = $db->commit();

// Update search indexes AFTER transaction is completed, so changes are actually available for Search Engine.
if ( $commitResult ) {
if ( !empty( $assignedNodes ) ) {
foreach ( $assignedNodes as $node ) {
$objectIDArray = eZContentObjectTreeNode::getObjectIdsInNodeSubTree( $node );

foreach (array_chunk($objectIDArray, 100) as $pagedObjectIDs) {
// Clear cache of affected objects in sub tree so they are up-to-date when indexed.
eZContentCacheManager::clearObjectViewCacheArray($pagedObjectIDs);
eZSearch::updateObjectsSection($pagedObjectIDs, $sectionID);
}
}
} else {
eZSearch::updateObjectsSection(array($object->attribute("id")), $sectionID);
}
}
}
}

Expand Down

0 comments on commit 49521c1

Please sign in to comment.