Commands and implementations for common tasks for the PHP Content Repository (PHPCR) API.

Overview

PHPCR Utilities

Build Status Latest Stable Version Total Downloads

Commands and implementations for common tasks for the PHP Content Repository (PHPCR) API.

If you are using or implementing PHPCR you probably want some of the things in here.

PHPCR Users: Note that your PHPCR implementation probably already bundles the utils.

License

This code is dual licensed under the MIT license and the Apache License Version 2.0. Please see the file LICENSE in this folder.

Documentation

The utils bring you a couple of Commands you can use to interact with a PHPCR repository on the command line. Additionally we provide a couple of helper classes for common tasks.

Commands

There are a couple of useful commands to interact with a PHPCR repository.

To use the console, make sure you have initialized the git submodules of phpcr-utils, then copy cli-config.php.dist to cli-config.php and adjust it to your implementation of PHPCR. Then you can run the commands from the phpcr-utils directory with ./bin/phpcr NOTE: If you are using PHPCR inside of Symfony, the DoctrinePHPCRBundle provides the commands inside the normal Symfony console and you don't need to prepare anything special.

To get a list of the available commands, run bin/phpcr or set the commands up in your application. Running bin/phpcr help outputs the documentation of that command.

Helper Classes

The helper classes provide implementations for basic common tasks to help users and implementers of PHPCR. They are all in the namespace PHPCR\Util

PathHelper

Used to manipulate paths. Implementations are recommended to use this, and applications also profit from it. Using dirname and similar file system operations on paths is not compatible with Microsoft Windows systems, thus you should always use the methods in PathHelper.

NodeHelper

This helper has some generally useful methods like one to generate empty nt:unstructured nodes to make sure a parent path exists. It also provides some useful helper methods for implementations.

UUIDHelper

This little helper is mainly of interest for PHPCR implementers. It generates valid Universally Unique IDs and can determine whether a given string is a valid UUID. We recommend all implementations to use this implementation to guarantee consistent behaviour.

Note

You can use ramsey/uuid library to generate UUIDs. In this case, install it using Composer and generating UUIDs will be taken over by ramsey/uuid.

QOM QueryBuilder

The QueryBuilder is a fluent query builder with method names matching the Doctrine QueryBuilder on top of the QOM factory. It is the easiest way to programmatically build a PHPCR query.

Query Object Model Converter

In the PHPCR\Util\QOM namespace we provide, implementation-independant code to convert between SQL2 and QOM. Sql2ToQomQueryConverter parses SQL2 queries into QOM . QomToSql2QueryConverter generates SQL2 out of a QOM.

TraversingItemVisitor

This ItemVisitorInterface implementation is a basic implementation of crawling a PHPCR tree. You can extend it to define what it should do while crawling the tree.

Comments
  • Expand references in phpcr:dump

    Expand references in phpcr:dump

    This PR expands reference in the PHPCR dump to change:

    ./app/console doctrine:phpcr:dump /cms/chronology --props 
      2011-01-20:
        - references = Array(    [0] => 78b6f31b-f72a-4514-8f9d-b6e4a6786134    [1] => 896a3903-2614-4f8d-
    8543-0758022aaa4d    [2] => 43d60...
        - phpcr:classparents = Array()
        - phpcr:class = DTL\TravelBundle\Document\ChronoDate
    

    to

    ./app/console doctrine:phpcr:dump /cms/chronology --props --expand-references
      2011-01-20:
        - references = 
           - ref: /cms/content/DTLs Blog/aut-molestiae-rerum-eum-eius
           - ref: /cms/media/e6d2cab1959d05eeeec8ebe6bb3f1f3068e89f4e.jpeg
           - ref: /cms/media/49c33d6063f1ad0f3d4a3aa7d09b986c4ccddd02.jpeg
           - ref: /cms/media/34f453a6b65d58345e1ff639b5714da451698178.jpeg
        - phpcr:classparents = Array()
        - phpcr:class = DTL\TravelBundle\Document\ChronoDate
    

    This is really good for debugging, not so sure on the name of the option however. I also wonder if we shouldn't list array properties in a similar way.

    opened by dantleech 24
  • [RFC] Added `--apply-closure` option

    [RFC] Added `--apply-closure` option

    This option gives us a very quick and flexible solution for migrations:

    ./bin/phpcr phpcr:nodes:update --query="SELECT * FROM [nt:unstructured] WHERE ..." --apply-closure="function ($session, $node) { if (null !== $node->getProperty('url')) { $node->setProperty('linkType', 'externalUrl'); }"
    

    What do people think?

    opened by dantleech 22
  • Qomf shortcut

    Qomf shortcut

    I have added a shortcut for ->getQOMFactory(), ->qomf() which is more analogous to the ORM's ->expr() shortcut.

        $qb->orWhere($qb->qomf()->comparison(
            $qb->qomf()->propertyValue('blog'),
            QOMConstants::JCR_OPERATOR_EQUAL_TO,
            $qb->qomf()->literal('My Blog')
        ));
    

    rather than:

                $qomf = $qb->getQOMFactory();
                $qb->orWhere($qomf->comparison(
                    $qomf->propertyValue('blog'),
                    Constants::JCR_OPERATOR_EQUAL_TO,
                    $qomf->literal($options['blog_uuid'])
                ));
    

    What do you think?

    Do you think it would be correct to add a shortcut for the Constants aswell?

      $qb->qomf()->operator('equal_to'); // or
      $qb->constrants('operator_equal_to'); // or
      $qb->operator('equal_to');
    
    opened by dantleech 21
  • Fixed CND parsing under Windows OS

    Fixed CND parsing under Windows OS

    CND data was not correctly parsed while using Windows OS. The issue was caused by the different line endings between the operating systems.

    I came up with a fix and updated the unit tests to test both Windows and Unix line endings.

    I've found some discrepancies inside the FileReader class, so it is updated as well.

    This commit fixes: https://github.com/symfony-cmf/symfony-cmf-standard/issues/21

    opened by dinamic 15
  • Fixing the string tokenization

    Fixing the string tokenization

    In the current version of the scanner, the scanner splits the string by spaces and then in a second pass it just gets the spaces in order to put the strings back together in the QueryConverter. This doesn't make much sense and can be very harmful to bigger queries. (as we found out even preg_match has a size limitation).

    After this merge request it parses the strings in the query directly into one token which also simplifies the QueryConverter.

    opened by mamazu 12
  • [WIP] Workspace Node Update Command and fixes

    [WIP] Workspace Node Update Command and fixes

    • This command updates multiple nodes in a workspace based on a given SQL query.
    ./bin/phpcr workspace:node:update "SELECT FROM nt:unstructred" --set-prop=foo=bar --add-mixin=some:mixin
    

    Follows same options as node:touch. There is also room for adding a workspace:node:remove command for selectively removing nodes from a workspace.

    Also some refactoring.

    opened by dantleech 12
  • Use rhumsaa/uuid if available

    Use rhumsaa/uuid if available

    fixes jackalope/jackalope-doctrine-dbal#298

    Even better will be to use rhumsaa/uuid library, imho (so I added it). openssl_random_pseudo_bytes function was failing on PHP 5.3.3.

    Thus, this PR also fixes #120

    opened by takeit 11
  • Fixed parser so that square brackets count as delimiters

    Fixed parser so that square brackets count as delimiters

    This is an "enabling" improvement which allows me to use the parser to parse things like:

    UPDATE [foo] SET foo = ['foo','bar',baz'];
    

    Square brackets are delimiters in JCR-SQL2 (right?) so I think this is valid without compromise.

    opened by dantleech 11
  • properly use the cli helper

    properly use the cli helper

    we should not create an instance of the phpcr_cli helper manually. i wonder why we even have both PhpcrHelper and PhpcrCliHelper - can we just merge the additional functionality into PhpcrHelper instead? /cc @dantleech

    bug console 
    opened by dbu 11
  • Adding QomToSQL1Converter

    Adding QomToSQL1Converter

    This adds a generic Qom to SQL1 Convertor like the SQL2 one to be used in jackalope-jackrabbit for letting the the QOM decide which SQL engine should be used

    See also:

    https://github.com/jackalope/jackalope/pull/115 https://github.com/jackalope/jackalope-jackrabbit/pull/17

    opened by chregu 11
  • [RFC] Reorganizing command names

    [RFC] Reorganizing command names

    This is just an proof of concept PR, so basically I propose to renmae the classes as follows:

    ./NodeMoveCommand.php
    ./NodeRemoveCommand.php
    ./NodeTouchCommand.php
    ./NodeTypeListCommand.php
    ./NodeTypeRegisterCommand.php
    ./WorkspaceCreateCommand.php
    ./WorkspaceDumpCommand.php
    ./WorkspaceExportCommand.php
    ./WorkspaceImportCommand.php
    ./WorkspaceListCommand.php
    ./WorkspacePurgeCommand.php
    ./WorkspaceQueryCommand.php
    

    and that would then translate to the following command schema:

    phpcr:workspace:purge
    phpcr:workspace:import
    phpcr:workspace:query
    ...
    phpcr:node-type:register
    ...
    phpcr:node:touch
    ...
    

    Not sure if I have categorized things correctly, does dump,import|export etc belong in workspace?

    opened by dantleech 10
  • CndParser issue with PHP 7

    CndParser issue with PHP 7

    CndParser hangs on buggy CND, only with PHP 7

    $cnd = <<<EOT
    la /*
    EOT;
    

    revert https://github.com/phpcr/phpcr-api-tests/commit/6ca175b8048fd492088022cf3e2188236fc34706 to see that the fix works.

    opened by dbu 0
  • Sql1QueryConverter does not encapsulate property names in square brackets

    Sql1QueryConverter does not encapsulate property names in square brackets

    e.g. it produces the following:

    SELECT s FROM nt:unstructured WHERE i18n:de-changer = 11
    

    Which is invalid JCR-SQL2 it should be:

    SELECT s FROM nt:unstructured WHERE [i18n:de-changer] = 11
    

    This causes problems with Jackrabbit, but not doctrine-dbal which doesn't care.

    Note that this is also specifically a problem for PHPCRSH when we perform UPDATEs. Normally queries to Jackrabbit are passed directly - bypassing the phpcr-utils SQL2 generation.

    In PHPCRSH however we parse the UPDATE (and implicitly the SELECT) which reveals this issue.

    opened by dantleech 0
  • JCR-SQL2 parser does not parse queries which JOIN on a JOIN

    JCR-SQL2 parser does not parse queries which JOIN on a JOIN

    The following query cannot be parsed:

    SELECT * FROM [nt:unstructured] AS a 
        INNER JOIN [nt:unstructured] AS b ON ISCHILDNODE(b,a) 
        INNER JOIN [nt:unstructured] AS c ON ISCHILDNODE(c,b);
    
    opened by dantleech 0
  • potential bug with operator precedence

    potential bug with operator precedence

    we probably still have an issue with operator precedence for the NOT case.

    how does the query builder distinguish NOT(a OR b) from (NOT a) OR b? afaik NOT a OR b precedence would make it (NOT a) or b.

    see discussion in https://github.com/phpcr/phpcr-api-tests/pull/140/files#r20051310

    /cc @dantleech

    bug 
    opened by dbu 0
  • CND dumper generates invalid CND when re-editing a mixin

    CND dumper generates invalid CND when re-editing a mixin

    I'm not sure what the exact problem is with the following, but for example the query operators are not properly quoted (but fixing this does not make the CND valid):

    <mix='http://www.jcp.org/jcr/mix/1.0'>
    <nt='http://www.jcp.org/jcr/nt/1.0'>
    [mix:menuItem] > nt:unstructured
    orderable mixin query
    - label (String)
    mandatory jcr.operator.equal.to', 'jcr.operator.greater.than', 'jcr.operator.greater.than.or.equal.to', 'jcr.operator.less.than', 'jcr.operator.less.than.or.equal.to', 'jcr.operator.like', 'jcr.operator.not.equal.to
    - path (String)
    mandatory jcr.operator.equal.to', 'jcr.operator.greater.than', 'jcr.operator.greater.than.or.equal.to', 'jcr.operator.less.than', 'jcr.operator.less.than.or.equal.to', 'jcr.operator.like', 'jcr.operator.not.equal.to
    + nt:unstructured (mix:menuItem)
    
    bug 
    opened by dantleech 1
Releases(1.6.3)
Box of Tricks for common PrePress related tasks.

PrePress Tricks Library Box of Tricks for common PrePress related tasks. Table of Contents Purpose Installation Basic Usage Purpose If you have ever a

null 1 Jul 26, 2022
The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.

netz98 magerun CLI tools for Magento 2 The n98 magerun cli tools provides some handy tools to work with Magento from command line. Build Status Latest

netz98 758 Dec 28, 2022
Bind your interfaces to implementations automatically.

Laravel Auto Binder This package automatically binds interfaces to implementations in the Service Container, scanning the specified project folders. T

Michael Rubel 68 Dec 8, 2022
Port of the Java Content Repository (JCR) to PHP.

PHP Content Repository PHPCR This repository contains interfaces for the PHPCR standard. The JSR-283 specification defines an API for a Content Reposi

PHPCR 436 Dec 30, 2022
Dobren Dragojević 6 Jun 11, 2023
PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP language

php-text-analysis PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP l

null 464 Dec 28, 2022
Sitepackage for TYPO3 CMS that adheres to the recommended standards, maps all conceivable functional areas and contains examples for common use cases.

TYPO3 CMS Sitepackage This sitepackage sticks as closely as possible to the recommended standard and maps all conceivable functional areas. There are

Eric Bode 3 Dec 18, 2022
Open-source library used in Gigadrive projects with common PHP utilities

PHP Commons This library provides PHP utilities used in Gigadrive projects, provided for the open-source community. Functions are registered globally

Gigadrive UG 3 Nov 10, 2021
Examples of some common design patterns implemented in php

What is a Design Pattern? Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can c

Bakhtiyor Bahritidinov 4 Feb 11, 2022
Orangescrum is a simple yet powerful free and open source project management software that helps team to organize their tasks, projects and deliver more.

Free, open source Project Management software Introduction Orangescrum is the simple yet powerful free and open source project management software tha

Orangescrum 110 Dec 30, 2022
Rocket Web Prime theme based on Magento Blank that includes our most common customizations.

RW Prime - Magento 2 boilerplate theme RW Prime theme is based on Magento Blank and includes our most common customizations that we make on the majori

Rocket Web FED 37 Aug 8, 2022
Twig extensions for common navigation widgets for symfony.

Twig Navigation Extension This bundle provides a Twig extensions for common navigation widgets. Installation composer require m2mtech/twig-navigation-

Martin Mandl 1 Feb 23, 2022
Blacksmith is a code generation tool which automates the creation of common files that you'd typically create for each entity in your application.

Blacksmith is a code generation tool which automates the creation of common files that you'd typically create for each entity in your application.

Indatus 197 Dec 30, 2022
Simple PHP/Laravel app that displays Todoist tasks in a view designed for a Kindle Touch

productivity-dashboard Just a simple PHP/Laravel app that retrieves (so far) tasks from Todoist and displays them in a simple view designed for a Kind

null 7 Dec 9, 2022
Simple PHP/Laravel app that displays Todoist tasks in a view designed for a Kindle Touch

productivity-dashboard Just a simple PHP/Laravel app that retrieves (so far) tasks from Todoist and displays them in a simple view designed for a Kind

null 3 Dec 27, 2021
Execute time consuming tasks as late as possible in a request

Procrastinator for PHP: do stuff later A few classes to help you executing complicated tasks (like sending mails) later. Example using fastcgi_finish_

Lars Strojny 62 Apr 29, 2021
A Symfony bundle built to schedule/consume repetitive tasks

Daily runs Code style Infection PHPUnit Rector Security Static analysis A Symfony bundle built to schedule/consume repetitive tasks Main features Exte

Guillaume Loulier 98 Jan 4, 2023
Magento 2 specific tasks for Capistrano 3

Capistrano::Magento2 A Capistrano extension for Magento 2 deployments. Takes care of specific Magento 2 requirements and adds tasks specific to the Ma

David Alger 223 Dec 2, 2022
Easy management of Virtualization technologies including KVM, Xen, OpenVZ, Virtuozzo, and LXC/LXD including unified commands, monitoring, template management, and many more features.

ProVirted About Easy management of Virtualization technologies including KVM, Xen, OpenVZ, Virtuozzo, and LXC/LXD including unified commands, monitori

null 2 Aug 22, 2022