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

[WIP] Persistence #55

merged 18 commits into from
Aug 14, 2013

Conversation

dantleech
Copy link
Member

Q A
Bug fix? no
New feature? no
BC breaks? yes
Deprecations? yes
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR symfony-cmf/symfony-cmf-docs#233

Implementing Model model ... FOR REVIEW

@dantleech
Copy link
Member Author

@dbu thinks that we should not support the *Base model for this bundle, and I tend to agree.

Another question is if we want to support other persistence layers here? I..e do I need to create cmf_menu.persistence.phpcr.route_provider parameter and such like it?

@dbu
Copy link
Member

dbu commented Aug 5, 2013

i am very much +1 for allowing other persistence layers. this is
actually simpler to support in orm than the routing + content things.

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.manager_name')
Copy link
Member

Choose a reason for hiding this comment

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

lets make this cmf_simple_cms.persistence.phpcr.manager_name to be consistent

Copy link
Member

Choose a reason for hiding this comment

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

+1

@dantleech
Copy link
Member Author

This is turning into a bit of an epic refactor - there sure is alot of DI code.

As we are removing Multilang and bundling that functionality by default, is there anything else we can do to make the SimpleCMS bundle more simple, especially in terms of the custom Routing setup? // cc @lsmith77

@dbu
Copy link
Member

dbu commented Aug 6, 2013

i propose to finalize what is in this PR and do further things in a new PR after this one is merged.

i think the main thing with the routes is about multilang, as per RoutingBundle the locale is part of the repository path, but for simplecms a special provider is used to extract the locale in the lookup (as we only have one route that is not translated). i guess we should keep that functionality, though maybe it could be simplified. right now we clone the dynamic router service definition and add all kind of things. not sure if there could be something simpler or more generic.

we should not just replace/reconfigure the normal dynamic router with this one, or the simplecms bundle could not be combined with things using routing bundle directly...

@lsmith77
Copy link
Member

lsmith77 commented Aug 6, 2013

agreed

@@ -12,7 +12,7 @@

use Symfony\Cmf\Component\Routing\RouteObjectInterface;

abstract class LoadCmsData extends ContainerAware implements FixtureInterface, OrderedFixtureInterface
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.

This seemed like a more appropriate name.

Copy link
Member

Choose a reason for hiding this comment

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

+1

@dantleech
Copy link
Member Author

ok, this now seems to work with Multilang. But it doesn't work with non-multilang.

e.g. the test fixtures create "/homepage", but this will only work with "/en/homepage".

The bundle doesn't work if we ommit multilang.locales.

I think we need someway to not add the static prefix /{locale} if locales are not set -- or even better if we can determine if the document has any translations or not. ??

@lsmith77
Copy link
Member

lsmith77 commented Aug 7, 2013

To be able to determine if the document has any translations we would need access to the DocumentManager. I guess what we could do is set something on the Route to enable multi lang for the given instance. I see 2 ways:

  1. we do this dynamically inside the RouteProvider
  2. we do this "semi" dynamically by modifying the state via a listener and then persisting a flag

<parameter key="cmf_simple_cms.generator_class">Symfony\Cmf\Bundle\RoutingBundle\Routing\ContentAwareGenerator</parameter>
<parameter key="cmf_simple_cms.phpcrodm_route_idprefix_listener_class">Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\IdPrefixListener</parameter>
<parameter key="cmf_simple_cms.enhancer_route_content_class">Symfony\Cmf\Component\Routing\Enhancer\RouteContentEnhancer</parameter>
<parameter key="cmf_simple_cms.enhancer_explicit_template_class">Symfony\Cmf\Component\Routing\Enhancer\FieldPresenceEnhancer</parameter>
<parameter key="cmf_simple_cms.enhancer_controllers_by_alias_class">Symfony\Cmf\Component\Routing\Enhancer\FieldMapEnhancer</parameter>
Copy link
Member Author

Choose a reason for hiding this comment

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

@dbu these enhancer class parameters do not seem to be used anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

if we have our own router, we also need our own enhancers i think.

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'm not really sure about the implications of what we currently do (using the RoutingBundle enhancers). But in anycase, these parameters are not used anywhere.

Are you suggesting that we create these enhancer services?

Copy link
Member

Choose a reason for hiding this comment

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

if we don't configure enhancers in the bundle config and everything works, lets drop them and see what happens :-) if we did not need them until now, lets drop them. not sure how the main content goes into the request without any enhancer though.

Copy link
Member Author

Choose a reason for hiding this comment

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

The enhancers seem to be implemented in the DI Extension with DefinitionDecorator classes, which are a bit foreign to me.

Copy link
Member

Choose a reason for hiding this comment

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

ah right. but guess we need them and can't drop them then. maybe add a

to those parameters then?

i think the decorator thing is to avoid instantiating the simple router
if its not used ever. we can't just tag the enhancers as the tag adds
them to the default dynamic router only. not sure if that could be
expressed in xml as well, if its static stuff.

@dantleech
Copy link
Member Author

ok, this is potentially done as far as I'm concerned, so good to review.

For the multilang stuff I have simply exposed the setAddLocalePattern method - I tried the alternative (only adding the locale if the document is translated) but this didn't work as all documents are "translated" and counting the number of translations seemed wrong (what if you delete a translation, should the URL for the page change just because there is only one left?).

@lsmith77
Copy link
Member

lsmith77 commented Aug 8, 2013

uhm .. the getLocales() method in the ODM only counts actual translations done via bindTranslation afaik. if not then maybe we should make it so. once things are like that then i would enable multilang behavior even if there is only one translation.

@@ -12,10 +12,9 @@

use Symfony\Cmf\Component\Routing\RouteObjectInterface;

abstract class LoadCmsData extends ContainerAware implements FixtureInterface, OrderedFixtureInterface
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

@dbu
Copy link
Member

dbu commented Aug 8, 2013

@lsmith77 you mean getLocalesFor? yes, that is only the locales of the current document. there is a method getDefaultLocalesOrder which should return all locales (though currently its missing to return the first locale)

or you could keep configuring the locales into this bundle if we need them.

@dbu
Copy link
Member

dbu commented Aug 8, 2013

the corebundle un-translate listener sets the locale to false if it removes translations. you could check getLocale() === false


$prefix = $this->getPrefix();
$path = substr(parent::getId(), strlen($prefix));
$path = $prefix.'/{_locale}'.$path;
Copy link
Member

Choose a reason for hiding this comment

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

should this not depend on the addLocalePattern flag?

Copy link
Member Author

Choose a reason for hiding this comment

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

We have already returned by now if that flag is set.

Copy link
Member

Choose a reason for hiding this comment

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

sorry, was not reading carefully

This was referenced Aug 10, 2013
@dantleech
Copy link
Member Author

Regarding the "automatic" prefixing of the locale in the URL depending on if it has bound translations or not - its not clear to me on how to proceed:

  • If we prefix the locale automatically, then the action of translating a document is irreversable, the user cannot remove the bound translation - even if done by accident in the admin interface.

What happens in this PR currently is this:

  • The user calls setAddLocalePattern on the document or they set this flag in the admin interface.

So the user chooses what happens, much like they would have choosen if they were going to use MultilangPage or Page, so, less magic.

And I wonder if there isn't some scope here for a new Translatable interface, e.g. MutableTranslatableStateInterface (why isn't there a neat word for enable/disable-able?) - which would allow us to explicitly enable / disable translation on a document via. a flag.

EDIT: Found one: http://en.wiktionary.org/wiki/activable#English :)

* **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?

@lsmith77
Copy link
Member

So I guess what we need now is:

  1. a rebase for this PR
  2. a migration script for the old document
  3. an integration with Alice in the SE + sandbox

@dbu
Copy link
Member

dbu commented Aug 14, 2013

lets keep the old way and do alice later, so that we can merge this PR soon


/**
* Extra values an application can store along with a page
*
* @PHPCRODM\String(assoc="")
*/
protected $extras;
Copy link
Member

Choose a reason for hiding this comment

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

we should init this with = array()

@dantleech
Copy link
Member Author

Migration instructions in CHANGELOG.md, they depend on https://github.com/doctrine/DoctrinePHPCRBundle/pull/84/files

@dantleech
Copy link
Member Author

ok, I have added a small test for the migrator and re-added DataFixtures base-class.

This is potentially good to merge I think.

lsmith77 added a commit that referenced this pull request Aug 14, 2013
@lsmith77 lsmith77 merged commit de0142c into master Aug 14, 2013
@lsmith77 lsmith77 deleted the persistence branch August 14, 2013 19:43
@lsmith77
Copy link
Member

looks like the tests need fixes for the non nullable fields

@lsmith77
Copy link
Member

ah .. is this fixed by changes in RoutingBundle?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants