Commit f618f072 authored by webchick's avatar webchick
Browse files

Issue #1635084 by webflo, penyaskito, vasi1186, Berdir: Fixed Fatal error when...

Issue #1635084 by webflo, penyaskito, vasi1186, Berdir: Fixed Fatal error when deleting language due to DBTNG typo.
parent 8364b744
...@@ -39,7 +39,6 @@ function setUp() { ...@@ -39,7 +39,6 @@ function setUp() {
* The language of the langcode to add. * The language of the langcode to add.
*/ */
function addLanguage($langcode) { function addLanguage($langcode) {
// Add language.
$edit = array('predefined_langcode' => $langcode); $edit = array('predefined_langcode' => $langcode);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
drupal_static_reset('language_list'); drupal_static_reset('language_list');
...@@ -47,10 +46,10 @@ function addLanguage($langcode) { ...@@ -47,10 +46,10 @@ function addLanguage($langcode) {
} }
/** /**
* Get translations for a array of strings. * Get translations for an array of strings.
* *
* @param $strings * @param $strings
* A array of strings to translate. * An array of strings to translate.
* @param $langcode * @param $langcode
* The language code of the language to translate to. * The language code of the language to translate to.
*/ */
...@@ -132,7 +131,7 @@ function testBulkImportUpdateExisting() { ...@@ -132,7 +131,7 @@ function testBulkImportUpdateExisting() {
); );
$this->checkTranslations($strings, $langcode); $this->checkTranslations($strings, $langcode);
// Fill the {locale_file} table with a older file. // Fill the {locale_file} table with an older file.
$file = $this->mockImportedPoFile($langcode, -1); $file = $this->mockImportedPoFile($langcode, -1);
// Add language. // Add language.
...@@ -178,4 +177,21 @@ function testBulkImportNotUpdateExisting() { ...@@ -178,4 +177,21 @@ function testBulkImportNotUpdateExisting() {
$timestamp = db_query('SELECT timestamp FROM {locale_file} WHERE uri = :uri', array(':uri' => $file->uri))->fetchField(); $timestamp = db_query('SELECT timestamp FROM {locale_file} WHERE uri = :uri', array(':uri' => $file->uri))->fetchField();
$this->assertEqual($timestamp, $file->timestamp); $this->assertEqual($timestamp, $file->timestamp);
} }
/**
* Delete translation files after deleting a language.
*/
function testDeleteLanguage() {
$dir = conf_path() . '/files/translations';
file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
variable_set('locale_translate_file_directory', $dir);
$langcode = 'de';
$this->addLanguage($langcode);
$file_uri = $dir . '/po_' . $this->randomString() . '.' . $langcode . '.po';
file_put_contents($file_uri, $this->randomString());
$this->assertTrue(is_file($file_uri), 'Translation file is created.');
language_delete($langcode);
$this->assertTrue($file_uri);
$this->assertFalse(is_file($file_uri), 'Translation file deleted after deleting language');
}
} }
...@@ -393,18 +393,21 @@ function locale_translate_update_file_history($file) { ...@@ -393,18 +393,21 @@ function locale_translate_update_file_history($file) {
*/ */
function locale_translate_delete_translation_files($langcode) { function locale_translate_delete_translation_files($langcode) {
$files = locale_translate_get_interface_translation_files($langcode); $files = locale_translate_get_interface_translation_files($langcode);
$return = TRUE;
if (!empty($files)) { if (!empty($files)) {
foreach ($files as $file) { foreach ($files as $file) {
$success = file_unmanaged_delete($file->uri); $success = file_unmanaged_delete($file->uri);
if (!$success) { if (!$success) {
return FALSE; $return = FALSE;
}
else {
// Remove the registered translation file if any.
db_delete('locale_file')
->condition('langcode', $langcode)
->condition('uri', $file->uri)
->execute();
} }
// Remove the registered translation file if any.
db_delete('locale_file')
->condition('langcode', $langcode)
->coddition('uri', $file->uri)
->execute();
} }
} }
return TRUE; return $return;
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment