Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Good evening. I have suggestions for function getTemplate(). I was faced with the header encoding. As they unloaded in UTF-8 Russian titles are not supported. I propose to do as follows,
public function getTemplate() { $mappings = feeds_importer($this->id)->processor->config['mappings']; $sources = $uniques = array(); $encoding = $this->config['encoding']; foreach ($mappings as $mapping) { if (in_array($mapping['source'], $uniques) || in_array($mapping['source'], $sources)) { // Skip columns we've already seen. continue; } if (!empty($mapping['unique'])) { $uniques[] = $mapping['source']; } else { $sources[] = $mapping['source']; } } $sep = $this->getDelimiterChar($this->config); $columns = array(); foreach (array_merge($uniques, $sources) as $col) { if (strpos($col, $sep) !== FALSE) { $col = '"' . str_replace('"', '""', $col) . '"'; } $columns[] = mb_convert_encoding($col, $encoding, 'utf-8'); } $template_file_details = $this->getTemplateFileDetails($this->config); $filename = "{$this->id}_template.{$template_file_details['extension']}"; $cache_control = 'max-age=60, must-revalidate'; $content_disposition = 'attachment; filename="' . $filename . '"'; $content_type = "{$template_file_details['mime_type']}; charset=utf-8"; drupal_add_http_header('Cache-Control', $cache_control); drupal_add_http_header('Content-Disposition', $content_disposition); drupal_add_http_header('Content-type', $content_type); print implode($sep, $columns); }
Comments
Comment #2
Demidov Sergey CreditAttribution: Demidov Sergey commentedComment #3
Demidov Sergey CreditAttribution: Demidov Sergey commentedComment #4
MegaChriz CreditAttribution: MegaChriz commentedHi, can you post your changes in the form of a patch? This makes it more clear at what exactly you changed in plugins/FeedsCSVParser.inc. Also, the file could get changed by other issues and then overwriting plugins/FeedsCSVParser.inc with your file would undo these changes. Also, when posting a patch and set the issue status to "Needs review", automated tests are ran against your code, which could catch bugs.
Glancing over the code posted in the issue summary, I see you are using the function
mb_convert_encoding()
. This function requires the mbstring extension, which may not be available.From http://php.net/manual/en/mbstring.installation.php:
You should therefore check if the extension is available before calling a function from it:
Comment #5
Demidov Sergey CreditAttribution: Demidov Sergey commentedSorry, first time doing an issue on d.org here fixed version.
Comment #6
Demidov Sergey CreditAttribution: Demidov Sergey commentedComment #8
Demidov Sergey CreditAttribution: Demidov Sergey commentedComment #9
Demidov Sergey CreditAttribution: Demidov Sergey commentedComment #10
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedThanks for posting the changes as a patch!
You could add a check here to see if
$encoding
is already 'utf-8'. Because if so, there is no need to convert it.As there was no test coverage yet for the CSV template, I've added some in #2771803: Tests for the CSV template. I've let the testbot test your patch again with these tests included.
Comment #11
Demidov Sergey CreditAttribution: Demidov Sergey commented