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

CRM-18231 Environment variables #8724

Merged
merged 3 commits into from
Sep 3, 2017

Conversation

Edzelopez
Copy link
Contributor

@Edzelopez Edzelopez commented Jul 19, 2016

@Edzelopez Edzelopez changed the title [DO NOT MERGE - Submitted to facilitate testing] CRM-18231 Environment variables [ready for review by core team] CRM-18231 Environment variables Jul 21, 2016
@Edzelopez
Copy link
Contributor Author

jenkins, retest this please

@Edzelopez
Copy link
Contributor Author

Could one of the admins please verify this functionality?

@JoeMurray
Copy link
Contributor

@pradpnayak please test this. We should when ready close and resubmit a cleaner one rather than squashing. This should go in for 4.7.11

@@ -21,3 +22,14 @@ INSERT INTO
`civicrm_option_value` (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`)
VALUES
(@option_group_id_ext, {localize}'{ts escape="sql"}odt{/ts}'{/localize}, @option_group_id_ext_val+1, 'odt', NULL, 0, 0, @option_group_id_ext_wt+1, 0, 1, 1);

-- CRM-18231
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to move to 4.7.11 as RC for 4.7.10 has been cut

@seamuslee001
Copy link
Contributor

Also bin/regen.sh needs to be run to update civicrm_generated.mysql

@monishdeb monishdeb force-pushed the CRM-18231 branch 4 times, most recently from c6c1db3 to 89d6fd1 Compare April 28, 2017 17:29
@monishdeb
Copy link
Member

  • PR commits has been squashed into one
  • upgrade code is shifted from 4.7.10 to 4.7.20 sql script
  • included regen changes

@eileenmcnaughton eileenmcnaughton changed the title [ready for review by core team] CRM-18231 Environment variables [ready for review] CRM-18231 Environment variables May 3, 2017
@colemanw
Copy link
Member

Sorry @monishdeb this slipped through the cracks and it needs rebasing again. I'll get it reviewed/merged this cycle. Thanks.

@monishdeb
Copy link
Member

@colemanw I have rebased it!

$options = civicrm_api3('Setting', 'getoptions', array(
'field' => $setting,
));
if (array_key_exists('optionGroupName', $props['pseudoconstant'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getoptions should do this - & if it doesn't get label then I feel like we should address that (possibly as an option on the call)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(although you could probably settle for name for this PR & punt that)

public function postProcess() {
$params = $this->controller->exportValues($this->_name);

if ($params['environment'] != 'Production') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be an ontoggle function in the definition of the setting

@eileenmcnaughton
Copy link
Contributor

@colemanw this slipped through the cracks again. I did a quick read & this seems superficially good. I think it got stalled on whether it could be perfect. I made a couple of comments & it needs re-basing but I think it would be good to give a clear steer on what would get this over the line.

I also wonder if this could be seen as experimental at first, since it is not expected to affect production environments but I suspect once merged people will have some ideas to change it.

pinging @xurizaemon for input

if (defined('CIVICRM_ENVIRONMENT')) {
$element->freeze();
CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong to me. This function is a generic form generator (in a class extended by 14 child classes) and you're making the assumption that all select elements are the environment setting.

@eileenmcnaughton
Copy link
Contributor

@colemanw I see you picked up something that needs fixing - what's your big picture on this pr?

CRM_Core_OptionGroup::values($pseudoconstant['optionGroupName'], FALSE, FALSE, TRUE),
$params, 'Setting', 'getoptions'
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton reason to add this code is we cannot call CRM_Core_Pseudoconstant::get(..) OR buildOptions here as it needs DAO/BAO name to be passed either as parameter or class respectively as stated above at line 156.

@monishdeb
Copy link
Member

@eileenmcnaughton @colemanw I have made additional fixes as per comment and rebased the PR as it gone stale. Can you please check now?

@eileenmcnaughton
Copy link
Contributor

@colemanw I think the latest fixes address the issues raised so far so what do we still need to consider?

@eileenmcnaughton
Copy link
Contributor

@monishdeb test fail seems related

@monishdeb
Copy link
Member

@eileenmcnaughton yup fixed it.

@monishdeb monishdeb force-pushed the CRM-18231 branch 2 times, most recently from 9f42e89 to 90faa8e Compare August 29, 2017 16:34
if ($setting == 'environment' && defined('CIVICRM_ENVIRONMENT')) {
$element->freeze();
CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think this code belongs in theCRM_Admin_Form_Setting_Debugging class. After it calls parent::buildQuickform() it can do something like:

if (defined('CIVICRM_ENVIRONMENT')) {
  $element = $this->getElement('environment');
  $element->freeze();
  CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info');
}

@colemanw
Copy link
Member

@eileenmcnaughton this looks good to me.
@monishdeb can you please make that last change & then we're good to merge.

@colemanw
Copy link
Member

Not sure why a bunch of mailing tests just failed.
@civicrm-builder retest this please.

@monishdeb
Copy link
Member

Yeah, annoying test failures, that runs clean on local :(

@colemanw
Copy link
Member

Oh I see why they are related:

Failure in api call for job process_mailing: Job has not been executed as it is a Development (non-production) environment.

@monishdeb
Copy link
Member

Yup, reason why I set the environment setting to Production here But still its failing only on Jenkins not on local. Need to dig further to fix those test failures.

@eileenmcnaughton
Copy link
Contributor

Jenkins is still grumpy

@seamuslee001
Copy link
Contributor

@eileenmcnaughton i note that Jenkins appears to now be happy with this PR

@eileenmcnaughton eileenmcnaughton changed the title [ready for review] CRM-18231 Environment variables CRM-18231 Environment variables Sep 3, 2017
@eileenmcnaughton
Copy link
Contributor

Looks like @colemanw said this was ready to merge with one change, now made, so merging - thanks @seamuslee001

@eileenmcnaughton eileenmcnaughton merged commit f7a4b13 into civicrm:master Sep 3, 2017
$values = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME, 'environment');
$this->assertEquals('Staging', $values);

define('CIVICRM_ENVIRONMENT', 'Development');
Copy link
Member

@totten totten Sep 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(a) It's not safe for tests to call define() (at least, given the standard headless test environment). Trivially, suppose this test runs twice in a row. The second time, it will fail. Less trivially, it makes the test environment harder to predict. Compare:

  • When you run CRM_AllTests, any earlier tests (like CRM/Activity/**Test.php) run in an open-ended environment. (The default appears to be Production.)
  • When you run CRM_AllTests, any later tests (like CRM/Utils/**Test.php) are unalterably pegged to the Development environment.
  • When you run any test by itself (like CRM/Utils/**Test.php), you again have an open-ended environment (where the default is Production).
  • Consequently, tests will some of the time run in Production and some of the time in Development.
  • (Edit: Also, if the dev machine has its own define(), then this test will crash on trying to modify it.)

(b) Does it actually help to provide special handling for this setting (define(), CRM_Core_Config::environment()) rather than vanilla settings ($civicrm_setitings, Civi::settings()->get('environment'))?

  • For example, if the reason for the define() is that you want to be able to hard-code a value in civicrm.settings.php... then that's already handled by setting $civicrm_settings['domain']['environment']. (Note: Recall that in 4.7 you don't need to index by the DEVELOPER_PREFERENCES_NAME or whatever -- they're all just aliases for domain.)
  • On the other hand, if the setting is boot critical (meaning that it must be available as part of the early initialization of the settings/extensions/container system), then maybe it is needed. (But I'd really curious to know why it's boot-critical -- nothing pops while reading.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My immediate thinking here is that what the test here is trying to prove is that if there is a value set in civicrm.settings.php that it overrides everything else. so you have a method set using essentially Civi::settings()->set to set the value to staging but then someone is then overriding that by setting Development in civicrm.settings.php However i'm thinking that the style at https://github.com/civicrm/civicrm-core/pull/8724/files#diff-d392832fe610e31e06039270b3a100e6R546 seems to be more robust way of testing civicrm.settings.php

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 check Tim's comment about getMandatory - it makes me happy to see that

@eileenmcnaughton
Copy link
Contributor

ouch @monishdeb @Edzelopez can you look at @totten's comments & submit a follow up?

@totten are your concerns serious enough for us to revert if not resolved by the time the rc is released?

@eileenmcnaughton
Copy link
Contributor

Also re-reading - why are we adding the define in at all? ie. you can override settings in an unover-ridable way in the settings file currently - but perhaps we don't have a method to detect that?

@totten
Copy link
Member

totten commented Sep 3, 2017

For determining if the setting has been overridden, I think one can change the test:

if (defined('CIVICRM_ENVIRONMENT') ...

if (Civi::settings()->getMandatory('environment') !== NULL) ...

@eileenmcnaughton
Copy link
Contributor

nice!

@MegaphoneJon
Copy link
Contributor

Note that this PR introduced a regression, see here:
#11417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants