Skip to content
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

Dependency issue with installing redis #13

Open
mroest opened this issue Feb 26, 2016 · 14 comments
Open

Dependency issue with installing redis #13

mroest opened this issue Feb 26, 2016 · 14 comments

Comments

@mroest
Copy link

mroest commented Feb 26, 2016

Hi,

Currently we trying to use redis cache (Drupal 8) while doing that we run into this installation issue.

We work we a team and multiple environments. We're doing a 'code driven' approach and deploy from git.

In order to enable the redis cache the module needs to be enabled first. After that you put the config in settings.php in order to use redis.
While deploying instances and/or doing a site install this is an issue. It fails since settings.php already contains the redis config before the module is enabled.

What is the preferred way in enabling redis cache when working in teams with multiple environments?

@Berdir
Copy link
Member

Berdir commented Feb 26, 2016

Good question. There's not much that we can do. It's not possible for code in settings.php to detect if a module is enabled or not.

I've had the same problem.

The factory in core could fall back to the default if the service can't be found.

@mroest
Copy link
Author

mroest commented Feb 28, 2016

I've noticed the memcache module has the same issue. Obviously the situation is far from ideal. Have you tried to work around this?

For example by changing the redis config in settings.php to something like $settings['redis.enable'] = TRUE; Then have an event subscriber that subscribes on the Kernel REQUEST event and sets for example the cache backend to the redis service when reis.enable is TRUE? Would that work?

@guiajlopes
Copy link
Contributor

Same issue here, Did you guys solve it ?

@Berdir
Copy link
Member

Berdir commented Apr 12, 2016

@mroest The settings configuration is already settings based, we don't gain anything by adding more settings I think? if you can set that, you can also just not set the cache backend settings.

For the services, I have them in a separate file (sites/default/services.redis.yml) that I conditionally include. Drupal core handles that, the list of services files makes up the key for the container).

The problem is that there's no way in settings.php to know if a module is enabled or not.

I guess that's where a service provider could be useful as there you have the module list. But that again can't set settings.

@guiajlopes
Copy link
Contributor

@Berdir Could you provide an example of services.redis.yml and how do you include it conditionally? Thanks

@Berdir
Copy link
Member

Berdir commented Apr 12, 2016

That's part of the module: https://github.com/md-systems/redis/blob/8.x-1.x/example.services.yml.

I use platform.sh, there i enable that file/line and the other configuration based on environment variables provided by them.

@guiajlopes
Copy link
Contributor

Did you include it on
if (!empty($_ENV['PLATFORM_RELATIONSHIPS']))
?

I'm using platform.sh as well. I tried with services but still having the same issues

@guiajlopes
Copy link
Contributor

I've fixed it by adding this piece of code:

$class_loader->addPsr4('Drupal\redis', DRUPAL_ROOT . '/sites/all/modules/redis/src');

@deviantintegral
Copy link

We ended up solving this by having our setup script basically do:

drush -y en redis && cp settings.redis.disabled.php settings.redis.php

And doing a file_exists() check to include the redis config in settings.php.

@rbayliss
Copy link

Just throwing this out there... If the classes were in a PHP library rather than a Drupal module, the classes would be autoloaded. The only reason I see for this to be a module is to display the status of the connection and to add some services to the container (which could be done in the site's services.yml file). Having this as a library that the module depends on would allow an "expert mode" configuration where the developer is responsible for setting up the services and the configuration, but wouldn't be required to have the module enabled at all. This would remove a pretty significant stumbling block for development teams.

Obviously, requiring the library for the module to function would only be possible if everyone is installing the module via Composer, because Drush installations or direct downloads from D.O. would fail to download the library (as far as I know).

@mirodietiker
Copy link
Member

I think it's strange to depend on a "module's" components/functionality while it is disabled. And libraries in general should be Drupal agnostic, right?

Are there some references or is there documentation how Drupal intends to handle such cases?

It's clear that d.o build infrastructure limitations is blocking us in many cases and this hopefully improves soonish.

@guiajlopes
Copy link
Contributor

You can solve this problem by just loading the module classes in your settings.php file like I said before

$class_loader->addPsr4('Drupal\redis', DRUPAL_ROOT . '/sites/all/modules/redis/src');

The problem is not that Drupal depends on a component/functionality that is disabled, it's just depending if you override on the settings.php, If you do so, you just need to load the Redis classes before.

@mirodietiker
Copy link
Member

Soo how about simply documenting the best practices?

@guiajlopes
Copy link
Contributor

I agree that we should document it

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

No branches or pull requests

6 participants