Importing string over rides fails because the file type *.po is not in the default list of allowed extentions.

To reproduce goto:
1) admin/config/regional/stringoverrides/import

2) select the *.po file that you exported successfully (after implementing this fix: http://drupal.org/node/1210180#comment-5384618)

3) Select the language

4) Click import button

5) get error message: The specified file my-string-overrides.en_.po could not be uploaded. Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.

_______

I've fixed this but adding upload_validators to the import file field:

stringoverrides_migrate.admin.inc

function stringoverrides_migrate_admin_import() {
  $form = array();
  $form['#attributes'] = array('enctype' => "multipart/form-data");
  $languages = module_exists('locale') ? locale_language_list() : array('en' => t('English'));
  $form['file'] = array(
    //'#type' => 'file',
      // hack matt: only managed_file type can have upload_validators
    '#type' => 'managed_file',
    '#title' => t('File'),
    '#description' => t('Attach your *.po file here to import the string overrides.'),
    // hack matt: *.po fails standard validation
    '#upload_validators' => array(
      'file_validate_extensions' => array('po'),
    ),
  );
  
  $form['lang'] = array(
    '#type' => 'select',
    '#title' => t('Language'),
    '#description' => t('Which language to import the overrides to.'),
    '#options' => $languages,
  );
  $form['import'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
    '#weight' => 3,
  );
  return $form;
}

This probably isn't actually what you want to do, but it does allow you to at least import the strings. Probably be better to keep the #type as 'file' and implement the extension validation a different way.

Comments

mariacha1’s picture

StatusFileSize
new733 bytes

It's perfectly acceptable to add the validation to the submit handler, and then you don't get stuck with the weird managed_file issues. I'm including a patch to do that.

bmx269’s picture

Thanks, but the patch did not work for me. Gave me:

PHP Parse error: parse error in /sites/all/modules/contrib/stringoverrides/stringoverrides_migrate.admin.inc on line 63

mariacha1’s picture

Hmm... The patch doesn't touch that line. Any chance you have an older version of the module? I tested this on stringoverrides_migrate version 7.x-1.8.

gbirch’s picture

There's an easier way to fix this. In stringoverrides_migrate_admin_import_submit(),
change

$file = file_save_upload('file');

to

$file = file_save_upload('file', array(
'file_validate_extensions' => array('po'),
));

aburrows’s picture

StatusFileSize
new784 bytes

Patch created as per gbirch suggestion

Status: Needs review » Needs work

The last submitted patch, 5: import_fails_validation-1377418-4.patch, failed testing.

4alldigital’s picture

StatusFileSize
new616 bytes

trying above patch again from #5, with module directory paths, as above patch fails with make files.

nicrodgers’s picture

Status: Needs work » Reviewed & tested by the community

patch in #7 applies and fixes the issue for me

nicrodgers’s picture

Status: Reviewed & tested by the community » Needs review

triggering test bot - didn't notice the old status

The last submitted patch, 1: Import_fails_validation-1377418-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: stringoverrides-1377418-6-7.43.patch, failed testing.