-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Conversation
Edzelopez
commented
Jul 19, 2016
•
edited by civicrm-builder
Loading
edited by civicrm-builder
- CRM-18231: Support safe migration from production to non-production instances
jenkins, retest this please |
Could one of the admins please verify this functionality? |
@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 |
There was a problem hiding this comment.
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
Also bin/regen.sh needs to be run to update civicrm_generated.mysql |
c6c1db3
to
89d6fd1
Compare
|
Sorry @monishdeb this slipped through the cracks and it needs rebasing again. I'll get it reviewed/merged this cycle. Thanks. |
@colemanw I have rebased it! |
CRM/Admin/Form/Setting.php
Outdated
$options = civicrm_api3('Setting', 'getoptions', array( | ||
'field' => $setting, | ||
)); | ||
if (array_key_exists('optionGroupName', $props['pseudoconstant'])) { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
CRM/Admin/Form/Setting/Debugging.php
Outdated
public function postProcess() { | ||
$params = $this->controller->exportValues($this->_name); | ||
|
||
if ($params['environment'] != 'Production') { |
There was a problem hiding this comment.
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
@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 |
CRM/Admin/Form/Setting.php
Outdated
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'); | ||
} |
There was a problem hiding this comment.
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.
@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' | ||
); | ||
} |
There was a problem hiding this comment.
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.
@eileenmcnaughton @colemanw I have made additional fixes as per comment and rebased the PR as it gone stale. Can you please check now? |
@colemanw I think the latest fixes address the issues raised so far so what do we still need to consider? |
@monishdeb test fail seems related |
@eileenmcnaughton yup fixed it. |
9f42e89
to
90faa8e
Compare
CRM/Admin/Form/Setting.php
Outdated
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'); | ||
} |
There was a problem hiding this comment.
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');
}
@eileenmcnaughton this looks good to me. |
Not sure why a bunch of mailing tests just failed. |
Yeah, annoying test failures, that runs clean on local :( |
Oh I see why they are related:
|
Yup, reason why I set the environment setting to |
Jenkins is still grumpy |
@eileenmcnaughton i note that Jenkins appears to now be happy with this PR |
Looks like @colemanw said this was ready to merge with one change, now made, so merging - thanks @seamuslee001 |
$values = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME, 'environment'); | ||
$this->assertEquals('Staging', $values); | ||
|
||
define('CIVICRM_ENVIRONMENT', 'Development'); |
There was a problem hiding this comment.
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 (likeCRM/Activity/**Test.php
) run in an open-ended environment. (The default appears to beProduction
.) - When you run
CRM_AllTests
, any later tests (likeCRM/Utils/**Test.php
) are unalterably pegged to theDevelopment
environment. - When you run any test by itself (like
CRM/Utils/**Test.php
), you again have an open-ended environment (where the default isProduction
). - Consequently, tests will some of the time run in
Production
and some of the time inDevelopment
. - (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 incivicrm.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 theDEVELOPER_PREFERENCES_NAME
or whatever -- they're all just aliases fordomain
.) - 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.)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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? |
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? |
For determining if the setting has been overridden, I think one can change the test:
|
nice! |
Note that this PR introduced a regression, see here: |