You are here

function stringoverrides_migrate_admin_import_submit in String Overrides 7

Triggered when the user imports data.

File

./stringoverrides_migrate.admin.inc, line 36
Stringoverride migration admin.

Code

function stringoverrides_migrate_admin_import_submit($form, &$form_state) {

  // Check if the file uploaded correctly
  $file = file_save_upload('file');
  if (!$file) {
    form_set_error('file', t('A file to import is required.'));
    return;
  }

  // Try to allocate enough time to parse and import the data.
  drupal_set_time_limit(240);
  $lang = $form_state['values']['lang'];

  // Get strings from file (returns on failure after a partial import, or on success)
  $status = _locale_import_read_po('mem-store', $file, LOCALE_IMPORT_OVERWRITE, $lang, 'stringoverrides');
  if ($status === FALSE) {

    // Error messages are set in _locale_import_read_po().
    return FALSE;
  }

  // Get the import result.
  $strings = _locale_import_one_string('mem-report');
  file_delete($file);
  variable_set("locale_custom_strings_{$lang}", $strings);
  drupal_set_message(t('The overrides have been imported.'));
}