Download & Extend

system_date_format_save() doesn't save localized date formats

Project:Drupal core
Version:8.x-dev
Component:system.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:needs backport to D7

Issue Summary

Problem/Motivation

The function system_date_format_save() implements the functionality to save localized date formats in the table {date_format_locale}. Unfortunately, the check whether or not to save a format localized is broken. A list of enabled languages is fetched with the following code:

<?php
  $languages
= language_list('enabled');
 
$languages = $languages[1];
?>

When checking each date format locale against this list to see if the language is enabled, the function uses if (in_array($langcode, $languages)). However, the langcodes are in the keys of this array. The values are full database records for each language.

Proposed resolution

Correct the function to use if (isset($languages[$langcode])).

Remaining tasks

User interface changes

None.

API changes

None.

Original report by @das-peter

The function system_date_format_save() already implements the functionality to save localized date formats in the table date_format_locale.Unfortunately, the check whether or not to save a format localized is broken.The attached patch fixes this.

AttachmentSizeStatusTest resultOperations
system-system_date_format_save-localized-date-format-not-saved.patch796 bytesIdleFAILED: [[SimpleTest]]: [MySQL] Invalid patch format in system-system_date_format_save-localized-date-format-not-saved.patch.View details

Comments

#1

Status:needs review» needs work

The last submitted patch, system-system_date_format_save-localized-date-format-not-saved.patch, failed testing.

#2

Status:needs work» needs review

Removed path prefix

AttachmentSizeStatusTest resultOperations
system-system_date_format_save-localized-date-format-not-saved-981524-2.patch774 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 28,783 pass(es).View details

#3

+++ modules/system/system.module
@@ -3740,7 +3740,7 @@ function system_date_format_save($date_format, $dfid = 0) {
       // Only proceed if language is enabled.
-      if (in_array($langcode, $languages)) {
+      if (isset($languages[$langcode])) {

Disabled languages are contained in $languages, too, AFAIK.

Powered by Dreditor.

#4

$languages is fetched using this code:

  $languages = language_list('enabled');
  $languages = $languages[1];

Thus there should be only the enabled languages in the variable.
Besides that I'm not sure how evil it would be to store the date formats from disabled languages ;)

#5

Status:needs review» reviewed & tested by the community

Thanks for clarifying!

#6

Status:reviewed & tested by the community» needs work

Sorry, this needs tests.

#7

Hmm, I'm not sure if the attached tests are sufficient. There is a lot more that could be covered...
But at least the topic of this issue is covered ;)

AttachmentSizeStatusTest resultOperations
system-system_date_format_save-localized-date-format-not-saved-tests-981524-7.patch3.21 KBIdleFAILED: [[SimpleTest]]: [MySQL] Invalid patch format in system-system_date_format_save-localized-date-format-not-saved-tests-981524-7.patch.View details

#8

Status:needs work» needs review

#9

Status:needs review» needs work

Testbot says invalid patch file.

#10

Status:needs work» needs review
AttachmentSizeStatusTest resultOperations
system-system_date_format_save-localized-date-format-not-saved-tests-981524-10.patch3.12 KBIdleFAILED: [[SimpleTest]]: [MySQL] 28,811 pass(es), 1 fail(s), and 0 exception(es).View details

#11

Status:needs review» needs work

The last submitted patch, system-system_date_format_save-localized-date-format-not-saved-tests-981524-10.patch, failed testing.

#12

+++ modules/system/system.test
@@ -1044,6 +1044,70 @@ class DateTimeFunctionalTest extends DrupalWebTestCase {
+    $query = db_select('date_formats', 'df');
+    $query->addField('df', 'format');
+    $query->condition('type', 'short');
+    $query->condition('format', 'dmYHis');
+    $format = $query->execute()->fetchColumn();

Can you rewrite these queries to:

$format = db_select('date_formats', 'df')
  ->fields('df', array('format'))
  ->condition('type', 'short')
  ->condition('format', 'dmYHis')
  ->execute()
  ->fetchField();

Powered by Dreditor.

#13

Thx sun - nice hint. Didn't recognized that always the addField kills the chaining.

AttachmentSizeStatusTest resultOperations
system-system_date_format_save-localized-date-format-not-saved-tests-981524-13.patch3.03 KBIdleFAILED: [[SimpleTest]]: [MySQL] 28,823 pass(es), 1 fail(s), and 0 exception(es).View details

#14

Status:needs work» needs review

#15

Status:needs review» needs work

The last submitted patch, system-system_date_format_save-localized-date-format-not-saved-tests-981524-13.patch, failed testing.

#16

Status:needs work» needs review

Rerolled the patch against the current 7.x branch and verified that the tests run successfully.

AttachmentSizeStatusTest resultOperations
981524-save-localized-date-formats-16.patch4.21 KBIdlePASSED: [[SimpleTest]]: [MySQL] 32,039 pass(es).View details

#17

Version:7.x-dev» 8.x-dev
Status:needs review» needs work

+++ b/modules/system/system.test
@@ -1048,6 +1048,74 @@ class DateTimeFunctionalTest extends DrupalWebTestCase {
   }
+  /**

Missing blank line.

2 days to next Drupal core point release.

#18

Status:needs work» needs review

Sorry for that, should be corrected now.

AttachmentSizeStatusTest resultOperations
981524-save-localized-date-formats-18.patch4.21 KBIdlePASSED: [[SimpleTest]]: [MySQL] 33,608 pass(es).View details

#19

Thank you sun for the review & thank you Pisco for the updated patch.
Would be nice to get rid of this diff in our own drupal repo. :)

#20

Status:needs review» reviewed & tested by the community

Thanks! Let's get this in.

#21

Issue summary added. I also opened #1234848: language_list() doc is missing return value to address the (lack of) documentation for language_list().

#22

Status:reviewed & tested by the community» fixed

Committed and pushed to 8.x and 7.x. Thanks!

#23

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here