Jackalope\Transport\DoctrineDBAL\Client::syncNode PHP Method

syncNode() private method

Actually write the node into the database
private syncNode ( string $uuid, string $path, string $type, boolean $isNewNode, Property[] $props = [], array $propsData = [] ) : boolean | string
$uuid string node uuid
$path string absolute path of the node
$type string node type name
$isNewNode boolean new nodes to insert (true) or existing node to update (false)
$props Jackalope\Property[]
$propsData array
return boolean | string
    private function syncNode($uuid, $path, $type, $isNewNode, $props = array(), $propsData = array())
    {
        // TODO: Not sure if there are always ALL props in $props, should we grab the online data here?
        // TODO: PERFORMANCE Binary data is handled very inefficiently here, UPSERT will really be necessary here as well as lazy handling
        if (!$propsData) {
            $propsData = $this->propsToXML($props);
        }
        if (null === $uuid) {
            $uuid = $this->generateUuid();
        }
        if ($isNewNode) {
            list($namespace, $localName) = $this->getJcrName($path);
            $qb = $this->getConnection()->createQueryBuilder();
            $qb->select(':identifier, :type, :path, :local_name, :namespace, :parent, :workspace_name, :props, :numerical_props, :depth, COALESCE(MAX(n.sort_order), 0) + 1')->from('phpcr_nodes', 'n')->where('n.parent = :parent_a');
            $sql = $qb->getSql();
            try {
                $insert = "INSERT INTO phpcr_nodes (identifier, type, path, local_name, namespace, parent, workspace_name, props, numerical_props, depth, sort_order) " . $sql;
                $this->getConnection()->executeUpdate($insert, $data = array('identifier' => $uuid, 'type' => $type, 'path' => $path, 'local_name' => $localName, 'namespace' => $namespace, 'parent' => PathHelper::getParentPath($path), 'workspace_name' => $this->workspaceName, 'props' => $propsData['stringDom']->saveXML(), 'numerical_props' => $propsData['numericalDom'] ? $propsData['numericalDom']->saveXML() : null, 'depth' => PathHelper::getPathDepth($path), 'parent_a' => PathHelper::getParentPath($path)));
            } catch (\Exception $e) {
                if ($e instanceof \PDOException || $e instanceof DBALException) {
                    if (strpos($e->getMessage(), "SQLSTATE[23") !== false) {
                        throw new ItemExistsException('Item ' . $path . ' already exists in the database');
                    } else {
                        throw new RepositoryException('Unknown database error while inserting item ' . $path . ': ' . $e->getMessage(), 0, $e);
                    }
                } else {
                    throw $e;
                }
            }
            $nodeId = $this->getConnection()->lastInsertId($this->sequenceNodeName);
        } else {
            $nodeId = $this->getSystemIdForNode($path);
            if (!$nodeId) {
                throw new RepositoryException("nodeId for {$path} not found");
            }
            $this->getConnection()->update('phpcr_nodes', array('props' => $propsData['stringDom']->saveXML(), 'numerical_props' => $propsData['numericalDom'] ? $propsData['numericalDom']->saveXML() : null), array('id' => $nodeId));
        }
        $this->nodeIdentifiers[$path] = $uuid;
        if (!empty($propsData['binaryData'])) {
            $this->syncBinaryData($nodeId, $propsData['binaryData']);
        }
        $this->referencesToUpdate[$nodeId] = array('path' => $path, 'properties' => $propsData['references']);
        return $nodeId;
    }