Example #1
0
 protected function updateChildNodesAfterMovingParent(EntityInterface $parent)
 {
     // find all existing children of the moved parent node
     $projection_type = $parent->getType();
     $parent_identifier = $parent->getIdentifier();
     $path = $this->calculateMaterializedPath($parent);
     $affected_relatives = [];
     $this->getQueryService($projection_type)->scroll(new CriteriaQuery(new CriteriaList(), new CriteriaList([new AttributeCriteria('materialized_path', new Equals($parent_identifier))]), new CriteriaList(), 0, $this->config->get('batch_size', 1000)), function (ProjectionInterface $projection) use(&$affected_relatives, $parent_identifier, $projection_type, $path) {
         // @note if there are many affected relatives this could consume memory
         $child_data = $projection->toArray();
         $pattern = '#.*' . $parent_identifier . '#';
         $child_data['materialized_path'] = preg_replace($pattern, $path, $projection->getMaterializedPath());
         $affected_relatives[] = $projection_type->createEntity($child_data);
     });
     return $affected_relatives;
 }