0

I am currently working on an internal project that would host a Drupal multisite platform.

For this, I am in the process of creating a site_manager module that will be running in the "main" Drupal instance, within the multisite setup.

Now, I want to be able to run a lot of functions in the context of a specific subsite.

For example: I want to run a cache_clear_all() or a module_enable() in a subsite.

When I call these functions, it will always run the functions in the current site's context (the "main" Drupal instance).

I have tried to use db_set_active() to resolve this, but no luck. It will always run it in the current "main" site.

To resolve the problem I started implementing a custom class that holds methods for the actions I want to perform, that fire custom db_query() implementations...

It works, but that cannot be the cleanest way to do this... Clearing the cache tables manually via db_query does not seem like the best way to do this, especially when you know that just calling cache_clear_all() should do the trick, when ran in the correct context.

Some research brought me here: Programmatically create user in another Drupal site But I don't really see how this would work, because I want the platform to be extendible,so that I can add functions later.

I could try to setup some kind of "client" module that listens for calls from the main site or something like this?

EDIT

After doing some additional research, I am looking into the possibilities of XML-RPC or some kind of webservice (json) that might do the trick as well.

It might be good to note that I would like to find a sustainable solution when looking forward to D8...

Anyway, did any of you try something like this?

Thanks in advance!

0

Normally, you would execute these commands on particular sites with Drush and site aliases (drush sa lists the aliases). I do it all the time.

  • hmz, never used aliases before. worth looking into indeed. But can I call all drush functions from within code? (I want to avoid the exec() functions for sure ;-) ). Also, what is the platform expands over multiple servers? Can i maintain the aliases across servers? – Guardian Nov 23 '15 at 22:33
  • It seems like your use case is to log on to one Drupal site and execute code on other Drupal sites via UI actions. Is that accurate? – cilefen Nov 24 '15 at 13:49
  • Not really. I want to be able to control subsite 1 and subsite 2 (for example) from withing my "main" site (via code). So not via the UI. – Guardian Nov 24 '15 at 16:23
  • 1
    Drush is the easiest and most powerful way to execute commands on sites in a multisite. How you execute it is up to you. It supports remote site aliases and can also be executed with a tool like jenkins, as suggested in another answer, which is something I do all the time also. – cilefen Nov 24 '15 at 18:30
0

I would suggest to use jenkins for this case. With jenkins you can create as many jobs as you want and call over http request those jobs. In this case you will have a freedom in your commands.

  • Thanks for the reply. I am actually considering this as well. This does introduce an additional "dependency" of having a Jenkins server on-hand, but it would fix the issue. – Guardian Nov 24 '15 at 16:22
  • This answer does not answer the question because the question states that the proposed management must be 'running in the "main" Drupal instance, within the multisite setup.' – cilefen Nov 24 '15 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.