Skip to content

Custom node type phpcr:managed

dbu edited this page Apr 9, 2011 · 17 revisions

What are NodeTypes

JCR defines node types which can be thought of a kind of schema for the repository's nodes. These types define the properties and children a node can have. JCR defines a set of node types that can be readily used. Some node types like nt:file restrict the set of allowed properties others like nt:unstructured allow any kind of properties and child nodes.

Why a custom node type

The PHPCR ODM stores with every node the alias of the document the node corresponds to. Therefore it adds a property named phpcr:alias to the node. If you use a node type like nt:file that does not allow free properties the node can not be saved when there are additional properties. Since the ODM uses the information stored in the property to construct the proper class when a node is read we need to find a way to store that property with all nodes managed by the ODM.

Node type phpcr:managed

The node type phpcr:managed defines that property. When this node type is registered with the repository we can simply add that type to the node when the node is created.

How to register that node type

Due to a limitation of the current (2.2.5) Jackrabbit implementation we cannot register a node type remotely, e.g. using Jackalope. There is currently a patch available that implements that functionality. In order to use it, you need to either build your own jackrabbit from https://github.com/uwej711/jackrabbit/tree/JCR-2454-PROPFIND or get it readily compiled from https://github.com/uwej711/phpcr-odm/wiki/files/jackrabbit-standalone-2.2.6-SNAPSHOT.jar (david had problems downloading this 33M file from github and thus uploaded it here too: https://fosswiki.liip.ch/display/jackalope/Jackrabbit+with+fixes).

Then get the node definition for phpcr:managed from https://github.com/uwej711/phpcr-odm/wiki/files/phpcr.cnd or create file with the following content:

<phpcr='http://www.doctrine-project.org/phpcr-odm'>
[phpcr:managed]
  mixin
  - phpcr:alias (STRING)

Once you have your patched jackrabbit running, you can use the command line tool from phpcr (bin/phpcr) to register the node type (once it is set up properly, see Command line tool configuration).

bin/phpcr odm:phpcr:register-node-types <node-type-file>

TODO: provide a nice symfony command in the phpcr odm bundle which reads the configuration from the phpcr-odm.