Skip to content

[WIP] Persistence #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Admin/PageAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected function configureFormFields(FormMapper $formMapper)
->add('label', null, array('required' => false))
->add('title')
->add('createDate')
->add('addLocalePattern')
->add('body', 'textarea')
;
}
Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
Changelog
=========

* **2013-08-10**: Removed "tags" property, see: https://github.com/symfony-cmf/SimpleCmsBundle/issues/53
* **2013-08-08**:
* Seperate Multilang document now incorporated in single document
* `multilang.locales` config removed (use cmf_core.multilang.locales)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? I prefer each Bundle to have its own setting and rely on CoreBundle to ease handling for duplicate settings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does SimpleCmsBundle itself still do anything with locales? if not, there is no need to configure them. but maybe the routes with the automatic locale prefixing need it to put a requirement on _locale?

* `DataFixtures/LoadCmsData` renamed and moved to DataFixtures/Phpcr
* PHPCR documents moved from Document to Doctrine/Phpcr

Migration instructions:

1. Set "addLocalePattern" flag to existing MultilangPage documents:

````bash
./app/console doctrine:phpcr:nodes:update --query="SELECT * FROM [nt:unstructured] WHERE phpcr:class = \"Symfony\\Cmf\\Bundle\\SimpleCmsBundle\\Document\\MultilangPage\"" --apply-closure="\$node->setProperty('addLocalePattern', true);"
````

2. Rename classes:

````bash
export CMFNS="Symfony\\Cmf\\Bundle\\SimpleCmsBundle"
./app/console doctrine:phpcr:document:migrate-class \
$CMFNS"\\Document\\MultilangPage" \
$CMFNS"\\Doctrine\\Phpcr\\Page"
./app/console doctrine:phpcr:document:migrate-class \
$CMFNS"\\Document\\MultilangRedirectRoute" \
$CMFNS"\\Doctrine\\Phpcr\\MultilangRedirectRoute"
./app/console doctrine:phpcr:document:migrate-class \
$CMFNS"\\Document\\MultilangRoute" \
$CMFNS"\\Doctrine\\Phpcr\\MultilangRoute"
./app/console doctrine:phpcr:document:migrate-class \
$CMFNS"\\Document\\MultilangRouteProvider" \
$CMFNS"\\Doctrine\\Phpcr\\MultilangRouteProvider"
./app/console doctrine:phpcr:document:migrate-class \
$CMFNS"\\Document\\Page" \
$CMFNS"\\Doctrine\\Phpcr\\Page"
````

* **2013-08-04**: Changed name of Sonata route names / patterns - now /admin/cmf/simplecms/foo instead of /admin/bundle/simplecms/foo

1.0.0-beta3
Expand Down
13 changes: 13 additions & 0 deletions CmfSimpleCmsBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;

class CmfSimpleCmsBundle extends Bundle
{
Expand All @@ -14,5 +15,17 @@ public function build(ContainerBuilder $container)
if ($container->hasExtension('jms_di_extra')) {
$container->getExtension('jms_di_extra')->blackListControllerFile(__DIR__ . '/Controller/PageAdminController.php');
}

if (class_exists('Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass')) {
$container->addCompilerPass(
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
array(
realpath(__DIR__ . '/Resources/config/doctrine-model') => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Model',
realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr',
),
array('cmf_simple_cms.persistence.phpcr.manager_name')
)
);
}
}
}
9 changes: 0 additions & 9 deletions Controller/PageAdminController.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Symfony\Cmf\Bundle\SimpleCmsBundle\DataFixtures;
namespace Symfony\Cmf\Bundle\SimpleCmsBundle\DataFixtures\Phpcr;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
Expand All @@ -12,11 +12,13 @@

use Symfony\Cmf\Component\Routing\RouteObjectInterface;

abstract class LoadCmsData extends ContainerAware implements FixtureInterface, OrderedFixtureInterface
/**
* @deprecated: To be removed in 1.1
*/
abstract class AbstractLoadPageData extends ContainerAware implements FixtureInterface, OrderedFixtureInterface
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we shouldn't simply remove this class. Its a bit of a convenience hack, there are probably other libraries that do this sort of thing much better, and it isn't /that/ much harder to do this ad-hoc in the concrete class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it makes it very easy to get started. if we remove it we have to add it to the SE for example https://github.com/symfony-cmf/symfony-cmf-standard/blob/master/src/Acme/MainBundle/DataFixtures/PHPCR/LoadSimpleCmsData.php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however we could consider basing this on https://github.com/nelmio/alice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like a really cool library, +1 for adopting it in the SE / Sandbox and dropping this, if possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine for me

{
protected $defaultClass = array(
'multilangpage' => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangPage',
'page' => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page'
'page' => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page'
);

abstract protected function getData();
Expand Down
144 changes: 99 additions & 45 deletions DependencyInjection/CmfSimpleCmsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,87 +33,141 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration(new Configuration(), $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

$container->setParameter($this->getAlias() . '.basepath', $config['basepath']);
$container->setParameter($this->getAlias() . '.menu_basepath', PathHelper::getParentPath($config['basepath']));
$container->setParameter($this->getAlias() . '.uri_filter_regexp', $config['routing']['uri_filter_regexp']);
$this->loadRouting($config['routing'], $loader, $container);

if (isset($config['persistence'])) {
if (isset($config['persistence']['phpcr'])) {
$this->loadPhpcr($config['persistence']['phpcr'], $loader, $container);
$this->loadPhpcrRouting($config, $loader, $container);

if ($config['use_menu']) {
$this->loadPhpcrMenu($config, $loader, $container);
}
}
}
}

protected function loadRouting($config, XmlFileLoader $loader, ContainerBuilder $container)
{
$container->setParameter($this->getAlias() . '.uri_filter_regexp', $config['uri_filter_regexp']);

$loader->load('routing.xml');
$loader->load('migrator.xml');

$dynamic = $container->getDefinition($this->getAlias().'.dynamic_router');

if (!empty($config['generic_controller'])) {
$definition = new DefinitionDecorator('cmf_routing.enhancer_explicit_template');
$definition->replaceArgument(2, $config['generic_controller']);
$container->setDefinition($this->getAlias() . '.enhancer_explicit_template', $definition);
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_explicit_template')));
$container->setDefinition(
$this->getAlias() . '.enhancer_explicit_template',
$definition
);
$dynamic->addMethodCall('addRouteEnhancer', array(
new Reference($this->getAlias() . '.enhancer_explicit_template')
));
}
if (!empty($config['routing']['controllers_by_alias'])) {

if (!empty($config['controllers_by_alias'])) {
$definition = new DefinitionDecorator('cmf_routing.enhancer_controllers_by_class');
$definition->replaceArgument(2, $config['routing']['controllers_by_alias']);
$container->setDefinition($this->getAlias() . '.enhancer_controllers_by_class', $definition);
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_controllers_by_alias')));
$container->setDefinition(
$this->getAlias() . '.enhancer_controllers_by_class',
$definition
);
$dynamic->addMethodCall('addRouteEnhancer', array(
new Reference($this->getAlias() . '.enhancer_controllers_by_alias')
));
}
if (!empty($config['routing']['controllers_by_class'])) {

if (!empty($config['controllers_by_class'])) {
$definition = new DefinitionDecorator('cmf_routing.enhancer_controllers_by_class');
$definition->replaceArgument(2, $config['routing']['controllers_by_class']);
$container->setDefinition($this->getAlias() . '.enhancer_controllers_by_class', $definition);
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_controllers_by_class')));
$definition->replaceArgument(2, $config['controllers_by_class']);
$container->setDefinition(
$this->getAlias() . '.enhancer_controllers_by_class',
$definition
);
$dynamic->addMethodCall('addRouteEnhancer', array(
new Reference($this->getAlias() . '.enhancer_controllers_by_class')
));
}
if (!empty($config['generic_controller']) && !empty($config['routing']['templates_by_class'])) {

if (!empty($config['generic_controller']) && !empty($config['templates_by_class'])) {
$controllerForTemplates = array();
foreach ($config['routing']['templates_by_class'] as $key => $value) {
foreach ($config['templates_by_class'] as $key => $value) {
$controllerForTemplates[$key] = $config['generic_controller'];
}

$definition = new DefinitionDecorator('cmf_routing.enhancer_controller_for_templates_by_class');
$definition->replaceArgument(2, $controllerForTemplates);
$container->setDefinition($this->getAlias() . '.enhancer_controller_for_templates_by_class', $definition);

$container->setDefinition(
$this->getAlias() . '.enhancer_controller_for_templates_by_class',
$definition
);

$definition = new DefinitionDecorator('cmf_routing.enhancer_templates_by_class');
$definition->replaceArgument(2, $config['routing']['templates_by_class']);
$container->setDefinition($this->getAlias() . '.enhancer_templates_by_class', $definition);
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_controller_for_templates_by_class')));
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_templates_by_class')));
$definition->replaceArgument(2, $config['templates_by_class']);

$container->setDefinition(
$this->getAlias() . '.enhancer_templates_by_class',
$definition
);

$dynamic->addMethodCall('addRouteEnhancer', array(
new Reference($this->getAlias() . '.enhancer_controller_for_templates_by_class')
));
$dynamic->addMethodCall('addRouteEnhancer', array(
new Reference($this->getAlias() . '.enhancer_templates_by_class')
));
}
}

$generator = $container->getDefinition($this->getAlias().'.generator');
$generator->addMethodCall('setContentRepository', array(new Reference($config['routing']['content_repository_id'])));

$container->setParameter($this->getAlias() . '.manager_name', $config['manager_name']);
$routeProvider = $container->getDefinition($this->getAlias() . '.route_provider');
$routeProvider->replaceArgument(0, new Reference($config['manager_registry']));
$multilangRouteProvider = $container->getDefinition($this->getAlias() . '.multilang_route_provider');
$multilangRouteProvider->replaceArgument(0, new Reference($config['manager_registry']));

if (!empty($config['multilang'])) {
$container->setParameter($this->getAlias() . '.locales', $config['multilang']['locales']);
$container->setAlias('cmf_simple_cms.route_provider', 'cmf_simple_cms.multilang_route_provider');
if ('Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page' === $config['document_class']) {
$config['document_class'] = 'Symfony\Cmf\Bundle\SimpleCmsBundle\Document\MultilangPage';
}
}
protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $container)
{
// migrator is only for PHPCR
$loader->load('migrator.xml');

$container->setParameter($this->getAlias() . '.document_class', $config['document_class']);
// save some characters
$prefix = $this->getAlias() . '.persistence.phpcr';

if ($config['use_menu']) {
$this->loadMenu($config, $loader, $container);
}
$container->setParameter($prefix . '.basepath', $config['basepath']);

$container->setParameter($prefix . '.menu_basepath', PathHelper::getParentPath($config['basepath']));

if ($config['use_sonata_admin']) {
$this->loadSonataAdmin($config, $loader, $container);
} elseif (isset($config['sonata_admin'])) {
throw new InvalidConfigurationException('Do not define sonata_admin options when use_sonata_admin is set to false');
}

$container->setParameter($prefix . '.manager_name', $config['manager_name']);

$container->setParameter($prefix . '.document_class', $config['document_class']);
}

protected function loadPhpcrRouting($config, XmlFileLoader $loader, ContainerBuilder $container)
{
$loader->load('routing-phpcr.xml');
$prefix = $this->getAlias() . '.persistence.phpcr';

$routeProvider = $container->getDefinition($prefix.'.route_provider');
$routeProvider->replaceArgument(0, new Reference($config['persistence']['phpcr']['manager_registry']));
$container->setAlias($this->getAlias() . '.route_provider', $prefix.'.route_provider');

$generator = $container->getDefinition($this->getAlias().'.generator');
$generator->addMethodCall('setContentRepository', array(
new Reference($config['routing']['content_repository_id'])
));
}

protected function loadMenu($config, XmlFileLoader $loader, ContainerBuilder $container)
protected function loadPhpcrMenu($config, XmlFileLoader $loader, ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
if ('auto' === $config['use_menu'] && !isset($bundles['CmfMenuBundle'])) {
return;
}

$loader->load('menu.xml');
$loader->load('menu-phpcr.xml');
}

protected function loadSonataAdmin($config, XmlFileLoader $loader, ContainerBuilder $container)
Expand All @@ -123,10 +177,10 @@ protected function loadSonataAdmin($config, XmlFileLoader $loader, ContainerBuil
return;
}

$container->setParameter($this->getAlias() . '.admin.sort',
$container->setParameter($this->getAlias() . '.persistence.phpcr.admin.sort',
isset($config['sonata_admin'])
? $config['sonata_admin']['sort']
: false
? $config['sonata_admin']['sort']
: false
);

$loader->load('admin.xml');
Expand Down
48 changes: 27 additions & 21 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,47 @@ public function getConfigTreeBuilder()

$treeBuilder->root('cmf_simple_cms')
->children()
->enumNode('use_sonata_admin')
->values(array(true, false, 'auto'))
->defaultValue('auto')
->end()
->arrayNode('sonata_admin')

->arrayNode('persistence')
->children()
->enumNode('sort')
->values(array(false, 'asc', 'desc'))
->defaultValue(false)
->arrayNode('phpcr')
->children()
->scalarNode('enabled')->defaultNull()->end()
->scalarNode('basepath')->defaultValue('/cms/simple')->end()
->scalarNode('manager_registry')->defaultValue('doctrine_phpcr')->end()
->scalarNode('manager_name')->defaultNull()->end()
->scalarNode('document_class')->defaultValue('Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page')->end()

->enumNode('use_sonata_admin')
->values(array(true, false, 'auto'))
->defaultValue('auto')
->end()
->arrayNode('sonata_admin')
->children()
->enumNode('sort')
->values(array(false, 'asc', 'desc'))
->defaultValue(false)
->end()
->end()
->end()
->end()
->end()
->end()
->end()

->enumNode('use_menu')
->values(array(true, false, 'auto'))
->defaultValue('auto')
->end()
->scalarNode('document_class')->defaultValue('Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page')->end()
->scalarNode('generic_controller')->defaultValue('cmf_content.controller:indexAction')->end()
->scalarNode('basepath')->defaultValue('/cms/simple')->end()
->scalarNode('manager_registry')->defaultValue('doctrine_phpcr')->end()
->scalarNode('manager_name')->defaultValue('default')->end()


->arrayNode('routing')
->fixXmlConfig('controller_by_alias', 'controllers_by_alias')
->fixXmlConfig('controller_by_class', 'controllers_by_class')
->fixXmlConfig('template_by_class', 'templates_by_class')
->addDefaultsIfNotSet()
->children()
->scalarNode('generic_controller')->defaultValue('cmf_content.controller:indexAction')->end()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved generic_controller under routing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be exactly the same as in cmf_routing - otherwise its really confusing. is there a way we could expose a method in RoutingBundle Configuration class to generate what it has there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or -- is there a way we could simply use the RoutingBundles dynamic router and so just use the native cmf_routing parameters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a separate instance of the service, as it might be configured
differently (like root path for routes). people could also only enable
the simplecms router and not the routingbundle one ideally.

->scalarNode('content_repository_id')->defaultValue('cmf_routing.content_repository')->end()
->scalarNode('uri_filter_regexp')->defaultValue('')->end()
->arrayNode('controllers_by_alias')
Expand All @@ -56,14 +70,6 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->arrayNode('multilang')
->fixXmlConfig('locale')
->children()
->arrayNode('locales')
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;

/**
* @PHPCRODM\Document
*
* provides multi language support when using MultilangRouteProvider
* Provides multi language support when using MultilangRouteProvider
*/
class MultilangRoute extends Route
{
Expand Down
Loading