Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Latest commit

 

History

History
363 lines (251 loc) · 11.9 KB

phpcr-odm.rst

File metadata and controls

363 lines (251 loc) · 11.9 KB

DoctrinePHPCRBundle

The DoctrinePHPCRBundle provides integration with the PHP content repository and optionally with Doctrine PHPCR ODM to provide the ODM document manager in symfony.

.. index:: DoctrinePHPCRBundle, PHPCR, ODM

Tip

This reference only explains the Symfony2 integration of PHPCR and PHPCR-ODM. To learn how to use PHPCR refer to the PHPCR website and for Doctrine PHPCR-ODM to the PHPCR-ODM documentation.

Setup

See :doc:`/tutorials/installing-configuring-doctrine-phpcr-odm`

Configuration

Tip

If you want to only use plain PHPCR without the PHPCR-ODM, you can simply not configure the odm section to avoid loading the services at all. Note that most CMF bundles by default use PHPCR-ODM documents.

PHPCR Session Configuration

The session needs a PHPCR implementation specified in the backend section by the type field, along with configuration options to bootstrap the implementation. Currently we support jackrabbit, doctrinedbal and midgard2. Regardless of the backend, every PHPCR session needs a workspace, username and password.

Tip

Every PHPCR implementation should provide the default workspace, but you can choose a different one. There is the doctrine:phpcr:workspace:create command to initialize a new workspace. See also :ref:`reference-phpcr-commands`.

This username and password are what is used on the PHPCR layer in the PHPCR\SimpleCredentials. They will usually be different from the username and password used by midgard or Doctrine DBAL to connect to the underlying RDBMS where the data is actually stored.

If you are using one of the Jackalope backends, you can also specify options. They will be set on the Jackalope session. Currently this can be used to tune pre-fetching nodes by setting jackalope.fetch_depth to something bigger than 0.

.. configuration-block::

    .. code-block:: yaml

        # app/config/config.yml
        doctrine_phpcr:
            session:
                backend:
                    # see below for how to configure the backend of your choice
                workspace: default
                username: admin
                password: admin
                # options:
                #    key: value


PHPCR Session with Jackalope Jackrabbit

The only setup required is to install Apache Jackrabbit (see :ref:`installing Jackrabbit <tutorials-installing-phpcr-jackrabbit>`).

.. configuration-block::

    .. code-block:: yaml

        # app/config/config.yml
        doctrine_phpcr:
            session:
                backend:
                    type: jackrabbit
                    url: http://localhost:8080/server/

PHPCR Session with Jackalope Doctrine DBAL

This type uses Jackalope with a Doctrine database abstraction layer transport to provide PHPCR without any installation requirements beyond any of the RDBMS supported by Doctrine.

You need to configure a Doctrine connection according to the DBAL section in the Symfony2 Doctrine documentation.

.. configuration-block::

    .. code-block:: yaml

        # app/config/config.yml
        doctrine_phpcr:
            session:
                backend:
                    type: doctrinedbal
                    connection: doctrine.dbal.default_connection

Once the connection is configured, you can create the database and you need to initialize the database with the doctrine:phpcr:init:dbal command.

app/console doctrine:database:create
app/console doctrine:phpcr:init:dbal

Tip

Of course, you can also use a different connection instead of the default. It is recommended to use a separate connection to a separate database if you also use Doctrine ORM or direkt DBAL access to data, rather than mixing this data with the tables generated by jackaleope-doctrine-dbal. If you have a separate connection, you need to pass the alternate connection name to the doctrine:database:create command with the --connection option. For doctrine PHPCR commands, this parameter is not needed as you configured the connection to use.

PHPCR Session with Midgard2

Midgard2 is an application that provides a compiled PHP extension. It implements the PHPCR API on top of a standard RDBMS.

For installation and the exact meanings and supported values in the configuration options, see the official Midgard PHPCR documentation

.. configuration-block::

    .. code-block:: yaml

        # app/config/config.yml
        doctrine_phpcr:
            session:
                backend:
                    type: midgard2
                    db_type: MySQL
                    db_name: midgard2_test
                    db_host: "0.0.0.0"
                    db_port: 3306
                    db_username: ""
                    db_password: ""
                    db_init: true
                    blobdir: /tmp/cmf-blobs


Doctrine PHPCR-ODM Configuration

This configuration section manages the Doctrine PHPCR-ODM system. If you do not configure anything here, the ODM services will not be loaded.

If you enable auto_mapping, you can place your mappings in <Bundle>/Resources/config/doctrine/<Document>.phpcr.xml resp. .yml to configure mappings for documents you provide in the <Bundle>/Document folder. Otherwise you need to manually configure the mappings section.

If auto_generate_proxy_classes is false, you need to run the cache:warmup command in order to have the proxy classes generated after you modified a document. You can also tune how and where to generate the proxy classes with the proxy_dir and proxy_namespace settings. The the defaults are usually fine here.

You can also enable metadata caching.

.. configuration-block::

    .. code-block:: yaml

        # app/config/config.yml
        doctrine_phpcr:
            odm:
                configuration_id:     ~
                auto_mapping: true
                mappings:
                    <name>:
                        mapping:              true
                        type:                 ~
                        dir:                  ~
                        alias:                ~
                        prefix:               ~
                        is_bundle:            ~
                auto_generate_proxy_classes: %kernel.debug%
                proxy_dir:            %kernel.cache_dir%/doctrine/PHPCRProxies
                proxy_namespace:      PHPCRProxies

                metadata_cache_driver:
                    type:                 array
                    host:                 ~
                    port:                 ~
                    instance_class:       ~
                    class:                ~
                    id:                   ~



Translation configuration

.. index:: I18N, Multilanguage

If you are using multilingual documents, you need to configure the available languages. For more information on multilingual documents, see the PHPCR-ODM documentation on Multilanguage.

.. configuration-block::

    .. code-block:: yaml

        # app/config/config.yml
        doctrine_phpcr:
            odm:
                locales:
                    en:
                        - en
                        - de
                    de:
                        - de
                        - en


General Settings

If the jackrabbit_jar path is set, you can use the doctrine:phpcr:jackrabbit console command to start and stop jackrabbit.

You can tune the output of the doctrine:phpcr:dump command with dump_max_line_length.

.. configuration-block::

    .. code-block:: yaml

        # app/config/config.yml
        doctrine_phpcr:
            jackrabbit_jar:       /path/to/jackrabbit.jar
            dump_max_line_length:  120


Configuring Multiple Sessions

If you need more than one PHPCR backend, you can define sessions as child of the session information. Each session has a name and the configuration as you can use directly in session. You can also overwrite which session to use as default_session.

.. configuration-block::

    .. code-block:: yaml

        # app/config/config.yml
        doctrine_phpcr:
            session:
                default_session:      ~
                sessions:
                    <name>:
                        workspace:            ~ # Required
                        username:             ~
                        password:             ~
                        backend:
                            # as above
                        options:
                            # as above

If you are using the ODM, you will also want to configure multiple document managers.

Inside the odm section, you can add named entries in the document_managers.

.. configuration-block::

    .. code-block:: yaml

        odm:
            default_document_manager:  ~
            document_managers:
                <name>:
                    # same options as directly in odm, see above.
                    # you want to set a different session


Doctrine PHPCR Commands

All commands about PHPCR are prefixed with doctrine:phpcr and you can use the --session argument to use a non-default session if you configured several PHPCR sessions.

Some of these commands are specific to a backend or to the ODM. Those commands will only be available if such a backend is configured.

Use app/console help <command> to see all options each of the commands has.

  • doctrine:phpcr:workspace:create Create a workspace in the configured repository
  • doctrine:phpcr:workspace:list List all available workspaces in the configured repository
  • doctrine:phpcr:purge Remove all content from the repository
  • doctrine:phpcr:register-system-node-types Register system node types in the PHPCR repository
  • doctrine:phpcr:register-node-types Register node types in the PHPCR repository
  • doctrine:phpcr:fixtures:load Load data fixtures to your PHPCR database.
  • doctrine:phpcr:import Import xml data into the repository, either in JCR system view format or arbitrary xml
  • doctrine:phpcr:export Export nodes from the repository, either to the JCR system view format or the document view format
  • doctrine:phpcr:dump Dump the content repository
  • doctrine:phpcr:query Execute a JCR SQL2 statement
  • doctrine:phpcr:mapping:info Shows basic information about all mapped documents

Jackrabbit specific commands

If you are using jackalope-jackrabbit, you also have a command to start and stop the jackrabbit server:

  • jackalope:run:jackrabbit Start and stop the Jackrabbit server

Doctrine DBAL specific commands

If you are using jackalope-doctrine-dbal, you have a command to initialize the database:

  • jackalope:init:dbal Prepare the database for Jackalope Doctrine DBAL

Note that you can also use the doctrine dbal command to create the database.

Some example command runs

Running SQL2 queries against the repository

app/console doctrine:phpcr:query "SELECT title FROM [nt:unstructured] WHERE NAME() = 'home'"

Dumping nodes under /cms/simple including their properties

app/console doctrine:phpcr:dump /cms/simple --props=yes