-
Notifications
You must be signed in to change notification settings - Fork 16
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
Comments
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. |
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? |
Same issue here, Did you guys solve it ? |
@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. |
@Berdir Could you provide an example of services.redis.yml and how do you include it conditionally? Thanks |
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. |
Did you include it on I'm using platform.sh as well. I tried with services but still having the same issues |
I've fixed it by adding this piece of code: $class_loader->addPsr4('Drupal\redis', DRUPAL_ROOT . '/sites/all/modules/redis/src'); |
We ended up solving this by having our setup script basically do:
And doing a |
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). |
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. |
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. |
Soo how about simply documenting the best practices? |
I agree that we should document it |
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?
The text was updated successfully, but these errors were encountered: