In Drupal 6 it was easy to configure the port and some other environment variables in settings.php
Since Drupal 7 now has support for multiple environments it has become harder to override these configurations.

We should add this support again to settings.php without changing our flexibility

Drupal 6 :

$conf['apachesolr_host']='localhost';
$conf['apachesolr_port']= '8080';
$conf['apachesolr_path']='/solr/core0';

Comments

nick_vh’s picture

Issue summary: View changes

Updated issue summary.

nick_vh’s picture

Issue summary: View changes

Added markup

phoenix’s picture

Here's an example how we used to set it in the settings.php with the drupal 6 module:

$conf['apachesolr_host'] = 'localhost';
$conf['apachesolr_port'] = '8983';
$conf['apachesolr_path'] = '/solr';
nick_vh’s picture

And the way it should be for D7

$conf['apachesolr_environment']['env_id']['name'] = 'Core1';
$conf['apachesolr_environment']['env_id']['url'] = 'http://localhost:8983/solr/core0';
$conf['apachesolr_environment']['env_id']['etc...'] = '...';
nick_vh’s picture

I was thinking to do this with some array_merge. The module loads these configurations from the settings.php after it loads it from the database. These are getting merged and everything is overridden as expected.

For the long term, or the hard part.. :
It would be perfect if we do not even do a query for the ones that we have set in the settings.php. But that seems a bit overkill for the few times we actually need it. There is already caching in place so I suspect that the first proposal is sufficient

jrbeeman’s picture

Just noting a use-case we'll want to make sure we handle:

Environment config can be stored in the database or in exportable data via a Feature. My opinion is that the settings.php data should override both database and feature data. @nick_vh, do you agree?

Example:

/**
 * Implements hook_apachesolr_environments().
 */
function myfeature_apachesolr_apachesolr_environments() {
  $export = array();

  $environment = new stdClass;
  $environment->api_version = 1;
  $environment->env_id = 'my_env_id';
  $environment->name = 'My Solr Environment';
  $environment->url = 'http://localhost:8093/solr/myenv';
  $environment->service_class = '';
  $environment->conf = array(
    'apachesolr_read_only' => '1',
  );
  $export['myfeature'] = $environment;

  return $export;
}

The following code in settings.php should override this feature:

$conf['apachesolr_environment']['my_env_id']['url'] = 'http://prod.solr.example.com/solr/myenv';

As a result, my customizations in settings.php could be quite small. Or, I could add entire environment definitions, should I choose to do so.

jrbeeman’s picture

Sorry, I need to clarify that my last comment was on an instance that has the latest patch in #1357588: follow-up for import (needs to be optionally available when ctools is enabled) applied, which allows the config to be exported.

Crell’s picture

It feels gross to add a third place (settings.php) that this value can come from (after DB and features export), but I don't think there's a better option given Drupal core's (lack of) support for exported configuration at present. Hopefully D8 will make this better, but for now I cannot think of a less-bad alternative.

jrbeeman’s picture

Status: Active » Needs review
StatusFileSize
new657 bytes

Here's a small patch that appears to do the job. Locally, it's working against 7.x-1.x as well as 7.x-1.x with #1357588: follow-up for import (needs to be optionally available when ctools is enabled) applied.

pwolanin’s picture

So... what's the use case?

nick_vh’s picture

To override settings of any environment in your settings.php. So you can have different environments for testing/staging/production while maintaining the same codebase

pwolanin’s picture

Well, you could also apply a SQL scrub?

Crell’s picture

We want to feature-ize the configuration, because other features (eg Views) will depend on the machine name, but if it's featurized then we cannot override the connection string per-site. That's the problem.

nick_vh’s picture

Status: Needs review » Needs work

jrbeeman, would you be available to write a test for this functionality? It could be as simple as assuming you have an array that could come from a settings.php (you should not create one) and then merge that and test the expected output in the UI.

pwolanin’s picture

You could set the global $conf to test?

jrigby’s picture

Would love to see this feature added. I rebuild dev and staging machines with prod data frequently and this would save me the trouble of reconfiguring the environments.

nick_vh’s picture

Status: Needs work » Needs review
StatusFileSize
new870 bytes
nick_vh’s picture

StatusFileSize
new1.66 KB

With a readme.txt adjustment

nick_vh’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Needs review » Patch (to be ported)

committed to 7.x-1.x

nick_vh’s picture

Status: Patch (to be ported) » Fixed

committed to 6.x-3.x

nick_vh’s picture

Status: Fixed » Closed (fixed)
alexkb’s picture

Is Crell's use case solved? : "We want to feature-ize the configuration, because other features (eg Views) will depend on the machine name, but if it's featurized then we cannot override the connection string per-site. That's the problem."By exporting the apache_search_page and not the apachesolr_environment, I still seem to get the feature flagged as "overridden". Does anyone else have this problem?

I ended up re-doing things, and it seems to be working ok now.

alexkb’s picture

Issue summary: View changes

Updated issue summary.

Guillermo.Larrosa’s picture

Issue summary: View changes

Is this supported at this moment on 7.x-1.x ? I can't seem to get it to work, and considering this issue is still open after five years I began to wonder if this actually work.

sjerdo’s picture

The correct way to use this is:

$conf['apachesolr_environments']['env_id']['name'] = 'Core1';
$conf['apachesolr_environments']['env_id']['url'] = 'http://localhost:8983/solr/core0';
$conf['apachesolr_environments']['env_id']['etc...'] = '...';

Note the conf variable: not apachesolr_environment but apachesolr_environments