Commit 3d38b572 authored by Dries's avatar Dries

- Patch #41481 by Zen, Cvbge, sun et al: bugfix: duplicate key error while editing locale strings.

parent 2d9eaf01
......@@ -378,9 +378,9 @@ CREATE TABLE locales_target (
translation text DEFAULT '' NOT NULL,
locale varchar(12) NOT NULL default '',
plid int4 NOT NULL default '0',
plural int4 NOT NULL default '0',
UNIQUE (lid)
plural int4 NOT NULL default '0'
);
CREATE INDEX locales_target_lid_idx ON locales_target(lid);
CREATE INDEX locales_target_locale_idx ON locales_target(locale);
CREATE INDEX locales_target_plid_idx ON locales_target(plid);
CREATE INDEX locales_target_plural_idx ON locales_target(plural);
......
......@@ -1218,7 +1218,7 @@ function system_update_159() {
case 'mysql':
$ret[] = update_sql("UPDATE {sequences} SET id = $vid WHERE name = '{node_revisions}_vid'");
break;
case 'pgsql':
$ret[] = update_sql("SELECT setval('{node_revisions}_vid_seq', $vid)");
break;
......@@ -1993,3 +1993,17 @@ function system_update_181() {
}
return $ret;
}
/**
* The lid field in pgSQL should not be UNIQUE, but an INDEX.
*/
function system_update_182() {
$ret = array();
if ($GLOBALS['db_type'] == 'pgsql') {
$ret[] = update_sql('ALTER TABLE {locales_target} DROP CONSTRAINT {locales_target}_lid_idx');
$ret[] = update_sql('CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)');
}
return $ret;
}
......@@ -358,13 +358,15 @@ function _locale_string_edit($lid) {
$result = db_query('SELECT DISTINCT s.source, t.translation, t.locale FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid);
$form = array();
$form['translations'] = array('#tree' => TRUE);
while ($translation = db_fetch_object($result)) {
$orig = $translation->source;
// Approximate the number of rows in a textfield with a maximum of 10.
$rows = min(ceil(str_word_count($orig) / 12), 10);
$form[$translation->locale] = array('#type' => 'textarea',
$form['translations'][$translation->locale] = array(
'#type' => 'textarea',
'#title' => $languages['name'][$translation->locale],
'#default_value' => $translation->translation,
'#rows' => $rows,
......@@ -386,7 +388,8 @@ function _locale_string_edit($lid) {
);
foreach ($languages['name'] as $key => $lang) {
$form[$key] = array('#type' => 'textarea',
$form['translations'][$key] = array(
'#type' => 'textarea',
'#title' => $lang,
'#rows' => $rows,
);
......@@ -404,14 +407,14 @@ function _locale_string_edit($lid) {
*/
function _locale_string_edit_submit($form_id, $form_values) {
$lid = $form_values['lid'];
foreach ($form_values as $key => $value) {
foreach ($form_values['translations'] as $key => $value) {
$value = filter_xss_admin($value);
$trans = db_fetch_object(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $key));
if (isset($trans->translation)) {
db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND locale = '%s'", $value, $lid, $key);
}
else {
db_query("INSERT INTO {locales_target} (lid, translation, locale) VALUES (%d, '%s', '%s')", $lid, $value, $key);
db_query("INSERT INTO {locales_target} (lid, translation, locale) VALUES (%d, '%s', '%s')", $lid, $value, $key);
}
}
drupal_set_message(t('The string has been saved.'));
......
......@@ -417,9 +417,9 @@ function xmlrpc_base64_get_xml($xmlrpc_base64) {
}
/**
* Execute an XML remote procedural call. This is private function; call xmlrpc()
* Execute an XML remote procedural call. This is private function; call xmlrpc()
* in common.inc instead of this functino.
*
*
* @return
* A $xmlrpc_message object if the call succeeded; FALSE if the call failed
*/
......
......@@ -73,7 +73,7 @@ function system_elements() {
$type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes' => array()), '#tree' => TRUE);
$type['select'] = array('#input' => TRUE);
$type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight' => array()));
$type['date'] = array('#input' => TRUE, '#process' => array('expand_date' => array()));
$type['date'] = array('#input' => TRUE, '#process' => array('expand_date' => array()), '#validate' => array('date_validate' => array()));
$type['file'] = array('#input' => TRUE, '#size' => 60);
// Form structure
......
......@@ -73,7 +73,7 @@ function system_elements() {
$type['checkboxes'] = array('#input' => TRUE, '#process' => array('expand_checkboxes' => array()), '#tree' => TRUE);
$type['select'] = array('#input' => TRUE);
$type['weight'] = array('#input' => TRUE, '#delta' => 10, '#default_value' => 0, '#process' => array('process_weight' => array()));
$type['date'] = array('#input' => TRUE, '#process' => array('expand_date' => array()));
$type['date'] = array('#input' => TRUE, '#process' => array('expand_date' => array()), '#validate' => array('date_validate' => array()));
$type['file'] = array('#input' => TRUE, '#size' => 60);
// Form structure
......
Markdown is supported
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