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-21627: makeMultilingual: update dbLocale to avoid fatal if lcMessages was not set #11491

Merged
merged 2 commits into from
Jan 10, 2018

Conversation

mlutfy
Copy link
Member

@mlutfy mlutfy commented Jan 7, 2018

Overview

Alternative PR to #11489. Fixes enabling of multilingual on 4.7.x.

Before

(copied from #11489)

  • Install Drupal site (Drupal 7.56)
  • Install CiviCRM 4.7.29
  • Go to Settings - Localization
  • Check Enable Multiple Languages
  • Click Save

Result: Fatal error.

NB: this only happens if we enable multi-lingual right away. It does not fatal if we first save the settings form, then enable multi-lingual.

After

Works as expected.

Technical Details

makeMultilingual should call applyLocale so that the dbLocale is set correctly. Otherwise we get "DB error: no such field" because CiviCRM looks for civicrm_option_value.label, but it should instead be looking for civicrm_option_value.label_xx_XX (where xx_XX is the default locale, such as en_US).

Comments

I tested:

  • Enabling multi-lingual
  • Reverting back to unilingual
  • Re-enabling multi-lingual
  • Adding a second language (this requires civicrm-l10n.tar.gz to be installed).

@monishdeb
Copy link
Member

monishdeb commented Jan 8, 2018

@mlutfy this works great 👍 But there is test failure related to it and I think it was using a wrong query which get caught due this fix. Here's the patch

diff --git a/tests/phpunit/CRM/Logging/LoggingTest.php b/tests/phpunit/CRM/Logging/LoggingTest.php
index f0422ca..7179854 100644
--- a/tests/phpunit/CRM/Logging/LoggingTest.php
+++ b/tests/phpunit/CRM/Logging/LoggingTest.php
@@ -41,13 +41,13 @@ class CRM_Logging_LoggingTest extends CiviUnitTestCase {
     $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", array(), FALSE, FALSE);
     $this->assertNotNull($value, 'Logging not enabled successfully');
     $logging->disableLogging();
-    CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT NULL", array(), FALSE, NULL, FALSE, TRUE);
+    CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT NULL", array(), FALSE, NULL, FALSE, FALSE);
     CRM_Core_I18n_Schema::rebuildMultilingualSchema(array('en_US'));
     $logging->enableLogging();
     $query = CRM_Core_DAO::executeQuery("SHOW CREATE TABLE `log_civicrm_option_value`", array(), TRUE, NULL, FALSE, FALSE);
     $query->fetch();
     $create = explode("\n", $query->Create_Table);
-    CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` DROP COLUMN `logging_test`", array(), FALSE, NULL, FALSE, TRUE);
+    CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` DROP COLUMN `logging_test`", array(), FALSE, NULL, FALSE, FALSE);
     $this->assertTrue(in_array("  `logging_test` int(11) DEFAULT NULL", $create));
     $logging->disableLogging();
   }

Due to this query ALTER TABLE `civicrm_option_value_en_US` DROP COLUMN `logging_test` it's throwing a DB error civicrm_option_value_en_us' is not BASE TABLE that's because the view is built on base table civicrm_option_value not on its locale table.

…ages was not set (adds unit-test fix by Monish Deb)
@mlutfy
Copy link
Member Author

mlutfy commented Jan 10, 2018

@monishdeb Thanks for the unit-test patch! I added it to the PR and tests are passing.

OK to merge?

@seamuslee001
Copy link
Contributor

@eileenmcnaughton this seems to have been reviewed by Monish. I also tested the change to the test and it was fine. Change seems to make sense to me. The research done my Mathieu seems to make sense and the change seems very small and sensible

@monishdeb
Copy link
Member

  • (r-jira) Pass
  • (r-test) Pass
  • (r-code) Pass
  • (r-doc) Pass
  • (r-maint) Pass
  • (r-run) Pass: Created 4.7.31 tarball which got this patch. Installed in drupal and enabled multilingual. Ensured that it fixed the issue.
  • (r-user) Pass
  • (r-tech) Pass

@monishdeb monishdeb merged commit 9028c91 into civicrm:master Jan 10, 2018
sluc23 pushed a commit to ixiam/civicrm-core that referenced this pull request Jan 10, 2018
CRM-21627: makeMultilingual: update dbLocale to avoid fatal if lcMessages was not set
@mlutfy mlutfy added this to the 4.7.31 milestone Feb 9, 2018
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.

4 participants