Multitenancy and PHPCR

46 views
Skip to first unread message

Rafał Muszyński

unread,
Dec 8, 2015, 8:35:26 AM12/8/15
to PHPCR User Group Mailinglist

Hi guys, 


could you help me to understand if making the multitenancy based on PHPCR workspaces is possible to do without much hassle and would you be so kind to direct me where to start? in Symfony and Doctrine ORM I could use event listener and filters to make sure I set tenant id all the time. How about PHPCR ? I know there is this workspace setting in Doctrine PHPCR Bundle:


doctrine_phpcr:

    session:

       workspace: default


I thought maybe it is possible somehow (how?) to set the diffrent workspace on runtime based on the current subdomain? and not using the default workspace.


Best Regards

David Buchmann

unread,
Dec 8, 2015, 11:56:16 AM12/8/15
to phpcr...@googlegroups.com
hi,

you can not change the workspace of a session at runtime. you can either
configure multiple workspace, or implement a service that acts as
factory for sessions and initializes them with the right workspace.

the recommended way (especially if the sites are not completely
separated but should share things) would be to use different root paths
based on the domain. that is, you can use one workspace but depending on
the tenant, you use different base paths for routing, content, menu and
so on. you can then easily have common areas that are accessible from
multiple sites.

however, as access control is not implemented with jackalope doctrine
dbal and can only be managed from a java client in jackrabbit, you would
need to be careful and might have an issue if you need to guarantee that
users can never see other sites.

hope that helps,
david

On 08.12.2015 14:30, Rafał Muszyński wrote:
> Hi guys,
>
>
> could you help me to understand if making the multitenancy based on
> PHPCR workspaces is possible to do without much hassle and would you be
> so kind to direct me where to start? in Symfony and Doctrine ORM I could
> use event listener and filters to make sure I set tenant id all the
> time. How about PHPCR ? I know there is this workspace setting in
> Doctrine PHPCR Bundle:
>
> *
> *
>
> *doctrine_phpcr:*
>
> **
>
> * session:*
>
> * workspace: default*
>
> *
> *
>
> I thought maybe it is possible somehow (how?) to set the diffrent
> workspace on runtime based on the current subdomain? and not using the
> default workspace.
>
>
> Best Regards
>
> --
> You received this message because you are subscribed to the Google
> Groups "PHPCR User Group Mailinglist" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to phpcr-users...@googlegroups.com
> <mailto:phpcr-users...@googlegroups.com>.
> To post to this group, send email to phpcr...@googlegroups.com
> <mailto:phpcr...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/phpcr-users.
> For more options, visit https://groups.google.com/d/optout.

--
Liip AG // Agile Web Development // T +41 43 500 39 80
CH-8005 Zurich // PGP 0xA581808B // www.liip.ch

Rafał Muszyński

unread,
Dec 8, 2015, 2:47:14 PM12/8/15
to PHPCR User Group Mailinglist
thank you David, that's really good advice, I get the point now.

Best,

Rafał Muszyński

unread,
Dec 14, 2015, 5:11:38 PM12/14/15
to PHPCR User Group Mailinglist
Hi David,

just one question according to your reply,

I have implemented some proof of concept that still needs some improvements based on your input. I have created the Repository Initializer (don't know if that's the right way to solve it) inside which I create proper paths which will be saved in the repository for each tenant (info about each tenant is fetched from the postgres database) so the example paths look like: /acme/client1/content, /acme/client2/content. So far it works as expected.

My nodes structure looks as follows: 

ROOT:
  acme:
    default:
      content:
      menu:
    client1:
      content:
        test-1:
        test-2:
        test-3:
      menu:

I'm just wondering if this is a proper way of doing it or maybe there is some easier/a proper way which you will recommend ?

Thanks,

On Tuesday, December 8, 2015 at 2:35:26 PM UTC+1, Rafał Muszyński wrote:

David Buchmann

unread,
Dec 15, 2015, 3:34:06 AM12/15/15
to phpcr...@googlegroups.com
hi,

that is the idea of the initializers, sounds right to me.
and the structure looks good to me. does it work fine for you, with
separating content between the different tenants?

cheers,david

On 14.12.2015 23:11, Rafał Muszyński wrote:
> Hi David,
>
> just one question according to your reply,
>
> I have implemented some proof of concept that still needs some
> improvements based on your input. I have created the Repository
> Initializer (don't know if that's the right way to solve it) inside
> which I create proper paths which will be saved in the repository for
> each tenant (info about each tenant is fetched from the postgres
> database) so the example paths look like:
> */acme/client1/content, **/acme/client2/content*. So far it works as
> expected.
>
> My nodes structure looks as follows:
>
> |
> ROOT:
> acme:
> default:
> content:
> menu:
> client1:
> content:
> test-1:
> test-2:
> test-3:
> menu:
> |
>
> I'm just wondering if this is a proper way of doing it or maybe there is
> some easier/a proper way which you will recommend ?
>
> Thanks,
>
> On Tuesday, December 8, 2015 at 2:35:26 PM UTC+1, Rafał Muszyński wrote:
>
> Hi guys,
>
>
> could you help me to understand if making the multitenancy based on
> PHPCR workspaces is possible to do without much hassle and would you
> be so kind to direct me where to start? in Symfony and Doctrine ORM
> I could use event listener and filters to make sure I set tenant id
> all the time. How about PHPCR ? I know there is this workspace
> setting in Doctrine PHPCR Bundle:
>
> *
> *
>
> *doctrine_phpcr:*
>
> **
>
> * session:*
>
> * workspace: default*
>
> *
> *
>
> I thought maybe it is possible somehow (how?) to set the diffrent
> workspace on runtime based on the current subdomain? and not using
> the default workspace.
>
>
> Best Regards
>
> --
> You received this message because you are subscribed to the Google
> Groups "PHPCR User Group Mailinglist" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to phpcr-users...@googlegroups.com
> <mailto:phpcr-users...@googlegroups.com>.
> To post to this group, send email to phpcr...@googlegroups.com
> <mailto:phpcr...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/phpcr-users.

Rafał Muszyński

unread,
Dec 15, 2015, 1:03:54 PM12/15/15
to PHPCR User Group Mailinglist
hi,

thanks for your reply.

So far separating the content between different tenants works fine when it comes to fetching the data from the database. I'm figuring out now, how to persist the data and keep the id/path based on current tenant as it doesn't work when it comes to persisting separated content per tenant.

I will try to split my code into separate repositories so it can be reused by others if possible. Here is the commit which introduces the repository initializer.

still work in progress though

Best,


On Tuesday, December 8, 2015 at 2:35:26 PM UTC+1, Rafał Muszyński wrote:

David Buchmann

unread,
Dec 16, 2015, 2:08:47 AM12/16/15
to phpcr...@googlegroups.com
hi,

yeah, i think repositories are the right way to go. when using the
object-oriented approach of phpcr-odm, its technically possible to
assign ids (= repository paths) to documents. but i prefer to use the
parent-and-name mapping to make sure the tree exists. when you always
attach your documents to a parent, you can be sure that they go into the
right subtree.

by the way, did you look at sulu.io? they build a cms on top of PHPCR
and some of the CMF components, and afaik also do multi-tenant.

cheers,david

On 15.12.2015 19:03, Rafał Muszyński wrote:
> hi,
>
> thanks for your reply.
>
> So far separating the content between different tenants works fine when
> it comes to fetching the data from the database. I'm figuring out now,
> how to persist the data and keep the id/path based on current tenant as
> it doesn't work when it comes to persisting separated content per tenant.
>
> I will try to split my code into separate repositories so it can be
> reused by others if possible. Here is the commit
> <https://github.com/takeit/web-renderer/commit/566d164c4070f23212b119cbb1b38ca278ed239e>
> which introduces the repository initializer.
>
> still work in progress though
>
> Best,
>
> On Tuesday, December 8, 2015 at 2:35:26 PM UTC+1, Rafał Muszyński wrote:
>
> Hi guys,
>
>
> could you help me to understand if making the multitenancy based on
> PHPCR workspaces is possible to do without much hassle and would you
> be so kind to direct me where to start? in Symfony and Doctrine ORM
> I could use event listener and filters to make sure I set tenant id
> all the time. How about PHPCR ? I know there is this workspace
> setting in Doctrine PHPCR Bundle:
>
> *
> *
>
> *doctrine_phpcr:*
>
> **
>
> * session:*
>
> * workspace: default*
>
> *
> *
>
> I thought maybe it is possible somehow (how?) to set the diffrent
> workspace on runtime based on the current subdomain? and not using
> the default workspace.
>
>
> Best Regards
>

Uwe Jäger

unread,
Dec 16, 2015, 2:12:30 AM12/16/15
to phpcr...@googlegroups.com
Hi,

you can also have a look at https://github.com/valiton/MultiSiteBundle, which we use in some of our projects although the bundle really lacks documentation ...

Cheers,
Uwe

To unsubscribe from this group and stop receiving emails from it, send an email to phpcr-users...@googlegroups.com.
To post to this group, send email to phpcr...@googlegroups.com.

Rafał Muszyński

unread,
Dec 16, 2015, 5:24:10 AM12/16/15
to PHPCR User Group Mailinglist
hi,

@david thanks for the advice and no, I didn't know about the sulu.io but I will take a look at that for sure.

@uwe thanks, I will check that bundle, the lack of the documentation should not be a problem.


Best,
Rafał
Reply all
Reply to author
Forward
0 new messages