Replaces a set of Site-Content indexes.

@param array  $parentUids

@return \BackBee\ClassContent\Repository\IndexationRepository
487902
private function replaceIdxContentContentsByUids(array $parentUids)
    {
        if (0 < count($parentUids)) {
            $command = 'REPLACE';
            if (!$this->replaceSupported) {
                // REPLACE command not supported, remove first then insert
                $this->_removeIdxContentContents(array_keys($parentUids));
                $command = 'INSERT';
            }

            $meta = $this->_em->getClassMetadata('BackBee\ClassContent\Indexes\IdxContentContent');
            $insertChildren = array();
            foreach ($parentUids as $parentUid => $subContentUids) {
                foreach ($subContentUids as $subContentUid) {
                    $insertChildren[] = sprintf('SELECT "%s", "%s"', $parentUid, $subContentUid);
                    $insertChildren[] = sprintf('SELECT %s, "%s"
                        FROM %s
                        WHERE %s = "%s"', $meta->getColumnName('content_uid'), $subContentUid, $meta->getTableName(), $meta->getColumnName('subcontent_uid'), $parentUid
                    );
                }
            }

            if (0 < count($insertChildren)) {
                $unionAll = implode(' UNION ALL ', $insertChildren);
                $query = sprintf('%s INTO %s (%s, %s) %s',
                    $command,
                    $meta->getTableName(),
                    $meta->getColumnName('content_uid'),
                    $meta->getColumnName('subcontent_uid'),
                    $unionAll
                );
                $this->_em->getConnection()->executeUpdate($query);
            }
        }

        return $this;
    }
1324850
protected function createAggregationQueryBuilderWithSiteIds(array $siteIds)
    {
        $qa = $this->createAggregationQuery();
        foreach ($siteIds as $key => $siteId) {
            $siteIds[$key] = new \MongoId($siteId);
        }
        $qa->match(
            array('site.$id' => array('$in' => $siteIds)),
            array('deleted' => false)
        );

        return $qa;
    }
659379
public function get($parentUuid, $uuid)
    {
        // Check parent exists
        $parentModel = static::$parentModel;
        $parentResource = $parentModel::findOrFail($parentUuid);

        // Authorize ability to view children model for parent
        $this->authorizeUserAction($this->parentAbilitiesRequired['view'], $parentResource);

        // Get resource
        $model = new static::$model;
        $resource = $model::with($model::$localWith)->where($model->getKeyName(), '=', $uuid)->firstOrFail();

        // Check resource belongs to parent
        if ($resource->getAttribute(($parentResource->getKeyName())) != $parentResource->getKey()) {
            throw new AccessDeniedHttpException('Resource \'' . class_basename(static::$model) . '\' with given UUID ' . $uuid . ' does not belong to ' .
                'resource \'' . class_basename(static::$parentModel) . '\' with given UUID ' . $parentUuid . '; ');
        }

        if (! $resource) {
            throw new NotFoundHttpException('Resource \'' . class_basename(static::$model) . '\' with given UUID ' . $uuid . ' not found');
        }

        // Authorize ability to create this model
        $this->authorizeUserAction('view', $resource);

        return $this->response->item($resource, $this->getTransformer());
    }
305957
private function removeIdxSiteContentsByUids($siteUid, array $contentUids)
    {
        if (0 < count($contentUids)) {
            $this->getEntityManager()
                    ->createQuery('DELETE FROM BackBee\ClassContent\Indexes\IdxSiteContent i
                        WHERE i.site_uid=:site_uid
                        AND i.content_uid IN (:content_uids)')
                    ->setParameters(array(
                        'site_uid' => $siteUid,
                        'content_uids' => $contentUids, ))
                    ->execute();
        }

        return $this;
    }
322740
public function getParentRepository()
    {
        $parent = $this->getRepository()->getDescription()->getProperty('parent');
        $parent = $this->getIdentifier($parent->getParent());

        return AnDomain::getRepository($parent);
    }
1192368
public function getNativelyNodeChildren($nodeUid)
    {
        $query = $this->createQueryBuilder('s')
                ->select('s._uid', 's._leftnode')
                ->where('s._parent = :node')
                ->addOrderBy('s._leftnode', 'asc')
                ->addOrderBy('s._modified', 'desc')
                ->getQuery()
                ->getSQL();

        $result = $this->getEntityManager()
                ->getConnection()
                ->executeQuery((string) $query, [$nodeUid], [\Doctrine\DBAL\Types\Type::STRING])
                ->fetchAll();

        return Collection::array_column($result, 'uid0');
    }
359990
public function getParentContentUidByUid($contentUid)
    {
        $q = $this->_em->getConnection()
                ->createQueryBuilder()
                ->select('c.parent_uid')
                ->from('content_has_subcontent', 'c')
                ->where('c.content_uid = :uid')
                ->setParameter('uid', $contentUid);

        return $q->execute()->fetchAll(\PDO::FETCH_COLUMN);
    }
790262
public function countChildren($parentId, $siteId)
    {
        $qa = $this->createAggregationQuery();
        $qa->match(
            array(
                'siteId'     => $siteId,
                'parent.$id' => new \MongoId($parentId)
            )
        );

        return $this->countDocumentAggregateQuery($qa);
    }
1218795
public function getParentContentUidsByUids(array $uids)
    {
        $ids = array();

        $query  = 'SELECT j.parent_uid FROM content_has_subcontent j
                   LEFT JOIN content c ON c.uid = j.content_uid
                   WHERE classname != \'BackBee\ClassContent\Element\'';

        $where = array();
        foreach ($uids as $uid) {
            $where[] = $uid;
        }

        if (count($where) > 0) {
            $query .= ' AND j.content_uid  IN ("'.implode('","', $where).'")';
            $parents = $this->getEntityManager()
                ->getConnection()
                ->executeQuery($query)->fetchAll(\PDO::FETCH_COLUMN);
            if ($parents) {
                $ids = array_merge($ids, $parents, $this->getParentContentUidsByUids($parents));
            }
        }

        return array_unique($ids);
    }
242190
public function newQueryForRestoration($ids)
    {
        if (is_array($ids)) {
            return $this->newQueryForCollectionRestoration($ids);
        }

        if (! Str::contains($ids, ':')) {
            return parent::newQueryForRestoration($ids);
        }

        $segments = explode(':', $ids);

        return $this->newQueryWithoutScopes()
            ->where($segments[0], $segments[1])
            ->where($segments[2], $segments[3]);
    }
450728
public function updateParentChildRelationships(array $productIds = [])
    {
        $variantMasterIdCache = [];

        $innerQb = $this->createQueryBuilder('p');
        $innerQb->where('p.isVariantMaster = 1')
            ->andWhere('p.number = :number');

        $qb = $this->createQueryBuilder('p');
        $qb
            ->where('p.isVariantMaster = 0')
            ->andWhere('p.variantMasterId is not null')
        ;

        if (count($productIds)) {
            $qb->andWhere($qb->expr()->in('p.id', ':productIds'));
            $qb->setParameter('productIds', $productIds);
        }

        $batchSize = 50;
        $i = 1;

        $iterableResult = $qb->getQuery()->iterate();
        foreach ($iterableResult as $row) {
            /** @var ProductInterface $product */
            $product = $row[0];

            if (!isset($variantMasterIdCache[$product->getVariantMasterId()])) {
                try {
                    /** @var ProductInterface $parent */
                    $parent = $innerQb->setParameter(
                        'number',
                        $product->getVariantMasterId()
                    )->getQuery()->getSingleResult();
                    $parent = $parent->getId();
                } catch (UnexpectedResultException $e) {
                    $parent = null;
                }

                $variantMasterIdCache[$product->getVariantMasterId()] = $parent;
            }

            $ref = $variantMasterIdCache[$product->getVariantMasterId()];
            if ($ref) {
                try {
                    $ref = $this->getEntityManager()->getReference(Product::class, $ref);
                } catch (ORMException $e) {
                    $ref = null;
                }
            }

            $product->setParent($ref);

            if (0 === ($i % $batchSize)) {
                $this->getEntityManager()->flush();
                $this->getEntityManager()->clear();
            }

            ++$i;
        }

        $this->getEntityManager()->flush();
    }
412362
private function loadParentLocations(ContentInfo $contentInfo)
    {
        $locations = $this->persistence->locationHandler()->loadLocationsByContent($contentInfo->id);
        $parentLocations = [];
        foreach ($locations as $location) {
            if ($location->depth > 0) {
                $parentLocations[] = $this->persistence->locationHandler()->load($location->parentId);
            }
        }

        return $parentLocations;
    }
651216
private function getChildIds($parentIds)
    {
        $qb = $this->createQueryBuilder('roleHierarchy');

        $qb->select('roleHierarchy.childRoleId')
            ->where($qb->expr()->in( 'roleHierarchy.parentRoleId', $parentIds))
            ->indexBy('roleHierarchy', 'roleHierarchy.childRoleId');

        $childRoleIds =  $qb->getQuery()->getArrayResult();

        return array_keys($childRoleIds);
    }
553008
public function getDrillDown(Models\TableParams $params, array $parentId = [])
    {
        $resource = 'drilldown';
        $params = $params->toArray();

        if (!empty($parentId)) {
            $params['parent_id'] = json_encode($parentId);
        }

        $response = $this->sendGetRequest($resource, $params);
        $dataResponse = new Models\DrillDown($response);
        return $dataResponse;
    }
580961
public function createContent($contentType, $fields, $parentLocationId)
    {
        $repository = $this->getRepository();
        $languageCode = self::DEFAULT_LANGUAGE;
        $content = $this->createContentDraft($parentLocationId, $contentType, $fields, $languageCode);
        $content = $this->contentService->publishVersion($content->versionInfo);

        return $content->contentInfo->mainLocationId;
    }
1288889
protected function processFullTextIndex($ids)
    {
        $fullTextIndexer = $this->indexerRegistry->get(\Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID);

        if (!is_array($ids)) {
            $ids = [$ids];
        }

        $parentIds  = $this->fullIndexer->getRelationsByChild($ids);
        $processIds = $parentIds ? array_merge($parentIds, $ids) : $ids;

        if (!$fullTextIndexer->isScheduled()) {
            if (!empty($processIds)) {
                $fullTextIndexer->reindexList($processIds);
            }
        }
    }
1206408
public function upsert($document, $parentPath = null)
    {
        $class     = $this->dm->getClassMetadata(get_class($document));
        $changeset = $this->uow->getDocumentChangeSet($document);

        if (!$class->isEmbeddedDocument) {
            $qb         = $this->dm->createQueryBuilder($class->name);
            $identifier = $class->createIdentifier($document);

            $qb->update();
            $qb->setIdentifier($identifier);
        } elseif ($parentPath === null) {
            throw new \InvalidArgumentException;
        }

        foreach ($changeset as $attributeName => $change) {
            if ($class->isIdentifier($attributeName)) {
                continue;
            }

            list($old, $new) = $change;

            $mapping            = $class->getPropertyMetadata($attributeName);
            $discriminatorValue = null;

            if ($mapping->embedded && $mapping->isOne()) {
                $embeddedClassName  = get_class($new);
                $embeddedClass      = $this->dm->getClassMetadata($embeddedClassName);
                $discriminatorValue = $embeddedClass->getEmbeddedDiscriminatorValue($mapping, $new);
                //@Many will set discriminator in updatePath
            }

            if ($class->isEmbeddedDocument) {
                $path = $parentPath->map($attributeName, $discriminatorValue);
            } else {
                $path = $qb->attr($attributeName, $discriminatorValue);
            }

            $this->updatePath($path, $old, $new, true);
        }

        // add discriminator if the class has one
        if ($class->discriminatorAttribute !== null) {
            if ($class->isEmbeddedDocument) {
                $path = $parentPath->map($class->discriminatorAttribute);
            } else {
                $path = $qb->attr($class->discriminatorAttribute);
            }

            $path->set(
                $class->discriminatorValue !== null
                    ? $class->discriminatorValue
                    : $class->name
            );
        }

        if ($this->class->isVersioned) {
            // Set the initial version. Only supported on top-level documents.

            $versionMapping = $this->class->getPropertyMetadata($this->class->versionAttribute);
            $nextVersion    = null;

            if ($versionMapping->type === Type::INT) {
                $nextVersion = max(1, (int)$versionMapping->getValue($document));
            } elseif ($versionMapping->isDateType()) {
                $nextVersion = new \DateTime();
            }

            $nextVersion = $versionMapping->getType()->convertToDatabaseValue($nextVersion);
            $versionMapping->setValue($document, $nextVersion);

            $qb->attr($versionMapping->name)->set($nextVersion);
        }

        //DynamoDB will upsert even if we only pass the id conditional with no UpdateExpression

        if (!$class->isEmbeddedDocument) {
            $qb->getQuery()->execute();
        }
    }