Doctrine DBAL Repository Data Fixes

Date: 2013-05-21

If you have updated your CMF bundles lately, you may have problems with PHPCR nodes created with an older implementation. The renaming of the RoutingExtraBundle to RoutingBundle will affect any route nodes stored with this class name and cause them to fail. Also due to a new feature of storing the node depth, previously created nodes which don't have this value could cause issues, one of which is the tree browser failing to load in Sonata Admin.

The Doctrine DBAL MySQL backend can be fixed by executing this SQL which will patch up your existing data:

    -- Rewrite depth column by counting slashes in path column
    UPDATE phpcr_nodes SET depth = (LENGTH(path) - LENGTH(REPLACE(path, '/', ''))) where id > 0;
    -- Root path has only one slash but should be set as depth zero
    UPDATE phpcr_nodes SET depth = 0 WHERE path = '/';

    -- Fix route nodes that reference RoutingExtraBundle and rename to RoutingBundle
    UPDATE phpcr_nodes
    SET props = REPLACE(props, 'RoutingExtraBundle', 'RoutingBundle')
    WHERE props LIKE '%RoutingExtraBundle%'
    AND id > 0;

If you wish to revert the change to the class name in your nodes (possibly because you revert back to older bundles for some reason) you can use this SQL:

    -- Revert fix, rename to RoutingBundle back to RoutingExtraBundle
    UPDATE phpcr_nodes
    SET props = REPLACE(props, 'RoutingBundle', 'RoutingExtraBundle')
    WHERE props LIKE '%RoutingBundle%'
    AND id > 0;

If you don't like to execute this directly on your database I recommend you create a Doctrine migration using the fix SQL in the up() method, and the revert SQL in down().

prev next