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

deleteProperty() protected method

{@inheritDoc}
protected deleteProperty ( $path )
    protected function deleteProperty($path)
    {
        $this->assertLoggedIn();
        $nodePath = PathHelper::getParentPath($path);
        $nodeId = $this->getSystemIdForNode($nodePath);
        if (!$nodeId) {
            // no we really don't know that path
            throw new ItemNotFoundException("No item found at " . $path);
        }
        $query = 'SELECT props FROM phpcr_nodes WHERE id = ?';
        $xml = $this->getConnection()->fetchColumn($query, array($nodeId));
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->loadXml($xml);
        $found = false;
        $propertyName = PathHelper::getNodeName($path);
        foreach ($dom->getElementsByTagNameNS('http://www.jcp.org/jcr/sv/1.0', 'property') as $propertyNode) {
            if ($propertyName == $propertyNode->getAttribute('sv:name')) {
                $found = true;
                // would be nice to have the property object to ask for type
                // but its in state deleted, would mean lots of refactoring
                if ($propertyNode->hasAttribute('sv:type')) {
                    $type = strtolower($propertyNode->getAttribute('sv:type'));
                    if (in_array($type, array('reference', 'weakreference'))) {
                        $table = $this->referenceTables['reference' === $type ? PropertyType::REFERENCE : PropertyType::WEAKREFERENCE];
                        try {
                            $query = "DELETE FROM {$table} WHERE source_id = ? AND source_property_name = ?";
                            $this->getConnection()->executeUpdate($query, array($nodeId, $propertyName));
                        } catch (DBALException $e) {
                            throw new RepositoryException('Unexpected exception while cleaning up deleted nodes', $e->getCode(), $e);
                        }
                    }
                }
                $propertyNode->parentNode->removeChild($propertyNode);
                break;
            }
        }
        if (!$found) {
            throw new ItemNotFoundException("Node {$nodePath} has no property {$propertyName}");
        }
        $xml = $dom->saveXML();
        $query = 'UPDATE phpcr_nodes SET props = ? WHERE id = ?';
        $params = array($xml, $nodeId);
        try {
            $this->getConnection()->executeUpdate($query, $params);
        } catch (DBALException $e) {
            throw new RepositoryException("Unexpected exception while updating properties of {$path}", $e->getCode(), $e);
        }
    }